How to avoid TypeError when calling keyword from the "Run Keyword If" (Robot Framework) - robotframework

I have a nested dictionary inside another dictionary created in .py file.
When I am calling it like that
FOR ${key} IN #{keys}
I fill "${key}" tab on Applicant page with "${data}[${key}]" data
END
it works absolutely fine. However, if I use this call
Run Keyword If $ADD_TO_BANKING_KEY in $keys I add Applicant to Banking with "${data}[${ADD_TO_BANKING_KEY}]" data
I always get an error "TypeError: Expected argument 1 to be a dictionary or dictionary-like, got string instead." when I am trying to use the argument as a dictionary inside "I add Applicant to Banking with ..." function.
Example of the "${data}[${ADD_TO_BANKING_KEY}]": {'Member No.': 'DO_NOT_CHECK', 'Benefit': 'Regular', 'Reason Opened': 'radio'}
How can I solve this issue and do it in the right way?
Thank you!
Update:
First function:
I add Applicant to Banking with "${data}" data
Log To Console \#\#\# I add Applicant to Banking with "${data}" data
I fill "Add To Banking" tab on Applicant page with "${data}" data
Second Function:
I fill "${tabName}" tab on Applicant page with "${data}" data
Log To Console \#\#\# I fill "${tabName}" tab on Applicant page with "${data}" data
#{keys}= Get Dictionary Keys ${data}
FOR ${key} IN #{keys}
I input "${data['${key}']}" to "${key}" element in "${tabName}" tab on "Applicants" page
END
There is a place where it is failed
#{keys}= Get Dictionary Keys ${data}
Third function:
I input "${value}" to "${elementName}" element in "${tabName}" tab on "${pageName}" page
[Documentation] Input ``value`` to ``elementName`` element in ``tabName`` tab on the ``pageName`` page
Log To Console \#\#\# I input "${value}" to"${elementName}" element in "${tabName}" tab on "${pageName}" page
${tempLocator}= Get Locator From DOM ${RETAIL_DOM} ${pageName} ${elementName} ${tabName}
SeleniumExtendedResource.Input Value ${tempLocator} ${value}

Related

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?

webscraping with rvest, select content in form

I am using rvest to web scrape a particular website. On the website I need to select for example the date and the location that I want to display.
library(rvest)
session<-html_session(url)
form<-html_form(read_html(url))[[1]]
I can now set different values e.g. for the date.
set_values(form, from="08.02.2018")
and on the console appears: < input text > 'from': 08.02.2018
as well as for the other element "location": < select > 'location': [0/3]
My question is how I can set the value for "location". I know the different elements of "location" from the manual dropdown. Still:
set_values(form, location="Location_A")
doesn't work. No selection is visible and when submitting the form with
result<-submit_form(session,form)
A red message is on the console (Submitting with 'Location'). The result is an object with class "session", which I wasnt able to read with
html_table(result)
With Error: Error in UseMethod("html_table") :
no applicable method for 'html_table' applied to an object of class "list"
I started with
html_table(result[1])
However, none was working, same error.

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

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

Selecting list values automatically results in StaleElementReferenceException

In my search page I have a list with an input box and 'Go' button. I get the list value in my console but what I want is to iterate the list and enter the text (text is static) in the input box. Every time the list is selected it automatically searches rather than having to press the 'Go' button.
WebElement search_list = driver.findElement(By.xpath("//*[#id='tl_tPlace']"));
List <WebElement> li = search_list.findElements(By.tagName("option"));
for(int i =0; i<li.size();i++){
System.out.println(li.get(i).click());
try{
driver.findElement(By.xpath("//*#id='cmain_Place']")).sendKeys("text");
Now the first time the list has "select the state" it passes for the 2nd loop and it selects the list item. Once selected, the page reloads. Then there's an error message:
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
This is entirely expected behavior, since the DOM is completely recreated when the page, so any references you have to elements will become invalid after the page refreshes.

Resources