[Bug]: Driver is showing 0 window handles when attaching to the existing desktop application which was started via CMD as Admin
zewer opened this issue · 3 comments
Description
Working with Windows 10 desktop application, writing C# UI tests.
Usually working with attaching to the exiting window which was started by external process (Browser Protocol Handler) or like default start via AppiumDriver + options
Everyting was fine untill I started automation when application is starting immediately after installation via CMD. The point that it must be executed via Admin access rights so I can't verify scenario without admin rights.
Im doing simple attaching to the existing process with windowsHandler and appTopLevelWindow option
var handle = SessionHelper.GetExistingProcessHandle();
appiumOptions.AddAdditionalCapability("appTopLevelWindow", handle);
appiumOptions.AddAdditionalCapability("deviceName", "WindowsPC");
appiumOptions.AddAdditionalCapability("platformName", "Windows");
appiumOptions.AddAdditionalCapability("newCommandTimeout", 1200);
DriverUri = new Uri("http://127.0.0.1:4723/wd/hub");
Driver = new WindowsDriver<IWebElement>(DriverUri, appiumOptions);
And it is working. Driver can attach fine.
But, when I'm trying to manage windows with:
var debug = Driver.WindowHandles;
It will return empty List with 0 windows inside.
100% application in this period of time is opened and working fine.
In case of simple reopening application problem is gone.
I can't provide you full example with ready code to launch because this is high security project but guys from my dev team saying that there are no difference for application when I'm running application though cmd or manually. Must be system or driver issue.
How I'm starting cmd:
public static void ExecuteCMDWithWait(string strCmdText)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.UseShellExecute = true;
startInfo.Arguments = "/C " + strCmdText;
startInfo.Verb = "runas";
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
}
Versions
WinAppDriver v1.2.1
Appium v1.19.1
UAC disabled
Appium.WebDriver Version="4.2.1" or Appium.WebDriver Version="4.4.5" (no changes)
Details
I can produce it even manually when starting appium (appium -a localhost
) as non admin powershell process and running my app with cmd as admin. Driver is attaching but showing as 0 windows exist. Occurance always 100%. Restart app not via cmd - problem is gone. Always
Code To Reproduce Issue [ Good To Have ]
Currently can't provide. Just want to hear any information from you. If needed - will try to investigate much deeper and create some ready to run example with some other applications, not my enterprise application.
Exception stack traces
No Exceptions, driver just saying my app has 0 windows opened when it is running and working fine
Link to Appium logs
@zewer, Since you are using old versions of the dotnet client and appium server, that are no longer maintained.
I suggest you first update both and try again.
better you check out this section as well after you update to appium 2.x
https://github.com/appium/dotnet-client#winappdriver-notice
Make sense
Added PBI, will do asap (2-3 sprints probably).
For now using the following trick, forse closing app (taskkill /F /PID P_ID) after installation and starting it again via cmd but without admin access rights, everything is working fine
Sorry for delay, don't have time to test this deeper. Approach with reopening works good so currently using this one.
Will create new issue if find time to test everything! Thanks!