private void SelectBrowser(BrowserType browserType) { var downloadFilepath = Path.GetFullPath(Path.Combine(_appSettings.FileLocations.OutputPath, _appSettings.FileLocations.DownloadPdfLocation)); string filePath = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath); switch (browserType) { case BrowserType.Chrome: ChromeOptions chromeProfile = new ChromeOptions(); //ChromeOption.AddArguments("--headless"); chromeProfile.AddArgument("no-sandbox"); chromeProfile.AddUserProfilePreference("download.default_directory", downloadFilepath); Driver = new ChromeDriver(filePath, chromeProfile, new TimeSpan(0, 0, 60)); objectContainer.RegisterInstanceAs(Driver); break; case BrowserType.Firefox: FirefoxOptions firefoxProfile = new FirefoxOptions(); firefoxProfile.SetPreference("browser.download.folderList", 2); firefoxProfile.SetPreference("browser.download.dir", downloadFilepath); Driver = new FirefoxDriver(filePath, firefoxProfile, new TimeSpan(0, 0, 60)); objectContainer.RegisterInstanceAs(Driver); break; case BrowserType.InternetExplorer: InternetExplorerOptions IEProfile = new InternetExplorerOptions(); IEProfile.AddAdditionalCapability("browser.download.folderList", 2); IEProfile.AddAdditionalCapability("browser.download.dir", downloadFilepath); Driver = new InternetExplorerDriver(filePath, IEProfile, new TimeSpan(0, 0, 60)); objectContainer.RegisterInstanceAs(Driver); break; case BrowserType.Edge: EdgeOptions edgeProfile = new EdgeOptions(); edgeProfile.AddAdditionalCapability("browser.download.dir", downloadFilepath); edgeProfile.AddAdditionalCapability("browser.download.folderList", 2); Driver = new EdgeDriver(filePath, edgeProfile, new TimeSpan(0, 0, 60)); objectContainer.RegisterInstanceAs(Driver); break; default: break; } }
private FirefoxDriver StartDriver() { FirefoxOptions ffo = new FirefoxOptions(); ffo.AddArguments(new[] { "--private" }); ffo.SetPreference("pageLoadStrategy", "eager"); while (driver == null) { try { driver = new FirefoxDriver(ffo); } catch (Exception e) { Console.WriteLine(e.Message); } } driver.Url = "https://login.yahoo.com"; WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); var elem = wait.Until(ExpectedConditions.ElementToBeClickable((By.CssSelector("input.phone-no#login-username"))));; elem.SendKeys("*****@*****.**"); //driver.FindElementById("login-signin").Click(); return(driver); }
public static IWebDriver getDriver(DriverType type) { switch (type) { case DriverType.CHROME: { ChromeOptions options = new ChromeOptions(); options.AddArguments("--disable-notifications"); Environment.SetEnvironmentVariable("webdriver.chrome.driver", ""); BaseTest.driver = new ChromeDriver(options); break; } case DriverType.FIREFOX: { FirefoxOptions options = new FirefoxOptions(); options.SetPreference("dom.webnotifications.enabled", false); BaseTest.driver = new FirefoxDriver(options); break; } default: { InternetExplorerOptions options = new InternetExplorerOptions { EnsureCleanSession = true }; BaseTest.driver = new InternetExplorerDriver(options); break; } } BaseTest.driver.Manage().Cookies.DeleteAllCookies(); BaseTest.driver.Manage().Window.Maximize(); return(BaseTest.driver); }
public override IWebDriver createWebDriver() { FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.SetPreference("dom.webnotifications.enabled", false); return(new FirefoxDriver(firefoxOptions)); }
public FirefoxDriverWebClient(string geckoDriverDirectory) { // Workaround for error in FirefoxDriver when running on .net core: // Unhandled Exception: System.TypeInitializationException: The type initializer for 'System.IO.Compression.ZipStorer' threw an exception. --->System.NotSupportedException: No data is available for encoding 437.For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. // at System.Text.Encoding.GetEncoding(Int32 codepage) // at System.IO.Compression.ZipStorer..cctor() // -- - End of inner exception stack trace-- - // at System.IO.Compression.ZipStorer.WriteLocalHeader(ZipFileEntry & zipFileEntry) // at System.IO.Compression.ZipStorer.AddStream(CompressionMethod compressionMethod, Stream sourceStream, String fileNameInZip, DateTime modificationTimeStamp, String fileEntryComment) // at System.IO.Compression.ZipStorer.AddFile(CompressionMethod compressionMethod, String sourceFile, String fileNameInZip, String fileEntryComment) // at OpenQA.Selenium.Firefox.FirefoxProfile.ToBase64String() // at OpenQA.Selenium.Firefox.FirefoxOptions.GenerateFirefoxOptionsDictionary() // at OpenQA.Selenium.Firefox.FirefoxOptions.ToCapabilities() // at OpenQA.Selenium.Firefox.FirefoxDriver.ConvertOptionsToCapabilities(FirefoxOptions options) // at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(String geckoDriverDirectory, FirefoxOptions options) // See https://github.com/SeleniumHQ/selenium/issues/4816 Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); Environment.SetEnvironmentVariable("MOZ_HEADLESS", "1"); FirefoxOptions firefoxOptions = new FirefoxOptions() { Profile = new FirefoxProfile() { DeleteAfterUse = true, }, }; firefoxOptions.AddArgument("--headless"); firefoxOptions.SetPreference("javascript.enabled", false); _driver = new FirefoxDriver(geckoDriverDirectory, firefoxOptions); _driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(30); }
protected override IWebDriver GetInstance() { IWebDriver _instance; BaseClass.Logger.Information("Initialize Firefox, mobile=" + IsMobile); var profile = new FirefoxOptions { Profile = new FirefoxProfile { AcceptUntrustedCertificates = true } }; if (IsMobile) { profile.SetPreference("general.useragent.override", Configuration.MobileUserAgent); } _instance = new FirefoxDriver(profile); if (IsMobile) { _instance.Manage().Window.Size = new Size(412, 732); } else { _instance.Manage().Window.Maximize(); } _instance.Manage().Timeouts().PageLoad = TimeSpan.FromMinutes(5); return(_instance); }
static FirefoxOptions GetFirefoxOptions() { FirefoxOptions options = new FirefoxOptions(); options.SetPreference("browser.download.dir", GetDownloadsFolderPath()); return(options); }
private static DriverOptions GetOptions(BrowserType type) { DriverOptions ans; switch (type) { case BrowserType.Chrome: { ChromeOptions options = new ChromeOptions(); options.AddUserProfilePreference("safebrowsing.enabled", "false"); ans = options; } break; case BrowserType.FireFox: { FirefoxOptions option = new FirefoxOptions(); option.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream"); ans = option; } break; default: ans = null; break; } return(ans); }
public IWebDriver InitBrowser(string browser) { try { if (browser == null) { throw new BrowserFactoryException("Browser not be null", BrowserFactoryException.ExceptionType.NULL_EXCEPTION); } if (browser.Length == 0) { throw new BrowserFactoryException("Browser not be empty", BrowserFactoryException.ExceptionType.EMPTY_EXCEPTION); } switch (browser) { case "chrome": ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.AddArgument("--disable-notifications"); driver = new ChromeDriver(chromeOptions); break; case "firefox": FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.SetPreference("dom.webnotifications.enabled", false); driver = new FirefoxDriver(firefoxOptions); break; } return(driver); } catch (BrowserFactoryException exception) { throw new BrowserFactoryException(exception.Message, BrowserFactoryException.ExceptionType.NULL_EXCEPTION); } }
private IWebDriver CreateFirefoxDriver() { string firefoxDriverConfig = Config.Settings.RuntimeSettings.FirefoxDriverPath; string firefoxDriverPath = AppDomain.CurrentDomain.BaseDirectory + firefoxDriverConfig; FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.SetPreference("intl.accept_languages", Config.Settings.RuntimeSettings.BrowserLanguage); Proxy proxy = GetProxy(); if (proxy != null) { firefoxOptions.Proxy = proxy; } //var ffp = new FirefoxProfile(); //InitProfile(ffp); InitProfile(firefoxOptions); Driver = new FirefoxDriver(firefoxDriverPath, firefoxOptions); SetBrowserSize(Driver); Driver.VaftExt().TurnOnImplicitlyWait(); Driver.VaftExt().SetPageLoadTimeout(); return(Driver); }
public virtual FirefoxOptions ToFireFox() { var options = new FirefoxOptions() { UseLegacyImplementation = false }; if (!string.IsNullOrEmpty(DownloadsPath)) { options.SetPreference("browser.download.folderList", 2); options.SetPreference("browser.download.dir", DownloadsPath); options.SetPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/java-archive, application/x-msexcel,application/excel,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml,application/vnd.microsoft.portable-executable"); } return(options); }
public override IWebDriver CreateLocalDriver() { FirefoxDriverService service; string path = Environment.GetEnvironmentVariable("webdriver.gecko.driver", EnvironmentVariableTarget.Machine); if (path != null) { service = FirefoxDriverService.CreateDefaultService(path); } else { service = FirefoxDriverService.CreateDefaultService(); } service.HideCommandPromptWindow = true; var ops = new FirefoxOptions { Profile = CreateProfile() }; ops.SetPreference("security.enterprise_roots.enabled", true); var driver = new FirefoxDriver(service, ops, TimeSpan.FromSeconds(Timeouts.HttpCommandTimeout)); ProcessID = service.ProcessId; return(driver); }
public static RemoteWebDriver OpenBrowser(BrowserType browserType) { { switch (browserType) { case BrowserType.Chrome: ChromeOptions options = new ChromeOptions(); options.AddArgument("--start-maximized"); return(new ChromeDriver(ChromeDriverService.CreateDefaultService(), options, TimeSpan.FromMinutes(2))); case BrowserType.FireFox: FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.SetPreference("capability.policy.default.Window.frameElement.get", "allAccess"); return(new FirefoxDriver(firefoxOptions)); case BrowserType.Edge: EdgeOptions edgeOptions = new EdgeOptions(); string edgeWebDriverPath = Path.Combine(Directory.GetCurrentDirectory(), "MicrosoftWebDriver.exe"); return(new EdgeDriver(Directory.GetCurrentDirectory())); default: return(null); } } }
public Magazine AnalyzeData(Magazine derStandard) { try { FirefoxOptions options = new FirefoxOptions(); options.SetPreference("dom.push.enabled", false); foreach (Resort item in derStandard) { try { using (IWebDriver driver = new FirefoxDriver("../", options)) { AnalyzeResort(item, driver); driver.Close(); driver.Dispose(); } } catch (Exception e) { e.LogErrorToTSV("while analyzing resort " + item.name); } } } catch (Exception e) { e.LogErrorToTSV("generally unknown Error"); } return(derStandard); }
private static RemoteWebDriver StartFirefoxDriver(DriverSettings settings) { var profile = new FirefoxProfile(null, true); if (!string.IsNullOrEmpty(settings.Proxy)) { profile.SetProxyPreferences(new Proxy { HttpProxy = settings.Proxy }); } settings.Extensions?.ForEach(ext => profile.AddExtension(ext.RelativeToBaseDirectory())); var options = new FirefoxOptions { Profile = profile, UseLegacyImplementation = false }; settings.Capabilities?.ForEach(cap => options.AddAdditionalCapability(cap.Key, cap.Value)); if (!string.IsNullOrEmpty(settings.BrowserBinaryPath)) { options.BrowserExecutableLocation = settings.BrowserBinaryPath; } if (settings.CmdArgs != null) { options.AddArguments(settings.CmdArgs); } settings.ProfilePrefs?.ForEach(pref => options.SetPreference(pref.Key, (dynamic)pref.Value)); return(new FirefoxDriver(options)); }
public void Firefox() { _firefoxService = FirefoxDriverService.CreateDefaultService(_buildPath); _firefoxService.Host = "::1"; var options = new FirefoxOptions() { AcceptInsecureCertificates = true }; options.SetPreference("media.navigator.streams.fake", true); options.SetPreference("media.navigator.permission.disabled", true); _driver = new FirefoxDriver(_firefoxService, options); RunTest(); }
private static IWebDriver GetFirefoxDriver(string driverPath, string profilePath, string proxyString) { Environment.SetEnvironmentVariable("MOZ_CRASHREPORTER", "0"); Environment.SetEnvironmentVariable("MOZ_CRASHREPORTER_DISABLE", "1"); Environment.SetEnvironmentVariable("MOZ_CRASHREPORTER_NO_REPORT", "1"); Environment.SetEnvironmentVariable("XRE_NO_WINDOWS_CRASH_DIALOG", "1"); Environment.SetEnvironmentVariable("GNOME_DISABLE_CRASH_DIALOG", "1"); FirefoxOptions fOptions = new FirefoxOptions(); fOptions.SetPreference("browser.startup.page", 0); fOptions.SetPreference("browser.startup.homepage", "about:blank"); fOptions.SetPreference("browser.startup.homepage_override.mstone", "ignore"); fOptions.SetPreference(CapabilityType.UnexpectedAlertBehavior, "ignore"); fOptions.BrowserExecutableLocation = Config.FirefoxBrowserPath; if (!string.IsNullOrWhiteSpace(profilePath)) { FirefoxProfile profile = new FirefoxProfile(profilePath) { AcceptUntrustedCertificates = true, AssumeUntrustedCertificateIssuer = false, DeleteAfterUse = true }; fOptions.Profile = profile; } if (!string.IsNullOrWhiteSpace(proxyString)) { Proxy proxy = new Proxy { HttpProxy = proxyString, SslProxy = proxyString, FtpProxy = proxyString }; fOptions.Proxy = proxy; } if (string.IsNullOrWhiteSpace(driverPath)) { driverPath = Config.FirefoxDriverPath; } return(new FirefoxDriver(driverPath, fOptions)); }
private static FirefoxDriver StartDriver(string url, string linkText, bool click) { FirefoxDriver driver = null; if (!click && replayDriver != null) { driver = replayDriver; } else { FirefoxOptions ffo = new FirefoxOptions(); ffo.AddArguments(new[] { "--headless", "--private" }); ffo.SetPreference("pageLoadStrategy", "eager"); while (driver == null) { try { driver = new FirefoxDriver(ffo); } catch (Exception) { } } } driver.Url = url; WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); IWebElement success = null; int i = 0; do { try { if (i > 0) { driver.Navigate().GoToUrl(url); } i++; success = wait.Until(ExpectedConditions.ElementExists(By.LinkText(linkText))); } catch (Exception) { } } while (success == null && i < 3); if (success == null) { driver.Quit(); return(null); } if (click) { success.Click(); } return(driver); }
public static DriverOptions GetDriverOptions(Driver driver) { switch (driver) { case Driver.Chrome: var chromeOptions = new ChromeOptions { AcceptInsecureCertificates = true }; chromeOptions.AddArguments("--incognito", "--disable-infobars", "--disable-notifications", "disable-extensions"); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { chromeOptions.AddArgument("--disable-dev-shm-usage"); chromeOptions.AddArgument("--no-sandbox"); chromeOptions.AddArgument("--headless"); } return(chromeOptions); case Driver.Firefox: var firefoxOptions = new FirefoxOptions { AcceptInsecureCertificates = true }; firefoxOptions.AddArgument("-private"); firefoxOptions.SetPreference("dom.webnotifications.enabled", false); firefoxOptions.SetPreference("dom.webnotifications.enabled", false); return(firefoxOptions); case Driver.InternetExplorer: return(new InternetExplorerOptions { AcceptInsecureCertificates = true, BrowserCommandLineArguments = "", EnsureCleanSession = true, RequireWindowFocus = false }); default: throw new NotFoundException("This driver is not in the list of handled web drivers"); } }
/// <summary> /// Inizializza il browser /// </summary> /// <returns></returns> private static IWebDriver InitBrowser() { string userAgent = RandomUa.RandomUserAgent; FirefoxOptions options = new FirefoxOptions(); options.AddArgument("--headless"); options.AddArgument($"--user-agent={userAgent}"); options.AddArgument("--width=1366"); options.AddArgument("--height=768"); options.SetPreference("dom.webdriver.enabled", false); options.SetPreference("useAutomationExtension", false); IWebDriver driver = new FirefoxDriver(options); return(driver); }
private IWebDriver InitLocalDriver() { var options = new FirefoxOptions { AcceptInsecureCertificates = true }; if (BlockCameraAndMic) { options.SetPreference("permissions.default.microphone", 2); } else { options.SetPreference("media.navigator.streams.fake", true); } return(new FirefoxDriver(FireFoxDriverPath, options)); }
private static IWebDriver CustomProfile() { FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.SetPreference("app.update.enabled", false); return(new FirefoxDriver(firefoxOptions)); }
public static IWebDriver GetRemoteFirefox() { FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.SetPreference("intl.accept_languages", "pt-BR"); return(new RemoteWebDriver(new Uri(seleniumHub), firefoxOptions.ToCapabilities())); }
/// <summary> /// Creates the web driver from the specified browser factory configuration. /// </summary> /// <returns>The configured web driver.</returns> protected override IWebDriver CreateLocalDriver() { IWebDriver driver; if (this.Settings != null && this.Settings.Count > 0) { var options = new FirefoxOptions(); foreach (KeyValuePair <string, string> configurationElement in this.Settings) { // Removed debug lines but left in comments for future logger support // Debug.WriteLine("SpecBind.Selenium.SeleniumBrowserFactory.GetFireFoxDriver: Setting firefox profile setting:{0} with value: {1}", configurationElement.Name, configurationElement.Value); int intValue; bool boolValue; if (int.TryParse(configurationElement.Value, out intValue)) { // Debug.WriteLine("SpecBind.Selenium.SeleniumBrowserFactory.GetFireFoxDriver: Setting firefox profile setting with int value: '{0}'", configurationElement.Name); options.SetPreference(configurationElement.Key, intValue); } else if (bool.TryParse(configurationElement.Value, out boolValue)) { // Debug.WriteLine("SpecBind.Selenium.SeleniumBrowserFactory.GetFireFoxDriver: Setting firefox profile setting with bool value: '{0}'", configurationElement.Name); options.SetPreference(configurationElement.Key, boolValue); } else { // Debug.WriteLine("SpecBind.Selenium.SeleniumBrowserFactory.GetFireFoxDriver: Setting firefox profile setting with string value: '{0}'", configurationElement.Name); options.SetPreference(configurationElement.Key, configurationElement.Value); } } driver = new FirefoxDriver(options); } else { driver = new FirefoxDriver(); } if (this.EnsureCleanSession) { driver.Manage().Cookies.DeleteAllCookies(); } return(driver); }
public void BeforeTest() { FirefoxOptions options = new FirefoxOptions(); options.SetPreference("webdriver.gecko.driver", "geckodriver.exe"); this.webDriver = new FirefoxDriver(options); this.webDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(20); this.webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20); }
public override IWebDriver InitialiseForLocal() { var geckoService = FirefoxDriverService.CreateDefaultService(BuildPath); geckoService.Host = "::1"; var browserOptions = new FirefoxOptions(); browserOptions.SetPreference("media.navigator.streams.fake", true); browserOptions.SetPreference("media.navigator.permission.disabled", true); if (Proxy?.HttpProxy != null) { browserOptions.Proxy = Proxy; browserOptions.AddArgument(ProxyByPassList); } return(new FirefoxDriver(geckoService, browserOptions, LocalDesktopTimeout)); }
public IWebDriver Create() { var driverService = FirefoxDriverService.CreateDefaultService(); driverService.FirefoxBinaryPath = FirefoxBinaryPath; driverService.HideCommandPromptWindow = true; driverService.SuppressInitialDiagnosticInformation = true; var options = new FirefoxOptions(); options.SetPreference("javascript.enabled", true); options.SetLoggingPreference(LogType.Browser, LogLevel.Warning); options.SetPreference( "general.useragent.override", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0 Selenium/3.4"); return(new FirefoxDriver(driverService, options, CommandTimeout)); }
public void startBrowser(string url, string name) { this.name = name; var options = new FirefoxOptions(); options.SetPreference("permissions.default.microphone", 1); options.SetPreference("permissions.default.camera", 2); driver = new FirefoxDriver(options); driver.Navigate().GoToUrl(url); var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60)) { PollingInterval = TimeSpan.FromSeconds(5) }; wait.IgnoreExceptionTypes(typeof(NoSuchElementException)); new Thread(() => { handle(wait); }).Start(); }
public static IWebDriver CreateBrowser(BrowserType browserType) { switch (browserType) { case BrowserType.Chrome: return(new ChromeDriver()); case BrowserType.Firefox: FirefoxOptions firefoxProfile = new FirefoxOptions(); firefoxProfile.SetPreference("browser.download.manager.showWhenStarting", false); firefoxProfile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip"); firefoxProfile.SetPreference("browser.helperApps.neverAsk.openFile", "application/zip"); return(new FirefoxDriver(firefoxProfile)); default: throw new ArgumentOutOfRangeException(nameof(browserType), browserType, null); } }
//proxyの値をセット public virtual FirefoxOptions SetProxy(FirefoxOptions option, string noProxy) { string proxy = ConfigurationManager.AppSettings["Proxy"]; int port = Convert.ToInt32(ConfigurationManager.AppSettings["ProxyPort"]); option.SetPreference("network.proxy.type", 1); option.SetPreference("network.proxy.http", proxy); option.SetPreference("network.proxy.http_port", port); option.SetPreference("network.proxy.ftp", proxy); option.SetPreference("network.proxy.ftp_port", port); option.SetPreference("network.proxy.ssl", proxy); option.SetPreference("network.proxy.ssl_port", port); option.SetPreference("network.proxy.socks", proxy); option.SetPreference("network.proxy.socks_port", port); option.SetPreference("network.proxy.no_proxies_on", $"localhost, 127.0.0.1{ noProxy }"); return(option); }