private static void VerifyAppDriver(RemoteWebDriver app, AppManagerOptions opts) { if (app?.SessionId == null) { throw new DriverLoadFailedException(opts); } // Set implicit timeout to 2 seconds to make element search to retry every 500 ms for at most three times. app.Manage().Timeouts().ImplicitWait = opts.ImplicitWait; }
/// <summary> /// Starts the application ready for testing. /// </summary> /// <param name="opts"> /// The options to configure the driver with. /// </param> /// <exception cref="DriverLoadFailedException"> /// Thrown if the application is null or the session ID is null once initialized. /// </exception> public static void StartApp(AppManagerOptions opts) { StopApp(); switch (opts) { case WebAppManagerOptions webOpts: { switch (webOpts.DriverType) { case WebAppDriverType.Chrome: WebApp = new ChromeDriver(webOpts.DriverUri); break; case WebAppDriverType.Firefox: WebApp = new FirefoxDriver(webOpts.DriverUri); break; case WebAppDriverType.Opera: WebApp = new OperaDriver(webOpts.DriverUri); break; case WebAppDriverType.Safari: WebApp = new SafariDriver(webOpts.DriverUri); break; case WebAppDriverType.Edge: WebApp = new EdgeDriver(webOpts.DriverUri); break; case WebAppDriverType.InternetExplorer: WebApp = new InternetExplorerDriver(webOpts.DriverUri); break; } VerifyAppDriver(WebApp, webOpts); if (webOpts.Maximize) { WebApp.Manage().Window.Maximize(); } else { WebApp.Manage().Window.Size = webOpts.DesiredSize; } WebApp.Url = webOpts.Url; break; } case WindowsAppManagerOptions winOpts: { WebApp = new WindowsDriver <WindowsElement>( new Uri(winOpts.DriverUri), winOpts.AppiumOptions); VerifyAppDriver(WindowsApp, winOpts); break; } case AndroidAppManagerOptions androidOpts: { WebApp = new AndroidDriver <AndroidElement>( new Uri(androidOpts.DriverUri), androidOpts.AppiumOptions); VerifyAppDriver(AndroidApp, androidOpts); break; } case IOSAppManagerOptions iosOpts: { WebApp = new IOSDriver <IOSElement>(new Uri(iosOpts.DriverUri), iosOpts.AppiumOptions); VerifyAppDriver(IOSApp, iosOpts); break; } } }