How to run keywords into multiple times - robotframework

My scenario:
There is field called "search first value" i have to click on Then click on Submit.
I have to repeat this step more than 100 times. How can i do in Robot framework?
MY code:
[Documentation] Resubmit
wait until element is enabled ${CLICK_RESUBMIT}
click element ${CLICK_RESUBMIT}
sleep 2s
confirm action
repeat keyword 5times Go to Previous Page

Standard library have keyword Repeat Keyword
http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Repeat%20Keyword

Related

Is there an alternative way to my below code?

I am looking for an alternative and smarter way to achieve the below action
***Keywords***
Insert Values
[Documentation] Keyword is used to insert value
${Status1} Run Keyword and Return Status Wait Until Element is Visible ${ONPDonorLocator} 1s
${Status2} Run Keyword and Return Status Wait Until Element is Visible ${CustomerScoreLocator} 1s
${Status3} Run Keyword and Return Status Wait Until Element is Visible ${ContractDurationLocator} 1s
${Status4} Run Keyword and Return Status Wait Until Element is Visible ${OptionsInstalledLocator} 1s
${Status5} Run Keyword and Return Status Wait Until Element is Visible ${OrderAddsDeletesLocator} 1s
${Status6} Run Keyword and Return Status Wait Until Element is Visible ${SiteCategoryLocator} 1s
Run Keyword If '${Status1}'=='True' Wait and Click ${ONPDonor} ${LocatorWaitTime}
Run Keyword If '${Status2}'=='True' Wait and Click ${CustomerScore} ${LocatorWaitTime}
Run Keyword If '${Status3}'=='True' Wait and Click ${ContractDuration} ${LocatorWaitTime}
Run Keyword If '${Status4}'=='True' Wait and Click ${OptionsInstalled} ${LocatorWaitTime}
Run Keyword If '${Status5}'=='True' Wait and Click ${OrderAddsDeletes} ${LocatorWaitTime}
Run Keyword If '${Status6}'=='True' Wait and Click ${SiteCategory} ${LocatorWaitTime}
Expected:
Is it possible to click the locator that has '${Status}'=='True' instead of writing Status1, Status2, Status3 and so on?
I do not want to write the way I have written above. Tomorrow if I have to check status of few more locators then the lines will keep on getting added.
Note: I am still learning, so any suggestions are welcome.
Yes, by using a loop and storing only the locators that are visible; then you loop over the stored ones, and click them:
${visible}= Create List
FOR ${locator} IN ${ONPDonorLocator} ${CustomerScoreLocator} # etc, the others
${Status} Run Keyword and Return Status Wait Until Element is Visible ${locator}
Run Keyword If ${Status} Append To List ${visible} ${locator}
END
FOR ${locator} IN #{visible}
Wait and Click ${locator}
END
When you have more elements to wait for visibility and then click, you just add them in the first loop.

How to use values from one keyword to another keyword in robot framework

I would like to use value from keyword 1 to keyword 2. Tried searching on net but i could not able to solve it.
Verify that apps are listed
wait until element is visible ${AppMenuGrid} ${Timeout} "Apps NOT listed. Step execution failed"
log "Apps listed"
${APPSCOUNT} = GET ELEMENT COUNT ${AppMenuGrid}
log "Number of apps loaded are ${APPSCOUNT}"
[Return] ${APPSCOUNT}
Click on Refresh button
wait until element is visible ${Refresh} ${Timeout} "Refresh button is not visible"
click element ${Refresh}
log "click on refresh button successful"
Verify that same apps are listed
wait until element is visible ${AppMenuGrid} ${Timeout} "Apps list not refreshed. Step execution failed"
log "Apps list refreshed"
${APPSRECOUNT} = GET ELEMENT COUNT ${AppMenuGrid}
${Count} = verify that apps are listed ${APPSCOUNT}
log "Number of apps before refresh ${Count}"
log "Number of apps after refresh ${APPSRECOUNT}"
run keyword if "${APPSRECOUNT}" == "${Count}" log "Number of apps matching after refresh"
... ELSE fail "All apps not loaded after refresh"
I want to use AppsCount value (ex .10) from keyword "Verify that apps are listed" into "Verify that same apps are listed" keyword. But in the 2nd keyword, APPSCOUNT value is always blank.
Change the keyword Verify that same apps are listed to accept arguments:
Verify that same apps are listed
[Arguments] ${expected appscount}
# the rest of its code
And then, in the case where it's used, pass the value from the first keyword:
A case
${the count}= Verify that apps are listed
Verify that same apps are listed ${the count}
I agree with Todor Minakov's approach, to share the value via return clauses. Here is another approach:
Robot Framework (as described in the User Guide) has notion of variable scope: Local (Keyword) level, Test case level, Test suite level and Global. By default, the variables defined in the keywords have local scope.
To share the value of the variable between two keywords, just add a test case scope to the variable, like this:
Verify that apps are listed
wait until element is visible ${AppMenuGrid} ${Timeout} "Apps NOT listed. Step execution failed"
log "Apps listed"
${APPSCOUNT} = GET ELEMENT COUNT ${AppMenuGrid}
Set Test Variable ${APPSCOUNT}
Then, you can call ${APPSCOUNT} inside any other keyword in the same test case and it will have the stored value.
i tried the following and it worked.
In the test case file, i added a variables with the same name ${APPSCOUNT} and set the variables to the keyword like below,
Verify that apps are listed ${APPSCOUNT}
After this i can see value from keyword 1 in keyword 2.
Is this the correct approach?

