Manual input (Captcha) with Robot Framework? - robotframework

I'm writing an acceptance test for web using Robot Framework + Selenium2Library. The point is that web contain some input field that I can not automate (CAPTCHA), and I can't tell my vendor to turn off this feature while running test. So I have to input this field manually. Now I'm doing this:
Create User
[Arguments] ${username} ${password}
Open Browser ${URL} ${BROWSER}
Input Text username ${username}
Input Text password ${password}
Sleep 10 # XXX input CAPTCHA manually here!
Click Button submit
Page Should Contain ${username} has been created.
I've input CAPTCHA when I tell Robot Framework to Sleep 10, so far so good. But I wonder is there anyway to tell Robot Framework to wait indefinitely, then continue automate task after I finish input that CAPTCHA?

There is a keyword just for this purpose in the Dialog library that comes with Robot Framework.
Execute Manual Step Please complete the CAPTCHA portion of the form.

I can see a few options:
You can remove sleep and button clicking and do them yourself. Then you can use wait until page contains to continue after you has pushed submit button
Create User
[Arguments] ${username} ${password}
Open Browser ${URL} ${BROWSER}
Input Text username ${username}
Input Text password ${password}
Log Waiting for CAPTCHA
Wait Until Page Contains ${username} has been created. timeout=3600
You can also use Pause Execution keyword from Dialogs-library. This pauses execution until you click OK in a popup.
Create User
[Arguments] ${username} ${password}
Open Browser ${URL} ${BROWSER}
Input Text username ${username}
Input Text password ${password}
Pause Execution Enter captcha
Click Button submit
Page Should Contain ${username} has been created.
The most automated way I can think of is to use a CAPTCHA solving service. I believe they have an API where you send screenshot of your page and get a solved CAPTCHA back. I have never tried them and sharing screenshots of your software may not be an option.

You can also use the command- get value from user.
It opens the pop-up and tell user to insert the text value(Like enter captcha present at page), when user enters the captcha value and click on ok then this value gets insert into captcha window and next operation begins.
Code is:
#Use Library Dialogs
open browser http://sitename ff
input text id=name-id anytext
${Captcha} = get value from user Enter Captcha none none
input text id=captcha-id ${Captcha}
click element id=submit-id
Note: Use "Libray Dialogs" initially

Related

Robot Framework: get selection from user keyword inside a user defined keyword throws error 'Keyword name cannot be empty'

*** Settings ***
Library SeleniumLibrary
Resource ../Tests/Main.robot
Resource SSmthn.robot
Library Dialogs
Library Collections
*** Variables ***
*** Keywords ***
Select Browser: User Input
${value} = get selection from user Select Browser Begin Web Test with Chrome Browser Begin Web Test with headlessChrome
${value}
Begin Web Test with Chrome Browser
${options}= Evaluate sys.modules['selenium.webdriver.chrome.options'].Options() sys
Call Method ${options} add_argument --disable-notifications
${driver}= Create Webdriver Chrome options=${options}
go to ${URL}
maximize browser window
sleep 2sec
Begin Web Test with headlessChrome
open browser ${URL} ${Browser}
maximize browser window
sleep 2sec
End Web Test
close all browsers
Here Iam asking user for one of the 2 selections.
${value}: stores value from user selection but does not call the keyword selected by the user. What can I change here to make it work?
A keyword which name is stored in a variable can be executed by using the Run Keyword keyword from the BuiltIn library.
Select Browser: User Input
${value} = get selection from user Select Browser Begin Web Test with Chrome Browser Begin Web Test with headlessChrome
Run Keyword ${value}

How to report Data Driven in Robot Framework with different names of test cases?

I'm learning Robot Framework and I want to run a Excel file for my data of the test case.
When I run the code, The report shows all test case names are the same.
In my Excel file, the first column is "* Test Cases *". I want the name of test case will be chosen from there.
I am using Eclipse with Red Editor plugin of Nokia.
*** Settings ***
Library Selenium2Library
Library DataDriver ${CURDIR}/data/login_data.xlsx DataDriven
Resource ${CURDIR}/resources/login_resources.robot
Suite Setup Open Browser To Login Page
Suite Teardown Close Browser
Test Setup Open Login Page
Test Template Invalid Login
*** Test Cases ***
Login With Invalid Data ${USERNAME} ${PASSWORD}
*** Keywords ***
Invalid Login
[Arguments] ${USERNAME} ${PASSWORD}
[Tags] Flat
Input Username ${USERNAME}
Input Pass ${PASSWORD}
Click Submit Button
Create HalfTrip Menu Should Not Be Open

How to dismiss browser plugin alert in Robot framework

In our application, when I navigate between web pages, system is showing attached Browser Confirmation Alert. I am using Robot framework to automate. I tried accepting or Dismissing the alert using 'Handle Alert' keyword. But i am observing 'Alert not found' error in report. Also right click is disabled to find web element in the Alert window.
*** Settings ***
Library Selenium2Library
Test Teardown Close Application
*** Variables ***
*** Test Cases ***
Dismiss Alert
Open Aplication
Click WebElement ${serchXpath}
Click WebElement ${navigateXpath}
Wait Until Element Is Visible ${Inv_xpath_all_rows} timeout=60 seconds
Handle Alert action=DISMISS timeout=60 s
Fails with : Alert not found in 5 seconds. at the line Handle Alert action=DISMISS timeout=60 s
I am new to Automation world, Request you to help me. Thanks a lot.
Looking at the screenshot of the popup attached, it looks like you are dealing with an "External Protocol Request" box. You cannot interact with this box using selenium webdriver API. Instead you need to handle this using ChromeOptions or by editing the Chrome profile. Here is a SO answer that describes how to go about it.
To handle the same in RobotFramework using Selenium2Library, check this out.
${chromeOptions}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
${exclude}= Create Dictionary "fasp"=True
${prefs}= Create Dictionary protocol_handler.excluded_schemes=${exclude}
Call Method ${chromeOptions} add_experimental_option prefs ${prefs}
Create Webdriver Chrome chrome_options=${chromeOptions}
Source: https://support.asperasoft.com/hc/en-us/articles/216660968-How-to-unblock-the-launching-of-Connect-3-6-5-in-Chrome

