I'm able to select a random value from a list but I'm not able to enter that value in the search box. The thing is input text requires two arguments i.e the locator & the value. I'm stuck with the value part now
*** Variables ***
#{cin} U74999KA2016PTC096782 U22012CH1993PTC012939 U65999MH2016PTC287488
*** Test Cases ***
Search
input text ${SEARCH_BAR}
${value} Evaluate random.choice($cin) random
log to console \nvalue: ${value}
click element ${SEARCH_BUTTON}
You are trying to generate a random value after you try to input blank text into the box
Change your code to
*** Variables ***
#{cin} U74999KA2016PTC096782 U22012CH1993PTC012939 U65999MH2016PTC287488
*** Test Cases ***
Search
${value} = Evaluate random.choice($cin) random
input text ${SEARCH_BAR} ${value}
log to console \nvalue: ${value}
click element ${SEARCH_BUTTON}
Related
Anyone know is it possible for the keyword to keep same variable name as it received?
Following short example will add values to list.
Once it has been updated it needs to be set as a new variable (If i add "${first_list_values}" as test variable after new list insertion, it will only work with one specific list) and the same keyword can't be used anymore.
Id much rather use same keyword to loop multiple lists.
**Keyword**
Change List value
[Arguments] ${received_list}
${new_list} Insert Into List ${received_list} 0 xxx
Set Test Variable ${new_list}
**Test Cases*
Checking new list values
Change List value ${first_list_values}
Maybe something like this:
*** Settings ***
Library Collections
*** Variables ***
#{ORIGINAL_LIST} First Second
*** keywords ***
Change List value
[Arguments] ${received_list}
Append to List ${received_list} Appended Third Appended Fourth
[return] ${received_list}
*** Test cases ***
Use Return
Log To Console ORIGINAL_LIST: #{ORIGINAL_LIST}
#{ORIGINAL_LIST}= Change List value ${ORIGINAL_LIST}
Log To Console ORIGINAL_LIST AFTER CHANGE: #{ORIGINAL_LIST}
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}.
I want to create a unique string in robot framework each time I run my script.
*** Settings***
Library Selenium2Library
Library String
*** Variables ***
${RANUSER} Generate Random String 10 [LETTERS]
*** Test Cases ***
Enter Random Username
Input Text //input[#id='userInput'] ${RANUSER}
Using this, I always get Generate Random String 10 [LETTERS] as my output but I want unique output all the time. Can anyone please help me.
TY
Generate Random String is a keyword. So you need to call it as a keyword. E.g. like this:
*** Test Cases ***
Enter Random Username
${RANUSER} Generate Random String 10 [LETTERS]
Input Text //input[#id='userInput'] ${RANUSER}
Or by the custom keyword:
*** Keywords ***
Create Random User
${RANUSER} Generate Random String 10 [LETTERS]
[Return] ${RANUSER}
I am trying to create a unique string by embedding epoch time stamp after a static string as:
*** Keywords ***
Unique Title
[Return] ${title}
${secs}= Get Time epoch
${time}= Convert To String ${secs}
{title}= Catenate SEPRATOR=- Title ${time}
*** Test Cases ***
Test_Enter_Unique_Text
Open Browser #{urlUnderTest}
Input Text name=alertTitle Unique Title
Its not working I am not able to get the return value of Unique Title keyword, in the input box text is getting entered as "Unique Title".
Any suggestions will be really helpful.
You have to call the keyword and save what it returns, then use the saved value in the test case:
*** Test Cases ***
Test_Enter_Unique_Test
${title}= Unique Title
...
Input Text name=alertTitle ${title}
I want to create a random string, assign it to a variable and enter that variable into a text box. How can I do this?
Don't know how to use SELENIUM.SETTEXT with the assigned variable. I've done the following so far:
${RANUSER} = Generate Random String 6 [LETTERS]
Have you imported the correct libraries :
*** Settings***
Library Selenium2Library
Library String
*** Variables ***
${RANUSER} Generate Random String 10 [LETTERS]
*** Test Cases ***
Enter Random Username
Input Text //input[#id='userInput'] ${RANUSER}