Select window created using JavaScript

In My Robot Script , After clicking on Edit Description link a window get opens (i.e. Java Script Window) Images here
Image 1::
Image 2:: Window image Along with Page Source
What i need is a. Select the window (java script)
b. Enter text into Text Area and click Ok.
I tried to use Select Window new/ Select window Description But control is waiting infinite # Select Window key word its not moving forward. I have to kill Control forcefully.
*** Settings ***
Documentation Suite description
Library Selenium2Library run_on_failure=Nothing
Library Collections
*** Test Cases ***
Log into Command center
[Tags] DEBUG
open browser http://11.8.180.***/BCC ie
input text xpath=//*[#id='LoginName'] User
input password Password Pwd#123
click element LoginBtn
wait until keyword succeeds 30 sec 5 sec page should contain element AppTitle
sleep 3s
${Title} Get Page Title
log ${Title}
Navigation to Usrs
Click on Window popup and enter text
CloseBrowser
close all browsers
*** Keywords ***
Click on Window popup and enter text
Click Link //*[#id="aspnetForm"]/table/tbody/tr[1]/td[2]/a
Sleep 5s
Select Window By Unique Identifier Element With Delay //*[#id="descript"]
Select Window By Unique Identifier Element With Delay
[Arguments] ${element} ${delay_time}=10
sleep ${delay_time}
#{wins}= Get Window Handles
Log ${wins}<--these are window names console=true
:FOR  ${windowName}  IN  #{wins}
\   Log ${windowName} console=true
\ run keyword and ignore error Select Window  ${windowName}
\   ${found_flag}= run keyword and return status page should contain  ${element}
\   Run keyword if ${found_flag} input text ${element} this is text
\   exit for loop if ${found_flag}
Get Page Title
Log Control came to GET PAGE TITLE
run keyword and return Get Title
Navigation to Usrs
Go to http://11.8.180.***/BCC/role.aspx
Any Idea how to select new window? and enter text hit okay.
A.Get Window Identifiers --> Jus hangs it neither moves nor throw any error
B. Get Window Names gives this error {URLError: <urlopen error [Errno 10061] No connection could be made because the target machine actively refused it>..}.
C. Get Window Handles returns this { [u'b0ce0f28-f6d4-4943-93f7-f65fd5f1de2a', u'c0442110-4ea9-40a4-b126-eee09d9f3eb0']}
I am not sure how to identify which window have these id's
Thanks in Advance
It should be recognized as new window in your browser, so you can use:
Select Window Description

Unable to startup test. Unknown tests gets called for Robot Framework Test Execution

