How to capture alert box using Robot Framework - robotframework

I try to capture alert screenshot but in the screen doesn't show alert box.
For Example:
AlertTest
Open Browser http://www.seleniummaster.com/robotframeworktest/alerttest.html ff
Sleep 5s
Click Button name=alert_button
sleep 10s
capture page screenshot
Alert Should Be Present This is an alert box
Close Browser
If anyone has experience could you help me please.

To my understanding it is not possible to capture the alert with SeleniumLibrary, because the alert in not a part of the page.
We walk around this by using the BuiltIn Screenshot library and the KW Take Screenshot.
You could try and consider if it meet your requirements.

The behavior you're seeing is due to the Alert should be present keyword automatically accepts the alert. It happens so fast that if often looks that it never happened. By adding the optional parameter action=LEAVE you can check without modifying the behavior. The Keyword documentation shows other options.
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
AlertTest
Open Browser http://www.seleniummaster.com/robotframeworktest/alerttest.html chrome
Sleep 2s
Click Button name=alert_button
Alert Should Be Present action=LEAVE text=This is an alert box
Handle Alert action=ACCEPT
Close Browser
Although this will solve your: I don't see the Alert part of the problem, you will run into the next one. Taking a screenshot using SeleniumLibrary will not work because of the now present Alert. As suggested earlier, this can be taken care of by the Screenshot Library keyword Take Screenshot .
Please read the Using with Python section carefully as this library depends on Operating System specific Python modules.

Related

click element in robot framework is not working

Click Element is not working in Robot Framework, in the log.html it shows that it clicked on element, but it does not actually happen on the browser
This application is not an Angular JS application.
I have tried the same functionality in other application which is an Angular JS, it worked fine.
My Robot code is as below:
*** Settings ***
Library Selenium2Library
*** TestCases ***
Login to Application
Open Browser ${url} ff
Maximize Browser Window
Select from List by value id=selectedCountry MU
Input Text id=userid rajaint
Input Password id=password rajaint1
Click Element id=Submit1
what can be the reason for this?
I'm stuck in automation, as I stopped at the login.
I cannot share the application url as it is confidential.
After having a chat with Sarada - We discovered that the issue was on his application. The problem was the application had to lose focus of the drop down menu and the username field in order for the validation to pass through - and allowing more input from robot.
After some trail and error, we figured out how to lose focus of an element and allow the validation to work as intended; which in return meant everything else worked smoothly!
I suggested Focus but that did not work so instead we forced it using:
Press Key id=userid \\9
Which sends a Tab to the browser. Making it lose focus and making the validation tick over!
In the end the Robot File looks like:
Open Browser ${url} ff
Maximize Browser Window
Wait Until Element Is Visible id=selectedCountry 10s
Click Element id=selectedCountry
Select from List by value id=selectedCountry MU
Click Element id=selectedCountry
sleep 2s
Focus id=userid
Click Element id=userid
Input Text id=userid rajaint
Press Key id=userid \\9
sleep 5s
Input Password id=password rajaint1
sleep 2s
Click Button id=Submit1
sleep 10s
Capture Page Screenshot
I have experienced the same problem but the Press Key Trick is not working.
I used this hack instead
Execute JavaScript
document.getElementById('Submit1').click()
And it's working fine
Similar problem was faced by me.
The JavaScript worked perfectly.
Execute Javascript document.querySelector('#HIRESearchTable > tbody > tr > td.searchLink > span').click();
For this kind of scenarios, you can use JavaScript Executor. But in most of these cases, you can't find the Id of the element. So I have implemented a common keyword which can be used with the xpath.
Click Element By JavaScript Executor [Arguments] ${elementXpathLocator} ${retryScale}
[Documentation]
... Click an element by xpath using javascript executor ...
Wait Until Keyword Succeeds 2x 1 s Wait Until Element Is Enabled ${elementXpathLocator}
Execute JavaScript document.evaluate("${elementXpathLocator}", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0).click();
Sleep 1s after you found the element. It works for me.

How to handle dynamic overlay using webdriver

While executing a selenium script, we are getting a overlay (like popup) which is asking to confirm yes or no.
In this case the main problem being the Overlay popup does not come at a constant place,instead it comes at differen places.
example :- consider we have 4 pages to navigate some time it comes in first page and some times it comes in second page, and sometimes
it comes in the same page while we are accessing different elements.sometimes we are not getting overlay.
please let me know how to solve this issue, Thanks in advance
You can handle that through driver options, at least in Internet Explorer. This is how I do in Selenium.NET binding
var options = new InternetExplorerOptions { EnableNativeEvents = false };
options.UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Dismiss;
It will force close any unexpected pop up.
Not sure that this is correct solution, but this must solution of your task.
You can create simple function(method) that checks for existence of this popup with some timeout. And put in in all possible places.
Or you can check it by some timer in another thread(with pause of main thread)

