Java / WinAppDriver conflict

40 Views Asked by At

I am using WinAppDriver with Appium and Java/Eclipse. My Java code to get the WinAppDriver (from the testng test):

public static WindowsDriver getDriver() {
    try {
        if (!checkForRunning()) {
            String executable = Properties.getProperty("test.winappdriver.location", winAppDriver);
            Runtime.getRuntime().exec(executable);
            Thread.sleep(10000);
        }
    } catch (Exception ex) {
        throw new AssertionError(ex.getMessage(), ex);
    }

    HttpCommandExecutor exec = null;

    try {
        exec = new HttpCommandExecutor(new URL("http://127.0.0.1:4723/"));
    } catch (MalformedURLException e) {
        throw new AssertionError(e.getMessage(), e);
    }

    DesiredCapabilities dcaps = new DesiredCapabilities();
    dcaps.setCapability("automationName", "Windows");
    dcaps.setCapability("app", "Root");
    dcaps.setCapability("platformName", "Windows");
    dcaps.setCapability("deviceName", "Windows PC");
    WindowsDriver app = new WindowsDriver(exec, dcaps);
    return app;
}

Notice this checks to see if WinAppDriver is running and if it is not, then it starts it up. I am using this on a Windows File Chooser. My code is as follows (I have to type a file into a filename field, but there is more than one field with that nam, so I noticed the second one .get(1) is the correct one to use. Assume "wdriver" is the driver returned by the above,

 List<WebElement> g = wdriver.findElements(By.name("File name:"));
 if (g.size() < 2) {
            System.out.println("*** retry");
            g = wdriver.findElements(By.name("File name:"));
 }
 g.get(0).sendKeys(" ");
 WebElement clickIt = g.get(1);
 clickIt.click();
 String curdir = System.getProperty("user.dir");
 // add Keys.ENTER to file name to close it, since the OK button is hard to find
 String f2 = StringUtils.join(curdir, "\\", fileName, Keys.ENTER);
 clickIt.sendKeys(f2);
        

When WinAppDriver is already running (what is, I start it from the file explorer) everything works fine. If, however, it is not running and the code starts is up then I get an error. The error is a concurrent timeout exception. I catch this exception and have it halt.

Now here is the thing. When it halt because of the concurrent error, and I hit the red square (stop) on Eclipse, then the file name is sent correctly to the windows file chooser dialog. So it is as if the Java process were prohibiting the WindowsDriver from sending the data. Could this be true? Is there a way to get around it, or will we always have to start WinAppDriver.exe from a file explorer window? We need to use appium apparently if we want to use the Selenium grid.

This test also uses regular Selenium to navigate to a web site and do everything up to (and including) clicking "File" from the website to open the windows file chooser.

For info I am using are selenium-java 4.5.0, and java-client 8.1.1 (it needs to be these because later versions all seem to cause an error about not being able to cast an ImmutableMap to Capabilities)

So does what I say make sense? Any suggestions?

0

There are 0 best solutions below