public void SupplyingAcceptableCapabilitiesForDriverServiceLaunchesChromeBrowser() { TestEnvironmentParameters @params = new TestEnvironmentParameters() { RS_LocalExecution = true, RS_LocalExecutionAsService = true, RS_DriverServerExePath = TestContext.CurrentContext.TestDirectory, RS_BrowserName = "chrome", RS_ServerHost = "localhost", RS_ServerPort = "4278", RS_ImplicitWaitTime = "0" //Write unit test for testing empty properties }; DriverService.Start(@params); DriverCapabilities caps = new DriverCapabilities(@params); caps.GetDriverOptions <ChromeOptions>().AddArgument("--headless"); //Test this in unit test WebDriver.Initialize(caps); Assert.That(WebDriver.Instance != null, "Driver should have been instantiated successfully"); Assert.AreEqual("data:,", WebDriver.Instance.Url, "Empty url should have been opened"); WebDriver.Instance.Navigate().GoToUrl("https://google.com"); Assert.AreEqual("https://www.google.com/", WebDriver.Instance.Url, "Should have navigated to google.com"); WebDriver.Dispose(); DriverService.Dispose(); }
public void StopTestRun() { DriverService.Dispose(); // Delete the log created by the DriverService in the binaries directory, it has been copied to the logs directory. //var logs = Directory.GetFiles(".", "*.log"); // VsTest //var logs = Directory.GetFiles(TestContext.CurrentContext.TestDirectory, "*.log"); // NUnit var logs = Directory.GetFiles(TestContext.CurrentContext.TestDirectory, "*.log"); if (logs.Length.Equals(0)) { return; } foreach (var log in logs) { try { File.Delete(log); } catch (IOException ioEx) { Console.WriteLine(ioEx); } } }
public static void Stop() { if (WebDriver != null) { WebDriver.Quit(); WebDriver = _primaryWebDriver; if (_driverService != null) { _driverService.Dispose(); _driverService = null; } } }
public void Dispose() { if (WebDriver != null) { WebDriver.Dispose(); WebDriver = null; } if (DriverService != null) { DriverService.Dispose(); DriverService = null; } }
/// <summary> /// Close the Browser and WebDriver. /// </summary> // ReSharper disable once InheritdocConsiderUsage public void Dispose() { try { SessionId sessionId = null; switch (Options.Browser) { case BrowserType.Chrome: { sessionId = (WebDriver as ChromeDriver)?.SessionId; break; } case BrowserType.Edge: { sessionId = (WebDriver as EdgeDriver)?.SessionId; break; } case BrowserType.Firefox: { sessionId = (WebDriver as FirefoxDriver)?.SessionId; break; } case BrowserType.InternetExplorer: { sessionId = (WebDriver as InternetExplorerDriver)?.SessionId; break; } } if (sessionId != null) { WebDriver.Close(); } } catch (Exception e) { LogManager.Error(e.Message); } finally { WebDriver?.Quit(); DriverService?.Dispose(); LogManager?.Dispose(); } }
/// <summary> /// Quit browser. /// </summary> public void Quit() { if (webDriver == null) { return; } webDriver.Quit(); webDriver = null; if (driverService != null) { driverService.Dispose(); } }
protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { Driver.Close(); Driver.Quit(); Driver.Dispose(); DriverService.Dispose(); } disposed = true; }
public void TearDown() { if (WebDriver == null) { return; } try { if (_service.IsRunning.Equals(true)) { _service.Dispose(); } WebDriver.Quit(); WebDriver.Dispose(); } catch (WebDriverException err) { Debug.WriteLine(err, "Web driver stop error..."); } WebDriver = null; Trace("Web driver stopped..."); }
public static DriverService Stop() { _driverService.Dispose(); return(_driverService); }
public void Dispose() { _driverService?.Dispose(); }
public virtual void Cleanup() { Driver.Quit(); DriverService.Dispose(); }
public static IWebDriver Create(IConfiguration testConfig, out DriverService driverService) { var usingDriver = testConfig["usingDriver"]; var driverHostName = default(string); // https://github.com/SeleniumHQ/selenium/issues/4988 var driverOptions = default(DriverOptions); var baseDir = Environment.CurrentDirectory; switch (usingDriver) { case "Chrome": driverHostName = "127.0.0.1"; driverService = ChromeDriverService.CreateDefaultService(baseDir); driverOptions = new ChromeOptions(); break; case "Edge": driverHostName = "localhost"; driverService = EdgeDriverService.CreateDefaultService(baseDir); driverOptions = new EdgeOptions(); break; case "Firefox": driverHostName = "127.0.0.1"; driverService = FirefoxDriverService.CreateDefaultService(baseDir); driverOptions = new FirefoxOptions(); break; case "IE": driverHostName = "127.0.0.1"; driverService = InternetExplorerDriverService.CreateDefaultService(baseDir); driverOptions = new InternetExplorerOptions(); break; default: throw new Exception($"Unknown driver \"{usingDriver}\" was specified in configuration."); } try { driverService.HideCommandPromptWindow = true; driverService.Start(); var webDriver = new RemoteWebDriver(new Uri($"http://{driverHostName}:{driverService.Port}"), driverOptions); try { //webDriver.Manage().Window.Maximize(); //webDriver.Manage().Window.Position = new Point(x: 426, y: 0); //webDriver.Manage().Window.Size = new Size(width: 854, height: 720); webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); webDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5); return(webDriver); } catch { webDriver.Dispose(); throw; } } catch { driverService.Dispose(); driverService = null; throw; } }