How to dismiss browser plugin alert in Robot framework - robotframework

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

Related

Robot Framework Browser Library: Save and access PDF file returned by server

In my robot framework script I use the browser library to open a webpage and click on a button to get a receipt in PDF.
The button does not contain the direct link to the PDF: when you click the button, it opens a new page and after ~0.5 second the page returns a PDF file generated by the server.
I was not able to get and access the generated file in the Robot Framework script.
My tentative #1
I thought the PDF file could be captured by downloading it with a promise but it failed:
Click button.okButton
Switch Page NEW
${dl_promise} Promise To Wait For Download ./${SUITE_NAME}/downloads
${file_obj}= Wait For ${dl_promise}
File Should Exist ${file_obj}[saveAs]
Failure:
Tentative #1bis
${dl_promise} Promise To Wait For Download ./${SUITE_NAME}/downloads
Click button.okButton
Switch Page NEW
${file_obj}= Wait For ${dl_promise}
File Should Exist ${file_obj}[saveAs]
Same failure (TimeoutError: page.waitForEvent: Timeout 20000ms exceeded while waiting for event "download")
My tentative #2
The new page source code is the following:
<html><head></head><body><embed name="9AF27FA0E167C8860EB51FD926BE211B" src="about:blank" type="application/pdf" internalid="9AF27FA0E167C8860EB51FD926BE211B"></body></html>
I thought it is a local storage ID, am I right? So I tried the following:
Click button.okButton
Switch Page NEW
${sourceCode} = Get Page Source
${storageItem} = Get Regexp Matches ${sourceCode} (?<=(internalid="))(.*)(?=(">))
${myPDFfile} = Local Storage Get Item ${storageItem}
Log ${myPDFfile}
But seems it does not work:
... any idea how I should proceed? Thanks so much for your help and suggestions.
Keyword Promise To Wait For Download should be before triggering action. So the logic should be the following:
Promise
Trigger download
Wait for promise

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}

Manual input (Captcha) with Robot Framework?

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

Unable to handle the authenication dialog in firefox using selenlum webdriver

When I try to launch any URL a proxy authentication dialog pops up for username and password. The code (java) stops once the dialog appears and doesn't move further or throw an exception.
How can i handle this?
Note: This is happening only with firefox(v 22.0). I am able to handle the authentication dialog in IE(v 7) using the Robot send keys.
Webdriver: selenium-server-standalone-2.35.0
Firefox version : 22.0
testNG version: 6.8.7
I think it is because you are trying to reach HTTP authenticated page. The workaround is send username and password in url request like this:
driver.get("http://username:password#your-test-site.com");
where driver is assumed healthy living instance of WebDriver

Error downloading

to download a console returns the following error:
Frame load interrupted by policy change
Example:
Start Download
Console Preview:
Should I configure something in the Compiler or QWebSettings?
I discovered.
In conventional Webkit browsers, the place to download the console shows how the request canceled, so before turning to "download manager" of the browser the request should be canceled.
solution:
//replace [QWebView] by your WebView
connect([QWebView]->page(), SIGNAL(unsupportedContent(QNetworkReply*)),
this, SLOT(downloadContent(QNetworkReply*)));
...
void [main class]::downloadContent(QNetworkReply *reply){
//Replace "[main class]" by "Class" having the signs used in WebView.
[QWebView]->stop();
//solution: stop loading --replace [QWebView] by your WebView
/*function to donwload*/
}
Edit: hard to tell without a proper backtrace I requested in the comments, but it looks like the warning might actually be harmless.
Original:
That's because the QWebView doesn't know what to do with your app.exe file -- it's not an HTML page or a text/plain document or a supported image, after all. The QWebView class is not a web browser; you apparently want to start a download of some file, but there's no full-blown download manager in that class. You will have to provide your own code for this -- the code will have to ask for a proper location to save it, etc.
You can start with QWebPage::setLinkDelegationPolicy and handle this particular click yourself.

Resources