I want to write script test frontend by RobotFramework but I don't know how to choose a date in Datepicker calendar by RobotFramework.
To choose date on datepicker create following keywords:
Select Datepicker Date
[Documentation] Select given day from datepicker
[Arguments] ${dateElem} ${expectedMonthYear} ${clickElement}
Input Text ${dateElem} ${Empty} # open the datepicker
${monthyear}= Get Datepicker MonthYear
:FOR ${Index} IN RANGE 1 31
\ Run Keyword If '${monthyear}' == '${expectedMonthYear}' Exit For Loop
\ Click Link //*/div[#id='ui-datepicker-div']//*/a[contains(#class, 'ui-datepicker-prev')]
\ ${monthyear}= Get Datepicker MonthYear
Click Link ${clickElement}
Get Datepicker MonthYear
[Documentation] Return current month + year from datepicker
[Return] ${monthyear}
${month}= Get Element Text //*/div[#id='ui-datepicker-div']//*/div[#class='ui-datepicker-title']/span[#class='ui-datepicker-month']
${year}= Get Element Text //*/div[#id='ui-datepicker-div']//*/div[#class='ui-datepicker-title']/span[#class='ui-datepicker-year']
${monthyear}= Catenate ${month} ${year}
And then use Select Datepicker Date keyword with required arguments in your Test Cases.
This Below link is a working solution to use RobotFramework to choose date from datepicker
datepicker_robotFramework
Related
Here's my list
#{referentiel} N1(exemple)/N2(exemple) N2(exemple)/exemple
where i use it
Visca barca
[Arguments] ${index}
Click Element Using Javascript //div[#id='mat-select-value-5']
Click element of long page //span[#class='mat-option-text'][contains(.,'#{referentiel}[${index}]')]
And my testcase
we are the best
Visca barca 1
Error :
Value of variable '#{referentiel}[${index}]' is not list or list-like.
The issue you are describing here has nothing to do with the semicolons or slashes. The issue is actually that you are attempting to return the list item with wrong decorator.
To get a single item from a list you should use $ instead of #. When you use # Robot will attempt to return you a list which it cannot since the item on ${index} is a string.
See below:
#{referentiel} # == ['N1(exemple)/N2(exemple)', 'N2(exemple)/exemple']
or
${referentiel[0]} # == N1(exemple)/N2(exemple)
i'm using Robot Framework Keyword Subtract Date From Date to test that a date is between 2 dates(For example 11/06/2020 is between 07/06/2020 and 20/06/2020), but i'm getting an error in my log file ValueError: Invalid timestamp. The date is a String extracted from a Span Text and i convert it to date This is my code :
${date}= Get Current Date result_format=datetime
${postdate}= Get Text xpath://app-post[1]//div[1]//div[1]//div[1]//div[2]//div[1]//div[2]//div[1]//div[2]//span[2]
${postdate}= Convert Date ${postdate} date_format=%d/%m/%y
${date}= Convert Date ${date} result_format=%d/%m/%y
${temp} = Subtract Date From Date ${postdate} ${date}
Should Be True ${temp}>=0
The problem is you don't follow the allowed format for the keyword Subtract Date From Date mentioned here: https://robotframework.org/robotframework/latest/libraries/DateTime.html#Date%20formats
%y will give you 20, but that obviously is not enough. If I change it to %Y, it will give me 2020 for the current year, and the keyword Subtract Date From Date doesn't complain anymore about invalid timestamp. You'd also need to change it to something like date_format=%Y/%m/%d, that is to change the order of %Y, %m, and %d.
EDIT:
I can now see you're also using date_format as well as result_format with Convert Date. That's another bug in your code, you need to use result_format with both.
EDIT 2:
The full working example:
(And you're not using BuiltIn library here, these datetime keywords are from DateTime library)
The below script worked (Used the static PAST_DATE to check the sample run ):
${date}= Set Variable 21
${month}= Set Variable 12
${year}= Set Variable 2019
${PAST_DATE}= BuiltIn.Catenate SEPARATOR=/ ${year} ${month} ${date}
Log ${PAST_DATE}
${CURRENT_DATE}= Get Current Date result_format=%Y/%m/%d
Log ${CURRENT_DATE}
${DIFFERNCE_IN_DAYS}= Subtract Date from Date ${CURRENT_DATE} ${PAST_DATE} verbose
Log ${DIFFERNCE_IN_DAYS}
#{total_days}= Split String ${DIFFERNCE_IN_DAYS}
${final_days}= Set Variable ${total_days[0]}
Log ${final_days}
Should be true ${final_days} >= 0
I'm trying to enter a text into a message field using Input Key. Sometimes it enters all characters and other times it gets cut off. I've tried using Press Key but it does the same thing. Is there another solution?
Example:
Press Key id:noteMessage This is a note from the Robot Framework
What you could do, is insert a loop that runs for example a few times and tries each time to insert the text into the text field. During the loop you read the result of the text field, and if it matches the original text you try to input, you quit the loop.
For example something like:
${retries} = 3
${text} = "Some text that doesn't get fully displayed all the time."
${locator} = id:noteMessage
:FOR element IN RANGE 0 ${retries}
\ Input text ${locator} ${text}
\ ${inserted_text} = Get text ${locator}
\ ${result} = Evaluate ${inserted_text} = ${text}
\ Exit for loop if ${result} = True
Of course you can insert quite a few more failsafes, but this should be a good basis. And of course you should look into the problem why the field doesn't inserted sometimes the key or text.
In robot framework how can I change line in textarea that text comes to new line . Now I have the following code:
: FOR ${INDEX} IN RANGE 1 10
\ Input Text id=edit-message TestMessage\n
but now "TestMessage" writes on the previous one
Thanks!
It is typical to first fetch the value, then concatenate what you want added and then to overwrite the field with the new value.
: FOR ${INDEX} IN RANGE 1 10
\ ${textvalue} Get Text id=edit-message
\ Input Text id=edit-message ${textvalue}\nTestMessage
Try like this.
https://drive.google.com/file/d/1tWcdWLSy0zFTgVpiucOgVnScJJ0rX8SY/view?usp=sharing
Insert the $ {INDEX} index of the for loop into the input text locator to change the line and write to it.
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}