Is it possible to write a test template with multiple keywords?
I'm looking for something like:
Valid Login
[Template]
Given login page is open
When ${username} and ${password} are inserted
and user is on ${device}
Then welcome page should be open
root abc desktop
noman xyz laptop
It would be a bonus if I could use a list instead of a data table
The normal way is to create a new keyword that calls those keywords, and set the template in the settings:
*** Settings ***
Test template Valid Login
*** Test cases ***
root abc desktop
noman xyz laptop
*** Keywords ***
Valid Login
[Arguments] ${username} ${password} ${device}
Given login page is open
When ${username} and ${password} are inserted
and user is on ${device}
Then welcome page should be open
Related
I have a test suite
Library RequestsLibrary
Library JSONLibrary
Library OperatingSystem
*** Variable ***
${base_url} https://api.sportpartnerxxx.vn/v1
${identity_URL} https://identity.sportpartnerxxx.vn
*** Test Cases ***
Login
${body}= Create Dictionary client_id=sportpartner-mobile-app client_secret=ifd-sportpartner-secret-2021-mobile-app grant_type=password username=abc password=123456
${header}= create dictionary content_type=application/x-www-form-urlencoded
${response}= Post ${identity_URL}/connect/token headers=${header} data=${body}
${token}= Set Variable Bearer ${response.json()["access_token"]}
Status Should Be 200
Refresh token
${body}= Create Dictionary client_id=sportpartner-mobile-app client_secret=ifd-sportpartner-secret-2021-mobile-app grant_type=password refresh_token=${refresh_token}
${header}= create dictionary content_type=application/x-www-form-urlencoded Authorization=&{token}
${response}= Post ${identity_URL}/connect/token headers=${header} data=${body}
Status Should Be 200
I want to take ${token} variable of Login test case add to Authorization value of Refresh token test case. But it failed.
Does anyone help me?
Variable crated in a case is local (visible) only in it, and in the keywords it calls; once the case ends, the var is deleted.
If you want it to be accessible in a follow up case, you need to extend its scope - call Set Suite Variable with it, or Set Global Variable - which will make it available for any other suites ran after this one.
This has one big drawback, though - you're adding dependency on the cases order; "Login" has always to be ran fist - and to succeed, so that "Refresh token" works.
That's why this is usually done through keywords (called in case setup, etc).
I'd kindly suggest to read about variables scopes in the user guide -
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#using-set-test-suite-global-variable-keywords
You could try saving the variable with
Set Suite Variable
Then accessing it in your other test case
https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Set%20Suite%20Variable
*** Settings ***
Library SeleniumLibrary
Resource ../Tests/Main.robot
Resource SSmthn.robot
Library Dialogs
Library Collections
*** Variables ***
*** Keywords ***
Select Browser: User Input
${value} = get selection from user Select Browser Begin Web Test with Chrome Browser Begin Web Test with headlessChrome
${value}
Begin Web Test with Chrome Browser
${options}= Evaluate sys.modules['selenium.webdriver.chrome.options'].Options() sys
Call Method ${options} add_argument --disable-notifications
${driver}= Create Webdriver Chrome options=${options}
go to ${URL}
maximize browser window
sleep 2sec
Begin Web Test with headlessChrome
open browser ${URL} ${Browser}
maximize browser window
sleep 2sec
End Web Test
close all browsers
Here Iam asking user for one of the 2 selections.
${value}: stores value from user selection but does not call the keyword selected by the user. What can I change here to make it work?
A keyword which name is stored in a variable can be executed by using the Run Keyword keyword from the BuiltIn library.
Select Browser: User Input
${value} = get selection from user Select Browser Begin Web Test with Chrome Browser Begin Web Test with headlessChrome
Run Keyword ${value}
I'm learning Robot Framework and I want to run a Excel file for my data of the test case.
When I run the code, The report shows all test case names are the same.
In my Excel file, the first column is "* Test Cases *". I want the name of test case will be chosen from there.
I am using Eclipse with Red Editor plugin of Nokia.
*** Settings ***
Library Selenium2Library
Library DataDriver ${CURDIR}/data/login_data.xlsx DataDriven
Resource ${CURDIR}/resources/login_resources.robot
Suite Setup Open Browser To Login Page
Suite Teardown Close Browser
Test Setup Open Login Page
Test Template Invalid Login
*** Test Cases ***
Login With Invalid Data ${USERNAME} ${PASSWORD}
*** Keywords ***
Invalid Login
[Arguments] ${USERNAME} ${PASSWORD}
[Tags] Flat
Input Username ${USERNAME}
Input Pass ${PASSWORD}
Click Submit Button
Create HalfTrip Menu Should Not Be Open
I want to execute the same keyword for an array of input in robot framework.
For ex:
*** Test Case ***
Login to gmail ${UserIDs} ${passwords}
Here, UserIDs and Passwords are an array and I wish to execute the keyword 'Login to gmail' for all the input in those arrays. I know that the keyword mentioned here wont work. But, I am looking help to achieve this.
Using a :FOR loop
If your constraint is that the usernames and passwords must be stored in arrays, and you all this in a single test case, your only solution is to use a loop. In this case, since you want to iterate over two equal-length arrays you can use the IN ZIP variant of robot's looping mechanism. In order for all iterations to run even if one failed, you can use run keyword and continue on failure within the loop.
Example:
*** Variables ***
#{userIDs} one#example.com two#example.com badguy#example.com
#{passwords} secretpassword secretPassword SecretPassword
*** Keywords ***
Login to gmail
[Arguments] ${userID} ${password}
should not be true $userID == "badguy#example.com"
... cannot login as bad guy
*** Test case***
Example
:FOR ${userID} ${password} IN ZIP ${userIDs} ${passwords}
\ run keyword and continue on failure
\ ... login to gmail ${userID} ${password}
Using a template
A more common solution is to use a test template. This allows you to specify keyword to be run for each test, and then the test itself contains the data (ie: the data is not stored in arrays).
Example:
*** Keywords ***
Login to gmail
[Arguments] ${userID} ${password}
should not be true $userID == "badguy#example.com"
... cannot login as bad guy
*** Test case***
Gmail logins
[Template] login to gmail
# username # password
one#example.com secretpassword
two#example.com bogus
badguy#example.com letmein
Using a test template for the suite
A third solution is to use one template for the whole suite. One advantage to this is that each success or failure is recorded as a separate test, and can have a unique name.
Example:
*** Settings ***
Test Template Login to gmail
*** Keywords ***
Login to gmail
[Arguments] ${userID} ${password}
should not be true $userID == "badguy#example.com"
... cannot login as bad guy
*** Test case***
# test case name # username # password
valid username/password one#example.com secretpassword
valid username, invalid password two#example.com bogus
invalid username badguy#example.com letmein
I'm writing an acceptance test for web using Robot Framework + Selenium2Library. The point is that web contain some input field that I can not automate (CAPTCHA), and I can't tell my vendor to turn off this feature while running test. So I have to input this field manually. Now I'm doing this:
Create User
[Arguments] ${username} ${password}
Open Browser ${URL} ${BROWSER}
Input Text username ${username}
Input Text password ${password}
Sleep 10 # XXX input CAPTCHA manually here!
Click Button submit
Page Should Contain ${username} has been created.
I've input CAPTCHA when I tell Robot Framework to Sleep 10, so far so good. But I wonder is there anyway to tell Robot Framework to wait indefinitely, then continue automate task after I finish input that CAPTCHA?
There is a keyword just for this purpose in the Dialog library that comes with Robot Framework.
Execute Manual Step Please complete the CAPTCHA portion of the form.
I can see a few options:
You can remove sleep and button clicking and do them yourself. Then you can use wait until page contains to continue after you has pushed submit button
Create User
[Arguments] ${username} ${password}
Open Browser ${URL} ${BROWSER}
Input Text username ${username}
Input Text password ${password}
Log Waiting for CAPTCHA
Wait Until Page Contains ${username} has been created. timeout=3600
You can also use Pause Execution keyword from Dialogs-library. This pauses execution until you click OK in a popup.
Create User
[Arguments] ${username} ${password}
Open Browser ${URL} ${BROWSER}
Input Text username ${username}
Input Text password ${password}
Pause Execution Enter captcha
Click Button submit
Page Should Contain ${username} has been created.
The most automated way I can think of is to use a CAPTCHA solving service. I believe they have an API where you send screenshot of your page and get a solved CAPTCHA back. I have never tried them and sharing screenshots of your software may not be an option.
You can also use the command- get value from user.
It opens the pop-up and tell user to insert the text value(Like enter captcha present at page), when user enters the captcha value and click on ok then this value gets insert into captcha window and next operation begins.
Code is:
#Use Library Dialogs
open browser http://sitename ff
input text id=name-id anytext
${Captcha} = get value from user Enter Captcha none none
input text id=captcha-id ${Captcha}
click element id=submit-id
Note: Use "Libray Dialogs" initially