microsoft / WinAppDriver

Windows Application Driver
MIT License
3.7k stars 1.4k forks source link

WPF desktop application launching twice through WinAppDriver #918

Open nimmi810 opened 5 years ago

nimmi810 commented 5 years ago

Hi,

I am trying to automate a WPF desktop application. It gets launched two times when I say: DesiredCapabilities cap=new DesiredCapabilities(); cap.setCapability("app", "C:\Program Files (x86)\XXX\Bin\XXX.UserIntrface.exe"); driver=new WindowsDriver(new URL("http://127.0.0.1:4723"),cap); After launching twice , it also loses the session. Eclipse console: Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{app=C:\Program Files (x86)\XXX\Bin\XXX.UserInterface.exe, platformName=Windows}], required capabilities = Capabilities [{}] Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000' System info: host: 'XXXXX', ip: 'XXXX', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_211' Driver info: driver.version: WindowsDriver at io.appium.java_client.remote.AppiumProtocolHandShake.lambda$1(AppiumProtocolHandShake.java:95) at java.util.Optional.orElseThrow(Unknown Source) at io.appium.java_client.remote.AppiumProtocolHandShake.createSession(AppiumProtocolHandShake.java:95) at io.appium.java_client.remote.AppiumCommandExecutor.doExecute(AppiumCommandExecutor.java:111) at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:162) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at io.appium.java_client.windows.WindowsDriver.execute(WindowsDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:144) at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:88) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:112) at io.appium.java_client.windows.WindowsDriver.(WindowsDriver.java:43) at com.automation.testing.hydraulics.LaunchApplicationWinApp.launchNHP(LaunchApplicationWinApp.java:17) at com.automation.testing.EndToEndAutomation.MainTestClass.main(MainTestClass.java:16)

In winappdriver logs i can see that the POST is happening thrice, is it correct? WinAppDriver Logs: Windows Application Driver listening for requests at: http://127.0.0.1:4723/ Press ENTER to exit.

========================================== POST /session HTTP/1.1 Accept-Encoding: gzip,deflate Connection: Keep-Alive Content-Length: 346 Content-Type: application/json; charset=utf-8 Host: 127.0.0.1:4723 User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_211)

{"capabilities":[{"desiredCapabilities":{"app":"C:\Program Files (x86)\XXX\Bin\XXX.UserInterface.exe","platformName":"Windows"}},{"requiredCapabilities":{}}],"desiredCapabilities":{"app":"C:\Program Files (x86)\XXX\Bin\XXX.UserInterface.exe","platformName":"Windows"},"requiredCapabilities":{}} HTTP/1.1 400 Bad Request Content-Length: 131 Content-Type: application/json

{"status":23,"value":{"error":"no such window","message":"Cannot find active window specified by capabilities: appTopLevelWindow"}}

========================================== POST /session HTTP/1.1 Accept-Encoding: gzip,deflate Connection: Keep-Alive Content-Length: 163 Content-Type: application/json; charset=utf-8 Host: 127.0.0.1:4723 User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_211)

{"desiredCapabilities":{"app":"C:\Program Files (x86)\XXX\Bin\XXXl.NHP.UserInterface.exe","platformName":"Windows"},"requiredCapabilities":{}} HTTP/1.1 400 Bad Request Content-Length: 131 Content-Type: application/json

{"status":23,"value":{"error":"no such window","message":"Cannot find active window specified by capabilities: appTopLevelWindow"}}

==========================================

POST /session HTTP/1.1 Accept-Encoding: gzip,deflate Connection: Keep-Alive Content-Length: 184 Content-Type: application/json; charset=utf-8 Host: 127.0.0.1:4723 User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_211)

{"capabilities":[{"desiredCapabilities":{"app":"C:\Program Files (x86)\XXX\Bin\XXX.NHP.UserInterface.exe","platformName":"Windows"}},{"requiredCapabilities":{}}]} HTTP/1.1 400 Bad Request Content-Length: 141 Content-Type: application/json

{"status":100,"value":{"error":"invalid argument","message":"Bad capabilities. Specify either app or appTopLevelWindow to create a session"}}

Please help in resolving this. I want a solution to launch the application once and identify elements on the opened session.

VijayHugar commented 5 years ago

As error message suggest, add below capability

cap.SetCapability("deviceName", "Windows");

nimmi810 commented 5 years ago

Hi Vijay,

Thank you for your response. I have added the capability suggested by you but issue remains the same. Any other suggestions?

pm90pl commented 5 years ago

Is WinAppDriver running with admin privileges ?

nimmi810 commented 5 years ago

Yes, it is running with admin privileges, but still not working

licanhua commented 5 years ago

You can try app Microsoft.WindowsCalculator_8wekyb3d8bbwe!App first. It will help you verify the capability setting.

If your app C#, you may need to escape for \

cap.setCapability("app", @"C:\Program Files (x86)\XXX\Bin\XXX.UserIntrface.exe");
cap.setCapability("app", "C:\\Program Files (x86)\\XXX\\Bin\\XXX.UserIntrface.exe");
nimmi810 commented 5 years ago

Hi, It works fine with calculator. I am using Java. I am facing this issue since it is a WPF application.

anunay1 commented 5 years ago

which version of WAD are you using

PandaMagnus commented 5 years ago

Have you tried putting a breakpoint right before the lines of code where you set the capability, and then stepping through one at a time? Also, are you setting an implicit wait anywhere? It almost looks like the app launches, but WAD can't work out what the window is supposed to be so it's retrying. I've seen this in weird cases where, for example, a splash screen appears before the main window, or if (even worse) a main process is used to launch the "main" window as a child.

Ginjitzu commented 1 year ago

Hello.

I know this thread is old but it's still open so I thought I'd mention that I'm having the same (or similar issue), though it's intermittent rather than persistent. Occasionally, when running my code,

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability("platformName", "Windows");
capabilities.SetCapability("deviceName", "WindowsPC");
capabilities.SetCapability("appWorkingDir", Config.AppWorkingDir);
capabilities.SetCapability("app", Path.Combine(Config.AppWorkingDir, "My.exe"));
capabilities.SetCapability("appArguments", "--automation --developer");
capabilities.SetCapability("newCommandTimeout", 1500);  // 25 minutes

try
{
    Driver = new MyDriver(new Uri(@"http://localhost:4723/wd/hub"), capabilities);
}

my target application will also open twice.

MyDriver just extends WindowsDriver by the way, but doesn't really add anything that I can see.

I am using Win App Driver 1.2.1.0 and Appium Server GUI 1.22.3-4.

As I said, the issue is intermittent so I can live with it if need be, but I'd appreciate any help if it's available.

Thanks.