passing command line argument when launching an application
this is probably an appium issue. How to pass command line arguments when launching the test application. this is to get around the issue where splash screen causes no elements to be found because the currentwindowhandle is that of the splash screen and not of the currently displayed window. the splash screen disappears after a while but the currentwindowhandle points to the splash screen instead of the new window.
- How to pass command line argument when launching the test application?
- How to switch window handle to handle WPF applications which have possibly more than one window.
For workarounds to switching window handles, please see #105.
@daghb I'm looking more closely at your switchto suggestion. Interesting, seems like it could be a more elegant way to switch between windows. Thank you for posting that.
Is there a solution for part 1? I also need to pass some command line arguments to the app to start.
Any updates on point 1?
I've got WPF application that supports command line arguments. I need to test the application with different arguments as it affects the behaviour of the application.
+1
Since v1.0-RC release, Windows Application Driver can now launch an application with command line arguments. Below is an example of launching Notepad opening MyTestFile.txt in C:\MyTestFolder\ working directory.
// Launch Notepad
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", @"C:\Windows\System32\notepad.exe");
appCapabilities.SetCapability("appArguments", @"MyTestFile.txt");
appCapabilities.SetCapability("appWorkingDir", @"C:\MyTestFolder\");
WindowsDriver<WindowsElement> NotepadSession = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities);
The snippet above is taken from CreateSessionWithArguments_ClassicApp test scenario. Check out the README.md for more information on other supported capabilities.
For switching window handle on multiple windows application, you can refer to the SwitchWindows test scenario. Below is a generalized example on how you can enumerates all top level windows belonging to the application and switching to it.
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", YourAppId);
WindowsDriver<WindowsElement> session = new WindowsDriver<WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);
Assert.IsNotNull(session);
// Identify the current window handle. You can check through inspect.exe which window this is and whether this is in fact the splash screen or the right window
var currentWindowHandle = session.CurrentWindowHandle;
// Wait for 5 seconds or however long it is needed for the right window to appear
Thread.Sleep(TimeSpan.FromSeconds(5));
// Return all window handles associated with this process/application.
// At this point hopefully you have one to pick from. Otherwise you can
// simply iterate through them to identify the one you want.
var allWindowHandles = session.WindowHandles;
// Assuming you only have only one window entry in allWindowHandles and it is in fact the correct one,
// switch the session to that window as follows. You can repeat this logic with any top window with the same
// process id (any entry of allWindowHandles). Otherwise, iterate through the list and find the right one.
session.SwitchTo().Window(allWindowHandles[0]);
Microsoft's WinAppDriver is still in RC status and it seems will never be fully released. Appium's WinAppDriver implementation using AppiumOptions.AddAdditionalCapabilty is where everyone is moving to. Sure, you can use the old WinAppDriver but will it be supported moving forward? No clue. As for AppArguments in AppiumOptions - I can't find any information on how to pass these in (anywhere). Seems like it is something that was left off Appium's implementation of the WinAppDriver?