Hi, I am new to Robot automation, please help with the below query…
I have 2 test cases, RegisterTest and LoginTest and i need to check the following
1)The output of Registertests, email address and password should be input to login test emailaddress and password
2)Only successful register, then only login test should execute
[When i executed below code , the error ‘The keyword "Login Test’ not defined’ displaying]
*** Variables ***
*** Test Cases ***
Registration test
Launching Browser ${urlRegster} ${browser}
${random_name}= Generate Random Alphanumeric 6
${random_pwd}= Generate Random Alphanumeric 5-8
${register_email}= Enter The Email ${random_email}
${register_password}= Enter The Password ${random_pwd}
Run Keyword If ‘${register_email}’!=‘’ and ‘${register_password}’!=‘’ Login test ${register_email} ${register_password}
*** Variables ***
*** Test Cases ***
Login test
[Arguments] ${register_email} ${register_password}
Run Keyword If ‘${register_email}’ != ‘’ and ‘${register_password}’ != ‘’ Launching Browser ${urlLogin} ${browser}
Run Keyword If ‘${register_email}’ != ‘’ and ‘${register_password}’ != ‘’ Enter The Emailaddress ${register_email}
Run Keyword If ‘${register_email}’ != ‘’ and ‘${register_password}’ != ‘’ Enter The Password ${register_password}
Run Keyword If ‘${register_email}’ != ‘’ and ‘${register_password}’ != ‘’ Click Login Button
First you probably need to understand Variable priorities and scopes, as the variables you created in Registration test only exist in that test case, you can’t use them in another test case unless you make them available in another scope (e.g. make the a suite variable).
Next I see this line:
Run Keyword If ‘${register_email}’!=‘’ and ‘${register_password}’!=‘’ Login test ${register_email} ${register_password}
Then I see that Login test is declared as a test case in LoginTest.robot, a test case and a keyword is not the same thing and you can’t call a test case that way.
Now we cleared that up, how you run these tests will determine your options for tackling this issue.
If both test cases were in the same robot file I’d know they were part of the same suite, in which case there are several options when the tests are in the same suite.
When you run robot framework do you run for an individual robot file, or for a directory that both these files are within? The answer to this will determine what options we can suggest for you.
In that case you’ll need to manage it outside robot framework, when you run RegisterTest.robot, capture the return code from robot framework, as it’s documented here: Return codes a return code of 0 means all tests passed so you use this to decide that it’s ok to run LoginTest.robot. As for passing the data from Registration test to Login test, there’s no simple mechanism to do this as it’s two separate robot framework instances (different unrelated processes on the computer) so your best option is probably have Registration test write to a file and then have Login test read the values from that file.
It’s much easier to have both tests in the same suite and let robot framework control if the second test should run.
The simplest, as Dave said, is to put your 2 TC is the same suite (aka same .robot file).
Thus you just need to use a couple “Set Suite variable” in your first TC, so the variables will be readable for the second (as the TC are executed in the order of appearance in the suite.
Or transform both TC in ‘functional’ keywords, and create a single TC to call the new keywords.
Or using the RF APIs to run the TCs and passing the variables, but this will be really complicated for your real needs.
Last thing “Run Keyword If” can be replaced by an IF statement.
Maybe you are using Chatgpt to help you to write your first test cases.
Unfortunatly, it has not be trained with latest RF versions so produce a poor code sometimes (and need strong prompts in order to produce good results).
Regards
Olivier