Write a test template with multiple keywords

Is it possible to write a test template with multiple keywords?
I'm looking for something like:
Valid Login
[Template]
Given login page is open
When ${username} and ${password} are inserted
and user is on ${device}
Then welcome page should be open
root abc desktop
noman xyz laptop
It would be a bonus if I could use a list instead of a data table
The normal way is to create a new keyword that calls those keywords, and set the template in the settings:
*** Settings ***
Test template Valid Login
*** Test cases ***
root abc desktop
noman xyz laptop
*** Keywords ***
Valid Login
[Arguments] ${username} ${password} ${device}
Given login page is open
When ${username} and ${password} are inserted
and user is on ${device}
Then welcome page should be open

How do i get the web browser password store to remember R/Shiny passwords?

The problem
I have a shiny application that requires user to login to access the underlying dataset.
The username and password are collected from form fields and submitted via a RESTful API on another server to get an access token which is used in future requests. I haven't included those details in this example.
I want to get the web browser to remember the login details and login automatically, but can't quite see how.
What I tried
In my first implementation, the <input type="text" name="username"> and <input type="password" name="password"> plus an actionButton were dynamically added to the page. This forced the user to re-login each time the shiny application was restarted, which was complex for development and unpleasant for users.
I then found https://gist.github.com/kostiklv/968927 which details the conditions for having the web browser remember the password and log in.
Shiny works on one page, so I couldn't have a separate login page (this would generate a new shiny session, discarding the login!).
I have tried various combinations of things, here is the closest I have got. This script correctly fills in a past password, but the user still has to manually hit submit.
Example code
Note that I have a custom hack my shiny in to enable type="password" to be treated the same as type="text". See bottom of question for access to this code
save this code as login.R then run R and type source("login.R")
write("","blank.html")
require(shiny)
addResourcePath("login",tools:::file_path_as_absolute("./"))
runApp(list(
ui=bootstrapPage(
tags$form(action="#",target="loginframe",
tags$input(id="username",type="text",placeholder="Username"),
tags$input(id="password",type="password",placeholder="Password"),
tags$input(id="loginButton",class="btn btn-primary",type="submit",value="Login")
),
tags$iframe(name="loginframe",src="login/blank.html",style="display:none")
),
server=function(input, output) {
observe({message(
"username ",input$username,"\n",
"password ",input$password,"\n"
)})
})
)
Analysis of what happened
Note that the presence of an html input submit button seems to tell shiny that it should only update the inputs once every submit. Without the submit button shiny updates its inputs every keystroke.
The same is true for shiny's submitButton.
Leaving the form but removing the button allows input$username and input$password to reach the server code, but...
To enable both conventional user login and automated login, I need the button to avoid repeated attempts to authenticate (which might cause problems) for partial usernames and passwords.
Log of what happened
Here are the console logs from the tests
Log with a submit button:
username
password
<enter username AA and password BB>
*no update*
<hit submit>
*browser requests to save password / yes*
username A
password B
<refresh page>
username
password
* onscreen form inputs are populated *
<hit submit>
username A
password B
Log without a submit button
Comment out
tags$input(id="loginButton",class="btn btn-primary",type="submit",value="Login")
and the preceding comma
note you may want to tell your browser to forget localhost web passwords for now.
username
password
<enter username AA and password BB>
username A
password
username AA
password
username AA
password B
password BB
<refresh browser>
* onscreen form inputs are not populated *
* browser requests to save password *
username
password
<refresh browser>
* onscreen form inputs are populated *
username
password
username AA
username BB
Shiny patch to enable password handling:
Install using library(devtools)
install_github("shiny","alexbbrown",ref="password-field")
Or download and install manually:
https://github.com/alexbbrown/shiny.git (branch password-field)
Or patch your shiny manually:
index 9b63c7b..15377d8 100644
--- a/inst/www/shared/shiny.js
+++ b/inst/www/shared/shiny.js
## -1336,7 +1336,7 ##
var textInputBinding = new InputBinding();
$.extend(textInputBinding, {
find: function(scope) {
- return $(scope).find('input[type="text"]');
+ return $(scope).find('input[type="text"],input[type="password"]');
},
getId: function(el) {
return InputBinding.prototype.getId.call(this, el) || el.name;
cf Password field using R Shiny framework
I was looking for something similar, and trestletech's fantastic package shinyStore worked for me.
It enables HTML5 client-side data storage for any data in your shiny app.
The github page is here, and an example of how it works is here.
You may wish to read the "Security" section on the README and ensure it is secure enough for your purposes.
I believe that you can use postForm() from RCurl package to perform a regular HTTP form submit request (unless Shiny would interfere with this functionality, which is based on using underlying libcurl library). For an example code, please see function srdaLogin() in my R module "getSourceForgeData.R": https://github.com/abnova/diss-floss/blob/master/import/getSourceForgeData.R.

Resources