before closing the Application browser should prompt conformation

I have a small requirement..
if the user dint sign off or log off then he try's to close the browser IE clicking on 'X' (top right of IE or Firefox browser ) then i need to ask a conformation message like "Are you sure you want to close ?" ...
I am using Master page in my application and i tried the event : "window.onbeforeunload " in my master page its works fine, shows an alert(conformation) message. but if i press back button on the browser(IE on IE or Firefox) then also its firing(but it should not) is there any way to full fill my requirement ..I hope i had explained u clearly...if not pl z let me know........
what i mean to say is.. if the Session("USerid") is active or if it contains any value ie.
Session("USerid")="XXX"
at that moment if user trys to close the browse(click in 'X'/Close button browser either IE or Firefox ) it should give prompt a message "are u sure do u want to close?"..
Its all about design steps - but the close and the back button is the same, the close the page, so maybe its impossible to have them all together.
To open, close your script you can make a simple trick. Place them inside a literal and open or close it.
<asp:literal run="server" id="txtCloseAlert">
<script>
... you code here ....
</script>
</asp:literal>
and on code behind.
txtCloseAlert.visible = !string.IsNullOrEmpty(Session("USerid"));
I've looked into this recently and there does not appear to be a standard / consistent way to do this cross-browser hence you back-button problem.
On IE at least you get an event object passed as a parameter to the onbeforeunload method that you can use to get the mouse position, but in FireFox you don't and you would need some other way to determine whether a confirmation is required. It is quite posible that you could get the mouse position in some other way as I haven't looked into that. Point is that if your mouse is not on your form you probably want a confirmation.
You can look at this SO question:
Prevent browser from closing in asp.net
Or do an Internet search on 'onbeforeunload prevent browser closing'.
In your case a synchronous ajax call can be made to the server to do the test.
HTH

how do i use firebug or chrome console instead of alert() to see variable values?

how do i use firebug or chrome console instead of alert() to see variable values?
currently, I want to see the value of var i as it increases. Not sure that it's increasing.
You probably want to use console.log(). It just prints the parameters in the firebug console.
More info can be found on http://getfirebug.com/logging.
You can use a breakpoint on this variable. You can find explanations for the Chrome Inspector here: http://code.google.com/chrome/devtools/docs/scripts-breakpoints.html
You could use something like the YUI Logger control - http://developer.yahoo.com/yui/logger/ - which puts a log window on your webpage that you can write debugging messages to and clear/hide/etc.
Or you could try a javascript shell bookmarklet that opens a separate shell in the context of the main window. One example is available at https://www.squarefree.com/bookmarklets/webdevel.html, and there may be others.

Wrapping AVCam demo from WWDC 2010

I have three camera-based apps (that take still pictures) in the app-store and have got feedback that the UIImagePickerController interface is very slow - and I can't deny that. So, to improve the performance of the app, I started to experiment with the AVCam Demo source code from the WWDC 2010.
Since the AVFoundation framework does not interact with the UI Kit, I have been successful at wrapping a view around the demo. I am able to transition between the view controllers successfully. The only thing that I've modified is replaced the Record button with the Exit button (to exit to the wrapping view controller)
The modified app works fine during the first session (wrapper -> demo) If I exit the demo to the wrapper, and come back to the demo second time , the video frame in the preview layer freezes a second or two after. The app itself does not freeze - just the video is frozen. At this point, all UI buttons are active. But, when I tap "Still" button to capture the image, I get the following error in an alert:
The operation cannot be completed (AVFoundationErrorDomain error - 11800.)
This cannot be duplicated in the original demo code - because you can't close and reopen the session. So, I am wondering if it has anything to do with the way I "exit" from the session in my test. Here's the "exit" action that I added in the demo code:
- (IBAction)exit:(id)sender
{
[[self captureManager] stopRecording];
[self dismissModalViewControllerAnimated:YES];
}
Is this sufficient - or did I miss something?
Regards, Sam.
There's a little problem of cleaning up a capture session in an orderly fashion, as there's some asynchroneous calls with no alerts of when they're done.
Try stopping and releasing as suggested in this question:
How to properly release an AVCaptureSession
(take the solution with most up votes)
If that doesn't help you may need to post some more code here. Are you sure that's all you changed?
Good luck!
Oded.

Resources