Accessing Windows dialog boxes from Selenium and java - java

I am testing web site functionality with Selenium using Java from Eclipse. One test is to click a "download" button, look for a popup window (this is another selenium window), respond to that window which should then cause a Windows download dialog to pop up (please see attached image).
Please note. I do not have to actually download the file. Just verify that the windows dialog popped up.
I know from experience (or at least am unaware) that Selenium can actually access the Windows download box, choose a file location and start the download. But all I need to do is verify that the download box popped up. Exiting the chromedriver will kill the download window so it won't linger but I still need to verify it was created.
Any suggestions? One thing I tried was having the task manager open. I thought I could find a process corresponding to the dialog box, but there were 119 processes before the dialog box came up as well as when it was up. So any suggestions what to do?
I could add as an aside that someone wrote a workaround to actually download the file. Instead of clicking on a button or link he pretended to be the Windows dialog box and accepted the download. That, for reasons I stated above, will not work in this instance as I have to verify the actual results of clicking the button.
Please see my attached image for an example of the dialog box.

One workaround to meet this test requirement is, once you responds to the window which results in a Windows download dialog, try performing the next action. This will result in a WebDriverException as the access to UI will be blocked by the Windows dialog. You can then catch this WebDriverException and in the catch block press escape key using Robot class in Java. Following is an example:
try {
//1) Respond to the window that results in Windows dialog box.
//2) Perform the next action on UI.
} catch (WebDriverException we) {
//3) You can capture screen shot as well at this stage.
System.out.println("Most likely Windows dialog appeared.");
//4) Press escape key using Robot class in Java
Robot r = new Robot();
r.keyPress(KeyEvent.VK_ESCAPE);
}

You can use AutoIT to check if the windows dialog appears, then save the status of the windows dialog in somewhere(eg. a temp file), then you read the status of the windows dialog using Java from Eclipse

Related

How can Take permission using an alert Box at just destroy the application in Android

I just want to show an alert box at just killing the application in android.
It's like a Notepad application, if we simply kill the app (on clicking the close button) then we get an alert box asking for save changes.
I just want to add same thing in my application.I have tried onBackPressed() and its working fine on clicking on Back Button. But I need same thing on closing the application.
There is now way to be sure if the app is being closed but you can place a check if the application is in foreground or not which is a better metric IMHO as this tells you when the user moved away from your application.
To check the ProcessLifeCycleOwner this will help you find state of process. You can check this Github sample or this stackoverflow question in how to use it.

Selenium WebDriver : Verify Print Window text

I have a scenario to verify Print Properties dialog opening up correctly after clicking on Print button. Aware of Robot utility class in Java which can emulate keyboard events like Escape/Enter etc. to operate on that window.
Is there any way we can verify the new dialog opened up is a Print dialog - something to verify dialog title i.e. Print or retrieve text from that windows dialog or something else which will confirm dialog to be a Print dialog.
You can use an image based automation tool. I use SIKULI which is based on JAVA Robot class. http://www.sikuli.org/
In SIKULI, you have to take the screenshot of the pop up or its title and then use it for comparison. SIKULI is available as a JAVA API and can be integrated with Selenium. SIKULI also procides a optical image recognition feature using tesseract. This can also be used to verify the title of the popup.
Hope this helps you.

Clicking button on File Download window

During automated testing using Selenium-2 we are clicking on the link and which opens the "File Download" window. And I want to click on "save" button and save the file to the disk.
Selenium2 doesn't support handling of filedownload on its own. So I have written a AutoIT script to click on the save button and it works successfully if we are testing the web application on the local machine. In remote machine if I am running this script it hangs if I close the Remote Desktop (RDP).
One thing is we don't know what will be the link which will be clicked. We will be only knowing that one "File Download" window is existing and which may not be on the top or active. But I need to click on save button.
So, is it possible to handle file download popup window in other way?
If we can handle it AutoIT then its very good. but other than AutoIT suggestions are also welcome. Like if we can do using some other APIs or scripts. But to run the script/solution it would be good if we do not need to install any other software.

