I have two problems, I want to automatized a login and password entry on an HTML page
I wrote this code on RFW :
*** Variable ***
${USER}
${PSW}
*** Test Case ***
ENTER_ID ${USER} ${PSW}
Input Text //input[#name="j_name"] ${USER}
Input Text //input[#name="j_password"] ${PSW}
*** Keywords ***
ENTER_ID
[arguments] ${myUSer} ${myPSW}
${myUSER}= Get Value From User Please enter Name
${myPSW}= Get Value From User Please enter password
But on the HTML page, nothing is wrote by Robot. Log :
INFO : Typing text '' into text field '//input[#name="j_name"]'.
INFO : Typing text '' into text field '//input[#name="j_password"]'.
And also the log send me that
INFO : ${myUSER} = Paul
INFO : ${myPSW} = MyPassword
Variables used are myUSer and myPSW, it should be USER and PSW and I dont understand why
Thanks for helping me :)
This:
*** Variable ***
${USER}
${PSW}
means that two variables are creates, variable with name USER and variable with name PSW. But they are empty.
This:
*** Test Case ***
ENTER_ID ${USER} ${PSW}
Input Text //input[#name="j_name"] ${USER}
Input Text //input[#name="j_password"] ${PSW}
seems like incorrectly formatted test case. But even if you gave it a name and formatted it properly, you still aren't assigning to those variables USER and PSW by the time Input Text keywords are executed. That's because you're using them as arguments and in keyword:
ENTER_ID
[arguments] ${myUSer} ${myPSW}
${myUSER}= Get Value From User Please enter Name
${myPSW}= Get Value From User Please enter password
there's no assignment into these two variables you're later using with Input Text keywords.
A working code would be:
*** Variables ***
${USER}
${PWD}
*** Test Cases ***
Input User And Pwd
Ask For Credentials
Input Text //input[#name="j_name"] ${USER}
Input Text //input[#name="j_password"] ${PWD}
*** Keywords ***
Ask For Credentials
${user}= Get Value From User Please enter Name
${pwd}= Get Value From User Please enter password
Set Suite Variable ${USER} ${user}
Set Suite Variable ${PWD} ${pwd}
Set Suite Variable or Set Global Variable is necessary here, because simple Set Variable will create only local variables, but you want to assign to USER and PWD in a keyword but use them in a test case elsewhere.
Personally, I'd rather go for an option with a return value, that seems a bit more secure than working with suite or global variables:
*** Test Cases ***
Input User And Pwd
${credentials}= Ask For Credentials
Input Text //input[#name="j_name"] ${credentials.user}
Input Text //input[#name="j_password"] ${credentials.pwd}
*** Keywords ***
Ask For Credentials
${user}= Get Value From User Please enter Name
${pwd}= Get Value From User Please enter password
${credentials} = Create Dictionary user=${user} pwd=${pwd}
[Return] ${credentials}
By this time, you realise, you don't really need those USER and PWD variables at all (unless you wan't to use them for something more like setting default values).
Related
In robot framework I'm trying to type the string 'r16Ed' as username in textbox.
now its trying r6 and the tab to password field and type the string Ed as **.
It seems number 6 act as TAB.If I give the string 'Admin' it is typing properly.
Any other way to fix it.I also tried press keys that as well not working as expecting
By below code is
*** Settings ***
Library SeleniumLibrary
*** variables ***
${URL} http://testDomain.com
${Browser} chrome
${Username} r16Ed
*** Test Cases ***
Testing with Browser
[Documentation] Launching the browser
LaunchBrowser ${URL} ${Browser}
click element xpath://input[#id='userid']
input text id:userid ${Username}
I had a similar issue when executing Android tests. The solution was put some delay between each character. I created a for with a small delay and typed char by char
I'm trying to call same user keyword in different location using different inputs. How to do it?
*** Keywords ***
Enter the Server Name
Wait until element is visible ${ServerIPField} ${Timeout} "Input field not loaded"
Log "Input field loaded. Entering server name"
Click element ${ServerIPField}
Input text ${ServerIPField} ${ServerDetails}
Log "Server name/IP ${ServerDetails} entered to the server name/ip field"
in the above code,
ServerDetails field will have different inputs based on the usage locations (say i call this keyword in TC1 and then in TC3). I want to give different inputs for each test case.
Pass the variable ${ServerDetails} as argument to the keyword.
*** Test Cases ***
Test 1
Enter the server name ${server_1_details}
Test 2
Enter the server name ${server_2_details}
*** Keywords ***
Enter the Server Name
[Arguments] ${ServerDetails}
Wait until element is visible ${ServerIPField} ${Timeout} "Input field not loaded"
Log "Input field loaded. Entering server name"
Click element ${ServerIPField}
Input text ${ServerIPField} ${ServerDetails}
Log "Server name/IP ${ServerDetails} entered to the server name/ip field"
For Test 1 the keyword Enter the server name is called with the value stored in ${server_1_details} and in Test 2 is called with the value stored in ${server_2_details}.
I am new to Robot Framework and going through its documentation. In Robot Framework's overall test data syntax they state the below example:
*** Settings ***
Documentation Example using the space separated plain text format.
Library OperatingSystem
*** Variables ***
${MESSAGE} Hello, world!
*** Test Cases ***
My Test
[Documentation] Example test
Log ${MESSAGE}
My Keyword /tmp
Another Test
Should Be Equal ${MESSAGE} Hello, world!
*** Keywords ***
My Keyword
[Arguments] ${path}
Directory Should Exist ${path}
I am unable to understand what [Documentation] / Example test and [Arguments] ${path} in respective sections means - there does not seems to be a clear explanation for same?
How can I learn these basics syntax as the guide does not starts from basic "Hello World" program?
Overview
Values in square brackets in a test case or keyword definition are called settings. They are documented in the robot framework user guide in the sections titled Settings in the test case table and Settings in the keyword table.
Robot supports a fixed number of settings, so you can't just put any word you want inside square brackets. Anything in the first word of a line that is in square brackets will throw an error if it's not one of the supported settings.
Test cases support the settings [Documentation], [Tags], [Setup], [Teardown], [Template], and [Timeout]
Keywords support the settings [Documentation], [Tags], [Arguments], [Return], [Teardown], and [Timeout]
[Documentation]
As you surmised, [Documentation] is for setting the documentation for a test case or keyword. More information can be found in the robot framework user guide, in a section titled Test case name and documentation and User keyword name and documentation
The advantage to using [Documentation] instead of comments is that the documentation will appear in reports and logs, and will be included in documentation generated by libdoc and testdoc.
[Arguments]
[Arguments] are how you specify arguments to a keyword. You cannot use this setting for test cases. It is only available for keywords, and is documented in a section titled User keyword arguments
For example, if you write a keyword that accepts the arguments "first_name" and "last_name", you would define the [Arguments] setting like this:
*** Keywords ***
Example Keyword
[Arguments] ${first_name} ${last_name}
log Hello, my name is ${first_name} ${last_name}
Within the keyword, the first argument will be assigned to the local variable ${first_name}, and the second argument will be assigned to ${last_name}.
I have written a few test cases but some of them can be reused instead of writing them again in the new scripts. So if I have an Input text keyword for one field declared on one page how can that be used in an another test cases w/o having to mention the same keyword and locator again.
You can create a user defined Keyword in robot framework and paste your test case scripts inside the keyword then use keyword to execute your tests
Follow this documentation to create a user defined keywords,
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#creating-user-keywords
I would advise you to look at this Link
Robot Framework allows the use of Keywords, I would suggest to create a diffrent folder with all the keywords e.g To open the browser or login with a user to website or what ever you want.
You can create your logic inside the keyword section, and then pass the Name of the Custom Created keyword (Equal String) to the Test script.
Example of Keywords.
keywords.robot
*** Keywords ***
Equal String
Should be equal Hello Hello
Tests.robot
*** Settings ***
Resource keywords.robot
*** Test Cases ***
Validate Equal String
Equal String
You can only share keywords, not tests.
https://github.com/robotframework/robotframework/issues/2591
I have declared a variable in Variables section and initiated as ${Empty}.
Assigned the value in the TestCase and accessing the same in other keyword, it showed as ${Empty}.
my sample code is as below:
*** Variables ***
${fields} ${Empty}
*** Test Cases ***
Sample Code
${fields}= Get Service Details
Validate Service Details
*** Keywords ***
Get Service Details
... code for Get Service Details
[Return] ${fields}
Validate Service Details
${sValue}= Get Text ${serviceXpath}
Should be Equal As Strings ${fields} ${sValue}
Here, my question is, i delcared ${fields} in Variable section, i assigned value comes from the keyword Get Service Details, i want to use the updated value in Validate Service Details section.
I thought, as i have declared the variable in variable section, the updated value will be there in Validate Service Details keyword, but it displayed empty value.
How I can get updated value in Validate Service Details keyword
In Get Service Details, call Set Test Variable, Set Suite Variable, or Set Global Variable instead of (or in addition to) using [return] to make the changes visible outside of the keyword scope.
*** Keywords ***
Get Service Details
... code for Get Service Details
set test variable ${fields}