I want to replace ${assertion_Keyword} by Screen Should Contain or Screen Should Not Contain so i want to put an Argument like a keyword
check_element_and_its_representation
[Arguments] ${assertion_Keyword} ${payload} ${on_click_payload}
${assertion_Keyword} ${payload}
SikuliLibrary.Click ${payload}
Screen Should Contain ${on_click_payload}
With this code i code a syntax error no keyword found :
How can this action be possible? is there other ways to do it ?
Thanks.
The Run Keyword command will help you with that. Below is an example inspired on your example code. I've commented out the Sikuli keywords, but kept them in place and added two keywords to mock those found in the Sikuly Library.
*** Test Cases ***
TC Screen Should Contain
Check Element And Its Representation Screen Should Contain payload on_click_payload
TC Screen Should Not Contain
Check Element And Its Representation Screen Should Not Contain payload on_click_payload
*** Keywords ***
Check Element And Its Representation
[Arguments] ${assertion_Keyword}=Screen Should Contain ${payload}=None ${on_click_payload}=None
Run Keyword ${assertion_Keyword} ${payload}
# SikuliLibrary.Click ${payload}
# Screen Should Contain ${on_click_payload}
Screen Should Contain
[Arguments] ${var}
Log Screen Should Contain
Screen Should Not Contain
[Arguments] ${var}
Log Screen Should Contain
Related
Here I want to pass only specific variable value and should get other values as default but I am not getting that...
Ex: I want to pass only word2 variable value and want to get word1 value as default Like "Hello See"
*** Keywords ***
Check order
[Arguments] ${word1}=Hello ${word2}=World
log to console word1 is : ${word1}
log to console word2 is : ${word2}
*** Test Cases ***
Test case 1
Check order ${word2}=See
Test case 1 | FAIL |
Variable '${word2}' not found.
The way to do this is to use only the variable name to the left of the equals:
Check order word2=see
This is from the robot framework user guide, in a section titled Named arguments
When the named argument syntax is used with user keywords, the argument names must be given without the ${} decoration. For example, user keyword with arguments ${arg1}=first, ${arg2}=second must be used like arg2=override.
robotframework
I used this code:
Page Should Contain Textfield xpath: //*[contains(text(), "${date}")]
But that searches literally (Dutch: letterlijk)
The actual content could be:
value-example1${date}value-example2
So there can be some text in front and some text after the variable...
I tried this but that didn't work
Page Should Contain Textfield xpath: //*[contains(text(), "*${date}"*)]
so * before the ${date} and * after the ${date} ..... (but that doesn't work)
The reason xpath: //*[contains(text(), "*${date}"*)] didn't work is because xpath will look for text with literal asterisks. You don't need the asterisks, contains takes care of that because it looks for your requested string anywhere in the element's text.
Here is an example using contains. First, save the following to /tmp/example.html:
<html><body>
<div><h1>Some text, January 1, 2020, and more text </h1>
</body></html>
Next, save this to example.robot:
*** Settings ***
Library SeleniumLibrary
Suite Setup open browser ${URL} ${BROWSER}
Suite Teardown Close all browsers
*** Variables ***
${URL} file:///tmp/example.html
${BROWSER} chrome
${date} January 1, 2020
*** Test Cases ***
Example
Page should contain element xpath://*[contains(text(), "${date}")]
When you run this test with robot, it should pass because the element contains the string stored in ${date}.
so there is a website: https://www.guruwatch.nl/Aandelen/Default.aspx
I click the element 'koop' and then I want to verify that the value in the top is bigger then 10
id="ctl00_ctl00_ContentPlaceHolder1_RightContent_ListAandelen_repAandelen_ctl01_lblCountBuy"
what is the fastest way to do this?
i used
Element Text Should Be ctl00_ctl00_ContentPlaceHolder1_RightContent_ListAandelen_repAandelen_ctl01_lblCountBuy 24
but that is for the exact match, i just want to verify the integer is bigger then 10.
there is also an
Should Be Equal As Integers first second
builtin
but not a
Should Be Bigger As Integer
Should be Smaller As Integer
p.s. why are those not builtin? is it so strange to use this?
There are plenty of ways of checking if one value is larger than another with the * If keywords that can be found in the BuiltIn Library. Below is an example of how you can craft the larger than keyword:
*** Test Cases ***
Test Positive
${value} Set Variable 24
Should Be Larger Than ${value} 1
Test Negative
${value} Set Variable 24
Run Keyword And Expect Error * Should Be Larger Than ${value} 100
*** Keywords ***
Should Be Larger Than
[Arguments] ${value_1} ${value_2}
Run Keyword If ${value_1} <= ${value_2}
... Fail The value ${value_1} is not larger than ${value_2}
In order to do this, you need to find the xpath locator first. Since the xpath is quite long so, I just assign it to a variable as below.
${top_position_xpath}= set variable //span[#id='ctl00_ctl00_ContentPlaceHolder1_RightContent_ListAandelen_repAandelen_ctl01_lblCountBuy'
${get_number}= GET TEXT xpath=${top_position_xpath} ## --> This is xpath locator for that top column
${check}= SHOULD BE TRUE ${get_number} > 10 # --> The current test will fail if the result is false..
Okay, so I summarize the steps I use above here:
Get the xpath locator for the specific column that you want to verify.
Use the GET TEXT keyword to get the exact output (number) of that column.
Verify using the SHOULD BE TRUE keyword. This keyword is sufficient to verify the condition.
But just to highlight, that if you use the SHOULD BE TRUE keyword as above, the test will fail immediately, so a good approach is to use with keyword RUN AND RETURN STATUS and assign a variable to tell either the condition is true or false, so that you can proceed with your next code or statements..
${result}= RUN KEYWORD AND RETURN STATUS SHOULD BE TRUE ${get_number} > 10 #
Before I read the messages I solved it myself this way:
Should Match Regexp ctl00_ctl00_ContentPlaceHolder1_RightContent_ListAandelen_repAandelen_ctl01_lblCountBuy [0-9]{1}[0-9]{1}
How Can we use value returned from one keyword as input argument to other keyword directly (without assigning return value to variable)
Currently I am maintaining all Web Elements or Variable names and corresponding xpath in an Excel Sheet. I get XPath using keyword read_xpath by passing web element/variable name as argument.
I store the xpath in separate variable then make use of it for other or Next line keyword. Since I need to use a variable for each XPath access, i am trying to find out, whether is there any way to directly use one keyword output as input to other keyword without assigning it to variable.
The main purpose of storing XPath in Excel sheet is to avoid multiple test cases change with single Element XPath change, making just single change on Excel Sheet should be sufficient.
For Example:
read_xpath reads values from a Excel sheet, Excel sheet has two columns, one variable name and second one is xpath. Function read_xpath(element) takes variable name as input and gives back xpath.
xlread.py file looks like xlread.py code Excel Sheet look like Excel sheet
sample.robot file looks as below
${login_user_textctrl}= read_xpath username_textctrl
clear element text ${login_user_textctrl}
Input text ${login_user_textctrl} admin
Now let us check how I used read_xpath keyword in my robot file
I called Keyword read_xpath with argument username_texctrl, which returns xpath for username text Control which is stored in variable ${login_user_textctrl}. Now Input Text ${login_user_textctrl} admin works fine.
For below code
clear element text read_xpath username_textctrl
I am getting, clear element text requires 1 argument but two arguments provided, is there any way i can use the the value returned from Keyword(read_xpath) as input to other keyword directly, without assigning it to any variable?
Thanks in advance.
Separating your locators from your robot code through an Object Repository is often done when the locators are reused a lot. An alternative implementation paradigm is to use the Page Object Model. An example of such an implementation can be found in the Robotframework-PageObjectLibrary.
In case you still prefer the Object Repository approach, then using the Selenium2Library keyword Add Location Strategy might be of interest to you. Below is a working example which uses a YAML file as it's OR to fetch the search input box and search button from Google.
ObjectRepo.yaml
OR:
searchbox: '//input[#id="lst-ib"]'
searchbutton: '//button[#id="_fZl"]'
Robot Script
*** Settings ***
Library Selenium2Library
Variables ObjectRepo.yaml
*** Test Cases ***
Yaml Object Repository
[Setup] Add Location Strategy yro Yaml Locator Strategy
Open Browser http://www.google.com Chrome
Input Text yro=searchbox Robot Framework
Click Element yro=searchbutton
Sleep 3s
[Teardown] Close All Browsers
*** Keywords ***
Yaml Locator Strategy
[Arguments] ${browser} ${criteria} ${tag} ${constraints}
${xpath}= Set Variable ${OR.${criteria}}
${retVal}= Get Webelement xpath=${xpath}
[Return] ${retVal}
As you can see the abstraction through a custom locator keyword allows for clearner code and not require you to fetch into a variable for later reuse.
You can use Evaluate to call python functions directly. Example:
${my element to clear}= Evaluate read_xpath("username_textctrl") xlread
See the documentation here
(Note: Example is untested and you should check if xlread is in PYTHONPATH, or found at test run time)
When I execute this keyword, 'No keyword with name 'and' found error is displayed.
Test this keyword
[arguments] ${YearDiff} ${MonthDiff}
Run Keyword If ${YearDiff}>=0 and ${MonthDiff}>=0 Click Element id=Left_Calendar_Icon
Run Keyword If ${YearDiff}<=0 and ${MonthDiff}<=0 Click Element id=Right_Calendar_Icon
Correct me if i have used wrong syntax.
You are using the space-separated format, which means that robot uses two or more spaces to separate keywords. You have two spaces on each side of "and" so robot thinks "and" is a keyword. The entire expression needs to fit in a single cell of the test case table.
The solution is to put only one space on each side of "and":
Run Keyword If ${YearDiff}>=0 and ${MonthDiff}>=0 Click Element id=Left_Calendar_Icon