0

I am new to the WinAppDriver Windows Based Automation. Kindly help me to launch my windows application through winappdriver.

String applicationPath = System.getProperty("user.dir")+"/Data/TestData/StudioSetup.exe";
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("app", applicationPath);
WindowsDriver driv = new WindowsDriver(new URL("http://127.0.0.1:4723"), capabilities);

It launches my application, but it takes long time to open the window. In the meanwhile, it throws the below exception in the 4th line: -

org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: Failed to locate opened application window with appId: C:\Users\Peenu\git\Uptime/Data/TestData/StudioSetup.exe, and processId: 7208 (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 7.17 seconds
Rachit Jain
  • 103
  • 2
  • 11
  • In the error you provided, I see you mix slashes and back slashes in the same path for your `applicationPath` variable. I'm not sure this is the issue, but I would deem it safer to only use one or the other, not both. – PixelPlex Jun 14 '19 at 07:09
  • Also, did you start WinAppdriver.exe? It needs to be started (manually or by your test script) in order to execute tests. – PixelPlex Jun 14 '19 at 11:42

3 Answers3

1

This worked for me:

AppiumOptions appOptions = new AppiumOptions();

appOptions.AddAdditionalCapability("app", "PATH TO YOUR EXE");
appOptions.AddAdditionalCapability("deviceName", "WindowsPC");
appOptions.SetLoggingPreference(OpenQA.Selenium.LogType.Server, OpenQA.Selenium.LogLevel.All); //optional

WindowsDriver<WindowsElement> driv = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appOptions);
PixelPlex
  • 749
  • 5
  • 21
  • What to do if this throws the exception "The specified executable is not a valid application for this OS platform"? I am trying to launch a shortcut file (.lnk file) with the above code. – Balaram Dec 31 '21 at 19:30
  • Hi @Balaram, I'm not sure, never tried to do this with a shortcut. One consideration though, should you really be testing a shortcut? I mean, the shortcut is functionality provided by whatever OS you are using to launch your application. Unless you intend to test the OS or the success of a program setup, I don't think that's a very useful thing to do. – PixelPlex Jan 06 '22 at 12:46
0

See if this works

    Process.Start(@"<WinappDriver.exe path>");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.SetCapability("deviceName", "WindowsPC");
    capabilities.SetCapability("app", @"<Path to application.exe>");
    BasePage.WindowsDriver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), capabilities);
    Thread.Sleep(10000);    //Uncomment if required 
    BasePage.WindowsDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
Avinash
  • 188
  • 5
  • Thread.Sleep isn't good practice. [Here](https://saucelabs.com/blog/how-to-avoid-threadsleep-in-test-automation) is why you should avoid it. – PixelPlex Jun 14 '19 at 07:16
0

The application path is incorrect. Copy the path of your exe file using these steps:

Go to the application folder

Press the SHIFT key and right click the application icon

Select "Copy as path" from context menu

Now go back to your code and paste this value there.

Put an @ before the string

For example, the path to notepad looks like the following.

@"C:\Windows\System32\notepad.exe"

Naeem A. Malik
  • 995
  • 4
  • 19