private IWebDriver ObtemDriver(TipoDriver tipoDriver) { IWebDriver driver; switch (tipoDriver) { case TipoDriver.ChromeHeadLess: ChromeOptions options = new ChromeOptions(); options.AddArgument("headless"); var chromeDriverExePath2 = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var driverService2 = ChromeDriverService.CreateDefaultService(chromeDriverExePath2); driver = new ChromeDriver(chromeDriverExePath2, options); options.AddArguments("--ignore-certificate-erros", "test-type", "incognito", "-disable-popup-blocking"); break; case TipoDriver.Chrome: var chromeDriverExePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var driverService = ChromeDriverService.CreateDefaultService(chromeDriverExePath); ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.AddArguments("--ignore-certificate-erros", "test-type", "incognito", "-disable-popup-blocking"); driver = new ChromeDriver(driverService, chromeOptions); break; default: driver = new ChromeDriver(); break; } return(driver); }
/*public void executandoThread() { * * ThreadStart ts = new ThreadStart(InicializaValores); * CrossThreadTestRunner runner = new CrossThreadTestRunner(ts); * runner.Run(); * } */ /* public TestBase_Vendas() { * driver = ObtemDriver(); * }*/ protected virtual IWebDriver ObtemDriver(TipoDriver tipoDriver) { switch (tipoDriver) { case TipoDriver.Chrome: { var chromeDriverService = ChromeDriverService.CreateDefaultService(); chromeDriverService.HideCommandPromptWindow = true; ChromeOptions chromeOptions = new ChromeOptions(); //chromeOptions.AddArguments("headless"); chromeOptions.AddArguments("--incognito"); chromeOptions.AddArgument("--window-size=1300,1000"); driver = new ChromeDriver(chromeDriverService, chromeOptions, TimeSpan.FromSeconds(60)); break; } case TipoDriver.Firefox: { driver = new FirefoxDriver(); break; } case TipoDriver.InternetExplorer: { var IEservice = InternetExplorerDriverService.CreateDefaultService(); IEservice.HideCommandPromptWindow = true; IEservice.SuppressInitialDiagnosticInformation = true; InternetExplorerOptions IEoptions = new InternetExplorerOptions(); IEoptions.EnsureCleanSession = true; IEoptions.BrowserCommandLineArguments = "-private"; driver = new InternetExplorerDriver(IEoptions); break; } } return(driver); }
public static IWebDriver GetDriver(TipoDriver tipoDriver) { IWebDriver driver = null; switch (tipoDriver) { case TipoDriver.Chrome: driver = new ChromeDriver(); break; case TipoDriver.Firefox: driver = new FirefoxDriver(); break; default: break; } driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); return(driver); }
protected virtual IWebDriver ObtemDriver(TipoDriver tipoDriver) { switch (tipoDriver) { case TipoDriver.Chrome: { var chromeDriverService = ChromeDriverService.CreateDefaultService(); chromeDriverService.HideCommandPromptWindow = true; ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.AddArgument("--incognito"); driver = new ChromeDriver(chromeDriverService, chromeOptions, TimeSpan.FromSeconds(60)); break; } case TipoDriver.Firefox: { driver = new FirefoxDriver(); break; } } return(driver); }
private static IWebDriver CriarDriver() { if (falhouPorTimeOut) { Assert.Inconclusive("O driver do selenium falhou por timeout na execução anterior."); } try { /* * Limpar o proxy do webrequest para o selenium grid conectar diretamente. */ HttpWebRequest.DefaultWebProxy = null; //--- IWebDriver drv = null; var startTime = DateTime.Now; Trace.WriteLine("Iniciando driver selenium: " + TipoDriver.ToString()); switch (TipoDriver) { case SeleniumDriver.Firefox: drv = new FirefoxDriver(); break; case SeleniumDriver.Chrome: var chrome = new ChromeOptions(); chrome.AddArgument("-incognito"); //para não usar cache, nem guardar historico chrome.AddArgument("--start-maximized"); chrome.AddArgument("--ignore-certificate-errors"); if (Convert.ToBoolean(ConfigurationManager.AppSettings["chrome:headless"])) { chrome.AddArgument("--headless"); chrome.AddArgument("--disable-gpu"); } Trace.WriteLine(chrome.ToCapabilities(), nameof(SeleniumDriver.Chrome)); drv = new ChromeDriver(CaminhoDriverLocal, chrome); break; case SeleniumDriver.Edge: var edge = new EdgeOptions(); Trace.WriteLine(edge.ToCapabilities(), nameof(SeleniumDriver.Edge)); drv = new EdgeDriver(CaminhoDriverLocal, edge); break; //case SeleniumDriver.RemoteChrome: // var remoteChrome = DesiredCapabilities.Chrome(); // remoteChrome.IsJavaScriptEnabled = true; // Trace.WriteLine(remoteChrome.ToString(), nameof(SeleniumDriver.RemoteChrome)); // drv = new RemoteWebDriver(HubUri, remoteChrome); // break; default: throw new NotImplementedException(); } Trace.WriteLine("Driver iniciado. [" + Math.Round((DateTime.Now - startTime).TotalSeconds, 2) + "s]"); return(drv); } catch (WebDriverException ex) { if (ex.Message.Contains("timed out after")) { falhouPorTimeOut = true; Assert.Inconclusive("Driver de selenium falhou por timeout. Verifique a disponibilidade do hub.\r\n{0}\r\n----\r\n{1}", ex.Message, ex.InnerException); } throw; } }