Open MrMikheev opened 2 years ago
Try this:
Get the application name first if the application is already opened:
string mainWindowTitle = "";
var allProcesses1 = Process.GetProcesses();
foreach (Process process in allProcesses1)
{
if (process.ProcessName.Contains("Your Application"))
{
mainWindowTitle = process.MainWindowTitle;
}
}
use the below code to create a driver session with opened application:
desktopCapabilities.AddAdditionalCapability("app", "Root");
desktopSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), desktopCapabilities);
Assert.IsNotNull(desktopSession);
var RSWindow = desktopSession.FindElementByName(mainWindowTitle);
var RSTopLevelWindowHandle = RSWindow.GetAttribute("NativeWindowHandle");
RSTopLevelWindowHandle = (int.Parse(RSTopLevelWindowHandle)).ToString("x");
var appcapabilities = new AppiumOptions();
appcapabilities.AddAdditionalCapability("appTopLevelWindow", RSTopLevelWindowHandle);
appcapabilities.AddAdditionalCapability("newCommandTimeout", 300);
driver = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appcapabilities,TimeSpan.FromSeconds(50));
@MrMikheev Did it work?
I solved the "Unable to convert from "System.Uri to OpenQA.Selenium.AppiumOptions" error by modifying the code: FROM:
DesiredCapabilities appCapabilities1 = new DesiredCapabilities();
appCapabilities1.SetCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
var calculatorSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl);, appCapabilities);
TO:
var appCapabilities = new AppiumOptions();
appCapabilities.AddAdditionalCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
appCapabilities.AddAdditionalCapability("deviceName", "WindowsPC");
appCapabilities.AddAdditionalCapability("platformName", "Windows");
var calculatorSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities, TimeSpan.FromSeconds(180));
My application starts, but it has a splash screen. wiki doesn’t help me because swears at (new Uri("http://127.0.0.1:4723"), appCapabilities);
the application has a splash screen, it is impossible to create a root session, as it is written in the wiki