Window Dialogs & Popup handling in Java or Javascript

I need to manipulate Popups & Download Dialogs of IE browser using either Java or
Javascript based automated solution.
I tried with selenium2 but its not working properly so any other suggestion for the same.
Actually selenium2 does not provide proper handling of alert/download dialogs so
I am thinking to use some other javascript/java solution.
With Download Dialog: I need to save the downloaded file to particular location.
With Alerts Dialogs: I need to check the displayed message and click on the particular button.
Any suggestion is appreciated.
Thanks.
I use selenium 1 and it works well to handle popups in my application.
//Click on browse file button, open a popup
selenium.click("//input[#value='Browse...']");
//waiting for popup to load
selenium.waitForPopUp("_Dialog", "30000");
//selecting the popup by passing window name
selenium.selectWindow("name=_Dialog");
//click a link inside pop up window
selenium.click("link=something");
//Put other popup operations here
//click cancel button for pop up
selenium.click("cancel");
//back to main window
selenium.selectwindow("null")
To get the message from alert boxes, use selenium.getAlert();. This will return the message contained in the alert box as String.
Also, sometime you will need to check, whether alert has occurred before switching to it.
int noofWindows = selenium.getAllWindowNames().length;
if (noofWindows > 1){
//selects the second window
selenium.selectWindow(selenium.getAllWindowIds()[2]);
//Prints the message in the alert window
System.out.println(selenium.getAlert());
}
If it is not a necessity to run test in IE, use firefox(*chrome) and close all other windows before executing the code.
I hope this helps you.
*All the mentioned code is for handling JavaScript pop-ups. I'm not sure whether this will work for Vb-script or not.
EDIT
I think IE download pop up is a windows event so cannot be handled by selenium directly, for this you'll have to use Java AWT or AutoIT.
AutoIT script should be something similiar to
WinWaitActive(windowTitle)
ControlClick(windowTitle,"",buttonName)
and save it as IEsave.exe. NOTE: I'haven't tried this AutoIT script.
now you have execute IEsave.exe from your program. I'm using java here.
java.lang.Runtime.getRuntime().exec("c:/IEsave.exe");
This will execute the file which in-turn will handle the save button event for windows.
You can create similar exe files for handling other window's events.
Hope this solves your problem.

Swing: Steal focus from other apps (usability in OS X)

I have an application in java swing which runs in the system tray most of the time. The user can use the Tray Menu to perform several actions. One of those actions is to show the app window. The problem I have is with usability on OS X.
In windows, if the user brings up the app window and later switches to another app, they can switch back to my application using the taskbar. But in OS X, the app runs in a mode in which the app does not have a menu and also will not appear in the Command + Tab list.
__LSUIElement is set to true in the info.plist file
So my problem is that if the user opens the app window, later switches to another app, they cannot switch back unless they click on the window itself (which could be behind many other windows). The simplest way is for the user to open the window again using the tray icon, but since the window is already open I am unable to bring it to the front.
So, How to I take focus away from other applications and bring my window to the front?
EDIT:
My issue is not with getting the 'Application running as agent'. I already have that working. The issue I have is to get my program window to the top when its created. I am unable to do this in java.
You can call activateIgnoringOtherApps: with a true parameter when the user clicks on the icon in the menu bar (or however you open the window). You'll have to hook into Cocoa from Java, though.
The code provided in the answer to the question below did the trick
How to bring a window to the front?
After much effort trying to do the same thing, I found that the following was the simplest solution for me:
try {
String[] cmd = new String[2];
cmd[0] = "open";
cmd[1] = "/Applications/MyApp.app";
Runtime.getRuntime().exec(cmd);
}
catch(Exception ex) {
//ignore since there's nothing else that can be done
}
Essentially, I chose to execute another process through the JVM which uses the "open" command on Mac OS X to open the app that wraps the java program that created the tray icon. Telling it to open itself again causes the window to be brought to the front since it is already running.

Categories