I'm surprised to see this error message when executing Test Automation using RobotFramework with RED editor. Plz guide me on this issue getting rectified.
I dont have any test case called "Filter the customer". When running my suite it shows up the below error.
Note: I did the below, even then I'm having this issue.
1. I cleaned the Project
2. I also deleted and re-added the modified libraries.
3. Saved all the updated files.
Error:
The source is as below,
*** Setting ***
Resource ../KCC_Automation/ResourceFiles/KCC_Resource.txt
*** Test Cases ***
Login with valid credentials
Logon to KCC browser
Enter User Name
Enter Password
Click Login
Show Customers available in Customer List Page
Get the customer names and click them from Customer List Page
Begin the New Assessment for an opportunity
Filter by Customer Search
Expand the customer details and begin the New Assessment
Stop Testing
Logout of KCC
And the resource file is as below,
*** Keywords ***
Welcome1
${message} say hi
Log ${message}
Welcome2
${message} say hi Testers
Log ${message}
Welcome3
${message} type of 42
Log ${message}
Logon to KCC browser
Open Browser ${LOGIN URL} ${BROWSER}
Wait Until Page contains Element ${UserName_Field}
Enter User Name
Input Text ${UserName_Field} ${USERNAME}
sleep 2s
Enter Password
Input Text ${Password_Field} ${PASSWORD}
sleep 2s
Click Login
Click Element ${LoginButton}
sleep 5s
Get the customer names and click them from Customer List Page
set selenium speed 5s
wait until element is visible ${customers_grid}
wait until page contains element ${customers_grid}
sleep 3s
#{customers} get webelements ${customer_list}
${items} Store Texts #{customers}
#${items} storeTexts #{customers}[2]
${store} get text ${items}
Log ${store}
Filter by Customer Search
set selenium speed 5s
input text ${Customer_Search} ${Search_Text}
sleep 3s
${Entered_text}= get value ${Customer_Search}
should be equal ${Search_Text} ${Entered_text} The given message is incorrect true
Expand the customer details and begin the New Assessment
wait until page contains element ${customer_list}
click element ${customer_list}
sleep 2s
click element ${opportunity-status}
sleep 2s
click element ${forward_button}
sleep 2s
click element ${Btn_Add_Building}
sleep 2s
Logout of KCC
In the source file, I re-placed the test case name "Begin the New Assessment for an opportunity" by "filter the customers" as because earlier i named this testcase like this, executing it showing up below issue now, Is this RED editor issue?
[ ERROR ] Unexpected error: NoClassDefFoundError:
org/openqa/selenium/WebElement
java.lang.NoClassDefFoundError:
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetPublicMethods(Class.java:2902)
at java.lang.Class.getMethods(Class.java:1615)
at robot.utils.importer$py.import_$32(C:\jython2.7.0\Lib\site-packages\robot\utils\importer.py:274)
at robot.utils.importer$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\utils\importer.py)
at robot.utils.importer$py._import_class_or_module$5(C:\jython2.7.0\Lib\site-packages\robot\utils\importer.py:77)
at robot.utils.importer$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\utils\importer.py)
at robot.utils.importer$py.import_class_or_module$4(C:\jython2.7.0\Lib\site-packages\robot\utils\importer.py:74)
at robot.utils.importer$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\utils\importer.py)
at robot.model.visitor$py.visit_suite$2(C:\jython2.7.0\Lib\site-packages\robot\model\visitor.py:88)
at robot.model.visitor$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\model\visitor.py)
at robot.model.testsuite$py.visit$19(C:\jython2.7.0\Lib\site-packages\robot\model\testsuite.py:161)
at robot.model.testsuite$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\model\testsuite.py)
at robot.model.itemlist$py.visit$11(C:\jython2.7.0\Lib\site-packages\robot\model\itemlist.py:75)
at robot.model.itemlist$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\model\itemlist.py)
at robot.model.visitor$py.visit_suite$2(C:\jython2.7.0\Lib\site-packages\robot\model\visitor.py:88)
at robot.model.visitor$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\model\visitor.py)
at robot.model.testsuite$py.visit$19(C:\jython2.7.0\Lib\site-packages\robot\model\testsuite.py:161)
at robot.model.testsuite$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\model\testsuite.py)
at robot.utils.application$py._execute$10(C:\jython2.7.0\Lib\site-packages\robot\utils\application.py:94)
at robot.utils.application$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\utils\application.py)
at robot.utils.application$py.execute_cli$5(C:\jython2.7.0\Lib\site-packages\robot\utils\application.py:49)
at robot.utils.application$py.call_function(C:\jython2.7.0\Lib\site-packages\robot\utils\application.py)
at runpy$py._run_code$9(C:\jython2.7.0\Lib\runpy.py:73)
at runpy$py.call_function(C:\jython2.7.0\Lib\runpy.py)
at runpy$py._run_module_as_main$14(C:\jython2.7.0\Lib\runpy.py:161)
at runpy$py.call_function(C:\jython2.7.0\Lib\runpy.py)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebElement
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 191 more
Looking at the error it seems to me that you don't have the Selenium2Library loaded Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebElement You can load a library by using the syntax:
*** Settings ***
Library Selenium2Library
Please keep in mind that this library requires either a pip install robotframework-selenium2library or to install the Java Port of the Selenium2Library
Although I can't be sure, I suspect that when this issue is resolved your other problem is also fixed.

How to simulate onblur event with Robot Framework

I am automating login scenario of an application.
The execution steps are as below:
Select the Country
Enter the Username
Enter the Password
Click on Login Button.
Actually after entered the username, application validates the country and username in database exists or not.
When tried to automate through robot framework, this validation is not called and so unable to login (actually login button is clicked through script, but no error message or no response user is in same page).
When i verified exact scenario it calling the validation, comes to know that
validation is called on onblur of the usename element onblur="getlocation()".
I tried to simulate this by give tabout from username field through script as
Press Key ${element path} \\9 but it is not working always out of 10 run only 3 or 4 times it working.
Is there any way we can do 'blur` action on the element in robot framework
In the Selenium2Library for robot, there is a special keyword for that:
Simulate <element> <event>
In my keyword definition it looks like this:
I Enter The New Password
[Arguments] ${text}
Input Text ${INPUT_ELEMENT_PASSWORD} ${text}
Simulate ${INPUT_ELEMENT_PASSWORD} blur
http://robotframework.org/Selenium2Library/Selenium2Library.html#Simulate
I hope that helps, it took us a while to figure out what was missing in the test.
Just to save few minutes of googling.
Simulate
is deprecated. Use
Simulate Event
instead

Resources