Search code examples
linuxshellrobotframework

Robot Framework: How can I execute a .sh file in a test case?


I want to start a .sh file in a test case but it doesn't work like I would like it to.

I tried it with Run Process /appl/Test1/asd.sh Value1 Value2 and OperatingSystem.Run /Path/Test1/asd.sh Value1 Value2but both don't execute the asd.sh like it's executed in shell.

I used this Keywords for running a .pl Script and there it was no problem.


Solution

  • Do you mean to run .sh script in the same machine you launch ROBOT Framework or running the .sh file in another target unix/linux machine?

    Solution for these two(2) scenario as below. You can do many thing with this RUN PROCESS keyword, please refer to this link for RUN PROCESS keyword: http://robotframework.org/robotframework/latest/libraries/Process.html

    A. Running the .sh script in the same machine/os which you launch ROBOT Framework:

    Run Process /appl/Test1/asd.sh  shell=yes   --option  argument
    

    B. Running the .sh script in another target machine;

    In order to run .sh file, you must first write a ROBOT Framework's scripts to login to that unix/linux machine. So, follow the steps below.

    Import SSH Library into your RIDE. Follow the steps here: http://robotframework.org/SSHLibrary/

    Write ROBOT scripts to login to your unix/linux machine. Please go through all the available keywords under SSH Library first to get the hang of it. There are many ways to write the scripts but below are samples..

    See sample login scripts below.

    #SAMPLE A
    Open Connection    ${server_ip}    prompt=$
    ${std_output}=    Login ${username}    ${password}
    Should Contain    ${std_output}    $
    
    
    #SAMPLE B
    Write    sudo -u root -i
    ${std_output}=    Read    delay=5s
    Should Not Contain    ${std_output}    Permission denied
    Should Not Contain    ${std_output}    Password:
     #
    Write    cd /${hostname}_folder/Access
    ${std_output}=    Read    delay=5s
    Log    ${std_output}
    Should Not Contain    ${std_output}    Permission denied
    #
    Write    su devowner
    ${std_output}=    Read    delay=5s
    Log    ${std_output}
    Should Not Contain    ${std_output}    Password:
    

    Then, next you can use either WRITE or EXECUTE COMMAND keywords to run your .sh file at target machine/host.