Reputation: 65
I use SSHLibrary to connect to the computer to run test cases. As follows:
*** Test Cases ***
Check CPU Temperature
Check that the CPU temperature is less than ? °C ${CPU tem}
Check CPU Usage
Check if any application is using CPU more than ? percent ${CPU usage percent}
Check TCP transmission
Check TCP transmission > ? MBytes ${tcp transmission}
*** Keywords ***
Open Connection & Login
Open Connection ${HOST}
Login ${ACCOUNT} ${PASSWORD}
#(The following is omitted)
I would like to ask how can I do if I want to use the same Test cases to test the second computer?
Upvotes: 0
Views: 1547
Reputation: 8322
Well, that depends how much you want to change the structure of your current file/tests. Since you have single variables ${HOST}
, ${ACCOUNT}
, and ${PASSWORD}
and it doesn't seem from your question that you iterate over some data structure where you store different login information for several different hosts, then the more straightforward way of running this is just to run several commands:
$ robot --variable HOST:host1 --variable ACCOUNT:a --variable PASSWORD:secret * && robot --variable HOST:host2 --variable ACCOUNT:a --variable PASSWORD *
EDIT: As I have been correctly reminded in the comments, executing the second command from the previous example will overwrite the outputs created by the first command, so a better way to go about it (to preserve logs from both executions) is something like this:
$ robot --timestampoutput --output host1 --log host1 --report host1 --variable HOST:host1 --variable ACCOUNT:a --variable PASSWORD:secret * && robot --timestampoutput --output host2 --log host2 --report host2 --variable HOST:host2 --variable ACCOUNT:a --variable PASSWORD:secret *
That will create separate outputs for each command in the following format: host{n}-{date}-{time}
.
Since this is already a long command, it's better to use argument file that contains all these command-line options, you can later reference just this file from the command like: $ robot --argumentfile <path_to_argument_file>
. More on that here.
This approach requires no change in your test/keyword files, but it doesn't scale very well if you have a lot of machines to run these tests on.
I'd most likely go for the following approach:
Resources/machines.py
MACHINES = [
{
"host": "host1",
"account" "a",
"password": "secret"
},
{
"host": "host2",
"account" "b",
"password": "secret"
}
]
*** Test Cases ***
Check Temperature
FOR ${machine} IN @{MACHINES}
# you would need to assing values from the dict into ${host}, ${account},
# and ${pwd} here, you want to check Collections library for this
Check CPU Temperature ${host} ${account} ${pwd}
END
Then you would be able to issue just one command with no need to specify any variables on the command line. It scales better if you have a lot of test data.
Another way of doing this would be a data driven approach:
*** Test Cases ***
Check Temperature
[Template] Check CPU Temperature
host1 a secret
host2 a secret
host3 a secret
and similarly for other test cases. You'd also need to change your keywords such as Check CPU Temperature
so they accept parameters for a host, account, and login.
This approach is perhaps a little bit straighforward than the previous one, but you keep test data hard-coded in your test (.robot) files, which I personally don't like.
Upvotes: 3