I try TestStack.White to run an automation for JAVA app, here in my example is Calculator coded in JAVA, under VS2015 in C#. I installed TestStack.White using NuGet and tring with Winform app and it works, but here with java app, I can open the application, But not all component I can click on it.
So I try to know the component name with UIA Verify interface, but it selects the whole window, after that I look for something similar to UI Verify, and I found Ranorex STudio with Track Features and it works I can see Java Component name, but after I know the name, and I searsh for it in the app, the code not working. This is my code:
class Program
{
static void Main(string[] args)
{
Application aa = Application.Launch("..\\..\\CalculatorOrange.jar");
Window calcWindos = aa.GetWindow("Calculator Lite - 1.5.3", InitializeOption.NoCache);
Button twoBtn = calcWindos.Get<Button>(SearchCriteria.ByText("8"));
twoBtn.Click();
//var twoBtn = calcWindos.Get<MenuBar>("mnuFile");
//twoBtn.Click();
}
}
and it shows this error:
An unhandled exception of type 'TestStack.White.AutomationException'
occurred in TestStack.White.dll
Additional information: Failed to get (ControlType=button or
ControlType=check box),Name=8
This image shows the component type and name
Update 1 : On the left, I use Ranorex Spy, and it shows all the Component, and on the right the Inspect for Microsoft
Related
I have a selenium test (selenide to be precise) where the scenario requires a file upload.
The element to which I'm uploading the file is a hidden input field which is located at the end of DOM;
<input type="file" style="height: 0; width: 0; visibility: hidden;" tabindex="-1" accept="*">
and appears only after clicking on the area where the file is supposed to be "drag&dropped" or loaded from the system;
<a class="browse" ref="fileBrowse" href="#">select files...</a>
that means I am unable to use any method I've known until now without the need to click the element first - e.g., sendKeys, uploadFile, uploadFromClassPath, etc. However, the moment I click the element, a dialog window appears. After loading the file, the window won't close and I have yet to find a robust solution to close that window.
Situation how the dialog window looks within the macOS and chrome setup
I am using macOS and chrome, which means I cannot use "autoIT", and I was not able to run "sikuliX" either to create a simple screenshot script.
I was able, however, to scramble up an applescript using Automator which worked fine provided we omit the web driver's instance existence. Meaning; if I run the script from the console, setting the website exactly as the automated test would find it - it works... Unfortunately, it does not work once the test instantiates and runs within the webdriver.
I have two questions I hope someone with more experience could answer:
1) How to make the applescript use the webdriver's instance and not the regular chrome window - should this be solved somehow, it's a pretty neat solution
2) Any other idea on how to close the upload dialog window?
The applescript
on run {input, parameters}
-- Click “Google Chrome” in the Dock.
delay 6.006100
set timeoutSeconds to 2.000000
set uiScript to "click UI Element \"Google Chrome\" of list 1 of application process \"Dock\""
my doWithTimeout( uiScript, timeoutSeconds )
return input
-- Click the ÒCancelÓ button.
delay 3.763318
set timeoutSeconds to 2.0
set uiScript to "click UI Element \"Cancel\" of sheet 1 of window \"PowerFLOW portal - Google Chrome\" of application process \"Chrome\""
my doWithTimeout(uiScript, timeoutSeconds)
return input
end run
on doWithTimeout(uiScript, timeoutSeconds)
set endDate to (current date) + timeoutSeconds
repeat
try
run script "tell application \"System Events\"
" & uiScript & "
end tell"
exit repeat
on error errorMessage
if ((current date) > endDate) then
error "Can not " & uiScript
end if
end try
end repeat
end doWithTimeout
the code used to run the script within the test
try {
new ProcessBuilder("/path/to/the/script").start();
} catch (IOException e) {
e.printStackTrace();
}
}
Besides trying to use the applescript, I've tried "java robot class" but I wasn't able to close the dialog window.
Using the snippet below, the uncommented part escapes the entire chrome window (the window goes "grey"/inactive) and not the dialog window, which honestly surprised me, as I have thought the dialog window was the main working window at that moment.
The part that is commented works, but as you can imagine, it is useless, should the test be run on any other machine as the coordinates are specific to my machine only.
try {
Robot robot = new Robot();
//robot.mouseMove(906, 526);
//robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
//robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.keyPress(KeyEvent.VK_ESCAPE);
robot.keyRelease(KeyEvent.VK_ESCAPE);
} catch (AWTException e) {
e.printStackTrace();
}
The method itself looks just about like this
$$x("#ElementsCollection")
.findBy("text1")
.scrollIntoView(true)
.find(byXpath("#xpath")).val("text2")
.find(byXpath("#xpath") //this is the location of the <a> element mentioned above that needs to be clicked in order for <input type file> element to appear
.click();
$x("//input[#type=\"file\"]").sendKeys("/path/to/the/uploadedFile");
As I see, the original complexity on the way to achieve the goal is
the file is a hidden input field
and appears only after clicking on the area where the file is supposed to be "drag&dropped" or loaded from the system;
I.e. – the hidden file. Correct me if am wrong:)
But this should not be the problem, because the Selenium WebDriver's sendKeys command works with hidden elements of input tag with type=file. So just simple sendKeys should pass. The Selenide's uploadFromClassPath command is based on the original sendKeys - so it should pass too.
Here is a simple test that shows that uploading file does not depend on visibility of input element:
import org.junit.jupiter.api.Test;
import static com.codeborne.selenide.Condition.hidden;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selenide.*;
import static com.codeborne.selenide.Selenide.$;
public class TheInternetTest {
#Test
void fileUpload() {
// GIVEN
open("https://the-internet.herokuapp.com/upload");
executeJavaScript(
"document.getElementById('file-upload').style.display = 'none'"
);
$("#file-upload").shouldBe(hidden);
// WHEN
$("#file-upload").uploadFromClasspath("temp.txt");
$("#file-submit").click();
// THEN
$("#uploaded-files").shouldHave(text("temp.txt"));
}
}
Check the full working project with this code here: https://github.com/yashaka/selenide-file-upload-demo/blob/main/src/test/java/TheInternetTest.java
P.S.
The common best practice when writing Web UI Tests is "find the simple way to reach the goal instead of the best way in context of real user simulation". That's why we try to bypass all windows that are out of control for application under test. So my recommendation would be - forget apple script, and work with the input file directly through selenium webdriver.
I am using Winium + Java for automation testing of Windows application, and trying to access tool bar menu.
When I tried to detect elements using UI Automation Verify, I couldn't see child elements under tool bar element like below screenshot.
enter image description here
But my tool bar definitely has sub menu items like screenshot and I need to access them.
enter image description here
I tried below java code, but it didn't work
WebElement el = driver.findElement(By.id('59398'));
el.click();
WebElement child = el.findElement(By.name('Start'));
child.click();
when I tried
driver.findElement(By.name"Start').click();
it clicked my windows start menu, not my application's menu.
Is there any way to access items under this tool bar?
You can try use another UI Inspector
eg. UI SPY or Inspector.exe
Probably your ID is not a AutomationID (process id?)
You should find a main window (parent of your app) (Example for calc) and get a parameter like AutomationId, ClassName or Name
I see this is MFC application, and this is an app side MFC library problem. If you hover mouse over toolbar button using Inspect.exe, the info is available but you can't reach this button from the hierarchy (the buttons have no parent somehow). Possible workaround involves combined Win32 API and UI Automation approach:
get button rectangle using Win32 API (but there is no text).
use ElementFromPoint method of UI Automation API and get actual texts to choose the right button.
P.S. My suggestion is applicable for Java + Winium in theory. But I can't estimate the complexity because I'm not a Java expert. So below is Python solution.
We have plans to implemented this mixed way in pywinauto. See issue #413. It contains Python code sample how to do that. We've had no chance to integrate it yet.
from ctypes.wintypes import tagPOINT
import pywinauto
app = pywinauto.Application().start(r'.\apps\MFC_samples\RebarTest.exe')
menu_bar = app.RebarTest.MenuBar.wrapper_object()
point = menu_bar.button(0).rectangle().mid_point()
point = menu_bar.client_to_screen(point)
elem = pywinauto.uia_defines.IUIA().iuia.ElementFromPoint(tagPOINT(point[0], point[1]))
element = pywinauto.uia_element_info.UIAElementInfo(elem)
print(element.name)
I have tried eclipse GIT sample to open SWT browser
Ref : http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet260.java
This code works on Windows without any problem .But I get below exception in Linux.
I am developing an eclipse plugin which has repository setting page which is created by extending "AbstractRepositorySettingsPage" in the overrided method #Override "public void run(IProgressMonitor a_monitor) throws CoreException" I am creating Display in this method
Update :
This code works if I run it through main() method in Linux.
org.eclipse.swt.SWTError: Not implemented [multiple displays]
Root exception:
org.eclipse.swt.SWTError: Not implemented [multiple displays]
at org.eclipse.swt.SWT.error(SWT.java:4423)
at org.eclipse.swt.widgets.Display.checkDisplay(Display.java:767)
at org.eclipse.swt.widgets.Display.create(Display.java:908)
at org.eclipse.swt.graphics.Device.<init>(Device.java:156)
at org.eclipse.swt.widgets.Display.<init>(Display.java:507)
at org.eclipse.swt.widgets.Display.<init>(Display.java:498)
at com.test$OpenPage.run(test.java:267)
at org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage$29.run(AbstractRepositorySettingsPage.java:1964)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
AFAIK above exception is caused because it tries to create a new Display object So I tried to create the Display with existing NON UI thread and open the browser
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable()
{
public void run()
{
Shell aShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
Shell myShell = new Shell (aShell , SWT.SHELL_TRIM);
// Very important, generally parents must have a layout set to display children
myShell.setLayout (new FillLayout());
Browser browser = new Browser (myShell, SWT.NONE);
browser.setUrl ("http://www.google.de");
myShell.layout();
myShell.open();
}
});
The above snippet opens the browser but it does not allow to enter anything in the opened search engine. I want to enter in the available text box and also It does not close the opened browser on click of close button. I terminate the eclipse.
I have integrated the GWT application with Chrome packaged app with help of DirectLinkerinstaller like the code below:
public class CSPCompatibleLinker extends DirectInstallLinker {
#Override
protected String getJsInstallLocation(LinkerContext context) {
return "com/google/gwt/core/ext/linker/impl/installLocationMainWindow.js";
}
}
But now I want to call print function from Chrome packaged app. When I call window.print() it allows me to print current window, but I need to open a new separate window and print that.
Could you anyone please help me in this?
I can't answer anything about GWT or DirectLinkerinstaller, but here's an answer about Chrome Apps, assuming that's what you're asking about:
You use the chrome.app.window.create API to create a window. Then, you can call the print method for that window.
In my apps, I seldom want to print what's in a window, but rather something I've generated specifically for printing. For that, I create a PDF with jsPDF (Google it), which works well. Then I display the PDF in a window, and let the user print the PDF (or save it).
I have recorded the GUI desktop application using SIKULI as below:
App.open ("C:\\Program Files\\acd\\bin\\VPNClient.exe")
sleep(1)
type ("mganda1")
sleep(1)
click( ) //click OK
I want to convert this script into Java. So I am trying as below:
package com.arcot.test.vpn;
import org.sikuli.script.*;
public class AuthLogin {
public static void main(String[] args) {
Screen s = new Screen();
App myApp = new App("application-identifier") ;
myApp.open ("C:\\Program Files\\acd\\bin\\VPNClient.exe");
//How to simulate the type, sleep and click functions here?
I am searching for java examples to understand the objects relation and how to use it to simulate the recorded scripts. Please provide if any of you know the links that help me.
Best regards,
Madhu
After your program, proceed in following way:
package com.arcot.test.vpn;
import org.sikuli.script.*;
public class AuthLogin {
public static void main(String[] args) {
Screen s = new Screen();
App myApp = new App("application-identifier") ;
myApp.open ("C:\\Program Files\\acd\\bin\\VPNClient.exe");
Kindly proceed in this way,
-Create one image folder inside your package "img"
-Copy all the respective images in the img folder
-Assign the image names in a folder to a different variables
For doing operations, use follwing command:
s.type("mganda1");
s.sleep(time);
s.click("ok.png");
Regards,
Npesik
Madhu,
I'm not sure why you recorded the script to lunch that app with sikuli. All of the commands yu use don't invoke any images and can all be written without the sikuli ide.
I would make the following changes to your original sikuli/jython script
App.open ("C:\\Program Files\\acd\\bin\\VPNClient.exe")
sleep(1)
//change to
wait(path to image, FOREVER)
//By changing to a wait there is an implicit find as defined by the path to the image
type ("mganda1")
//if there are issues verifying focus invoke type with the img option
sleep(1)
//use wait instead of sleep
click( ) //click OK
//What are you clicking on?
Regarding Java, here's the link to Sikuli javadocs