0

Here is the below script file, I want to run in robot tests

import os

def ps_kill():
    os.system(' command')

ps_kill()

And below is my test

*** Settings ***
Library    SeleniumLibrary
Library    Process

*** Test Cases ***
Test case 1
    [Documentation]    Running a command
    [Tags]    Cur


    Launch py File
        ${result} =    run process   python   /path/ps_kill.py

After ran the test it just pass but not run the script.

0

2 Answers 2

1

try :

*** Test Cases ***

Launch py File
    ${result} =   evaluate   os.system('echo hello world')

if you want to validate it : you can add print as below:

*** Test Cases ***

Launch py File
    ${result} =   evaluate   print(os.system('echo hello world'))

the idea is that evaluate is the shortest way to run python in robot framework Starting from Robot Framework 3.2, modules used in the expression are imported automatically so there is no need to import the module

Sign up to request clarification or add additional context in comments.

Comments

1

There is a much simpler way to run commands from a Robot Framework test, it is by using the OperatingSystem library. This library offers similar functionality as the import os does in Python.

In your case these three keywords that could be used:

An example:

*** Settings ***
Library     OperatingSystem

*** Test Case ***
Test case 1
    ${rc}   ${output} =     Run and Return RC and Output    echo "My string printed by a command"    # Any command could be called here.
    Log    ${rc}
    Should Be Equal As Integers     ${rc}   0    # Check if command execution was succesful.    
    Log    ${output}    # Log output of the command.
 

This would give the following output:

enter image description here

2 Comments

Thanks @Bence Kaulics, but i;m facing the issue i ran the command to login the below command (It will log into remote windows server and kill the particular process) ${rc} ${output} = Run and Return RC and Output echo "psexec.exe \\\\<SERVER IP> -u <Username> -p <Password> cmd /c D: ^& D:\\abc\\pch\\bin\\kill.exe <Process>" # Any command could be called here.
@Babu echo is part of my example command so you do not need that in your case. Also everything after # is a comment, so you can remove those as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.