public void TakingHTML2CanvasFullPageScreenshot() { var options = new ChromeOptions(); options.AddArguments($"load-extension={GetAssemblyDirectory()}\\FullPageScreenshotsExtension-Chrome\\"); var capabilities = new DesiredCapabilities(); capabilities.SetCapability(ChromeOptions.Capability, options); var dc = DesiredCapabilities.Chrome(); dc.SetCapability(ChromeOptions.Capability, options); using (var driver = new ChromeDriver(options)) { driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5); driver.Navigate().GoToUrl(@"https://automatetheplanet.com"); var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); var fullPageImg = wait.Until(ExpectedConditions.ElementExists(By.Id("fullPageScreenshotId"))); var pngContent = fullPageImg.GetAttribute("src"); pngContent = pngContent.Replace("data:image/png;base64,", string.Empty); byte[] data = Convert.FromBase64String(pngContent); var tempFilePath = Path.GetTempFileName().Replace(".tmp", ".png"); Image image; using (var ms = new MemoryStream(data)) { image = Image.FromStream(ms); } image.Save(tempFilePath, ImageFormat.Png); } }
private static DesiredCapabilities CreateDesiredCapabilities() { DesiredCapabilities capabilities; switch (SeleniumConfig.Current.Browser) { case "FF": capabilities = DesiredCapabilities.Firefox(); capabilities.SetCapability(CapabilityType.BrowserName, "firefox"); break; case "IE": capabilities = DesiredCapabilities.InternetExplorer(); capabilities.SetCapability("enablePersistentHover", false); capabilities.SetCapability("ie.ensureCleanSession", true); capabilities.SetCapability(CapabilityType.BrowserName, "internet explorer"); break; default: capabilities = DesiredCapabilities.Chrome(); capabilities.SetCapability(CapabilityType.BrowserName, "chrome"); break; } return(capabilities); }
private static IWebDriver CreateChromDriver(string chromeDriverPath) { IWebDriver driver; var arrayList = new ArrayList { "--disable-glsl-translator --start-maximized --automation-reinitialize-on-channel-error --bwsi --assert-test --test-type --disable-logging --disable-plugins --disable-translate --disable-web-security" }; var desiredCapabilities = DesiredCapabilities.Chrome(); var chromeOptions = new ChromeOptions(); chromeOptions.AddArguments("test-type"); chromeOptions.AddArgument("--start-maximized"); chromeOptions.AddArguments("disable-infobars"); var perfLogPrefs = new ChromePerformanceLoggingPreferences(); perfLogPrefs.AddTracingCategories(new string[] { "devtools.network" }); chromeOptions.AddAdditionalCapability(CapabilityType.EnableProfiling, true, true); //chromeOptions.PerformanceLoggingPreferences = perfLogPrefs; chromeOptions.SetLoggingPreference("performance", LogLevel.All); chromeOptions.AddUserProfilePreference("intl.accept_languages", "en-AU"); desiredCapabilities.SetCapability("download.prompt_for_download", false); //desiredCapabilities.SetCapability("download.default_directory", browserDownloadDir); desiredCapabilities.SetCapability("disable-extensions", true); desiredCapabilities.SetCapability("chrome.switches", arrayList); var baseExecutingAssemblyDir = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath); var commandTimeout = new TimeSpan(0, 0, 60); driver = new ChromeDriver(Path.Combine(baseExecutingAssemblyDir ?? string.Empty, chromeDriverPath), chromeOptions, commandTimeout); return(driver); }
/// <summary> /// Returns DesiredCapabilities for Chrome with these options included as /// capabilities. This does not copy the options. Further changes will be /// reflected in the returned capabilities. /// </summary> /// <returns>The DesiredCapabilities for Chrome with these options.</returns> public ICapabilities ToCapabilities() { DesiredCapabilities capabilities = DesiredCapabilities.Chrome(); capabilities.SetCapability(ChromeOptions.Capability, this); // chromeOptions is only recognized by chromedriver 17.0.963.0 or newer. // Provide backwards compatibility for capabilities supported by older // versions of chromedriver. // TODO: remove this once the deprecated capabilities are no longer supported. capabilities.SetCapability("chrome.switches", this.arguments); if (!string.IsNullOrEmpty(this.binaryLocation)) { capabilities.SetCapability("chrome.binary", this.binaryLocation); } if (this.proxy != null) { capabilities.SetCapability(CapabilityType.Proxy, this.proxy); } foreach (KeyValuePair <string, object> pair in this.additionalCapabilities) { capabilities.SetCapability(pair.Key, pair.Value); } return(capabilities); }
public void TestMethod() { //var uri = "http://*****:*****@ssword1"); driver.FindElement(By.CssSelector("input.j-btn.j-primary")).Click(); }
public static void GridSetup() { #region DEMO CODE //DesiredCapabilities capabilities = new DesiredCapabilities(); //capabilities = DesiredCapabilities.Firefox(); //capabilities.SetCapability(CapabilityType.BrowserName, "firefox"); //capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows)); //Instance = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capabilities); #endregion if (GridBrowsers.Count() > 0) { GridBrowsers = new List <DesiredCapabilities> { DesiredCapabilities.InternetExplorer(), DesiredCapabilities.Chrome(), DesiredCapabilities.Firefox() } } ; foreach (var browser in GridBrowsers) { Instance = new RemoteWebDriver(new Uri(BaseUrl), browser); } Instance.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); }
private static void SetDesiredCapablities(string deviceOrbrowser) { switch (deviceOrbrowser.ToLower()) { case "chrome": capabillities = DesiredCapabilities.Chrome(); break; case "firefox": capabillities = DesiredCapabilities.Firefox(); break; case "edge": capabillities = DesiredCapabilities.Edge(); break; case "ipad": capabillities = DesiredCapabilities.IPad(); break; case "iphone": capabillities = DesiredCapabilities.IPhone(); break; case "ie": case "internetexplorer": capabillities = DesiredCapabilities.InternetExplorer(); break; default: break; } }
public static IWebDriver CreateGridDriver(DriverToUse driverToUse) { var gridUrl = ConfigurationManager.AppSettings["GridUrl"]; var desiredCapabilities = DesiredCapabilities.InternetExplorer(); switch (driverToUse) { case DriverToUse.Firefox: desiredCapabilities = DesiredCapabilities.Firefox(); desiredCapabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, FirefoxProfile); break; case DriverToUse.InternetExplorer: desiredCapabilities = DesiredCapabilities.InternetExplorer(); break; case DriverToUse.Chrome: desiredCapabilities = DesiredCapabilities.Chrome(); break; } desiredCapabilities.IsJavaScriptEnabled = true; var remoteDriver = new ExtendedRemoteWebDriver(new Uri(gridUrl), desiredCapabilities, TimeSpan.FromSeconds(180)); var nodeHost = remoteDriver.GetNodeHost(); Debug.WriteLine("Running tests on host " + nodeHost); return(remoteDriver); }
public DesiredCapabilities GetCapabilitiesForBrowser(Browser browser) { switch (browser) { case Browser.PhantomJS: return(DesiredCapabilities.PhantomJS()); case Browser.IE: return(DesiredCapabilities.InternetExplorer()); case Browser.Chrome: return(DesiredCapabilities.Chrome()); case Browser.Safari: return(DesiredCapabilities.Safari()); case Browser.Android: return(DesiredCapabilities.Android()); case Browser.IPhone: var capabilities = DesiredCapabilities.IPhone(); capabilities.SetCapability("device", "iphone"); capabilities.SetCapability("app", "safari"); return(capabilities); case Browser.IPad: return(DesiredCapabilities.IPad()); case Browser.Firefox: default: return(DesiredCapabilities.Firefox()); } }
public static IWebDriver getDriver() { if (driver == null) { try { String remoteServerUrl; if (String.Equals(Configuration.GetInstance().GetByKey("IsRemote"), "Yes", StringComparison.OrdinalIgnoreCase)) { remoteServerUrl = Configuration.GetInstance().GetByKey("RemoteServer"); String appURL = Configuration.GetInstance().GetByKey("HBLWeb"); initialize(DesiredCapabilities.Chrome(), remoteServerUrl, appURL); } if (String.Equals(Configuration.GetInstance().GetByKey("IsRemote"), "No", StringComparison.OrdinalIgnoreCase)) { String appURL = Configuration.GetInstance().GetByKey("HBLWeb"); initialize(appURL); } return(driver); } catch (Exception exception) { Console.WriteLine(exception.Message); } } return(driver); }
public static void GetWebDriver(string browser) { if (browser == "chrome") { IoLibrary.WriteLine("Launching Chrome Browser."); ChromeOptions options = new ChromeOptions(); options.AddArguments("--start-maximized"); options.AddArguments("--disable-extensions"); Driver = new ChromeDriver(IoLibrary.GetBinPath(), options); Driver.Manage().Cookies.DeleteAllCookies(); } else if (browser == "firefox") { // todo: add proper ff loation code.. System.setProperty("webdriver.gecko.driver", "src/main/resources/geckodriver"); } else if (browser == "seleniumGrid") { IoLibrary.WriteLine("Launching Browser Using Selenium Grid - Chrome Browser."); const string gridUrl = "http://*****:*****@SESYNPZ6.gridlastic.com:80/wd/hub"; ChromeOptions options = new ChromeOptions(); options.AddArguments("--start-maximized"); options.AddArguments("--disable-extensions"); DesiredCapabilities capabilities = DesiredCapabilities.Chrome(); capabilities.SetCapability(ChromeOptions.Capability, options); Driver = new RemoteWebDriver(capabilities); } else { throw new Exception(string.Format("Browser Type {0}, not Found, please add additional code for this desired WebDriver Type.", browser)); } }
private static void SelectBrowser(string browser) { switch (browser) { case "Firefox": _driver = new FirefoxDriver(); break; case "Chrome": var chromeDriverService = ChromeDriverService.CreateDefaultService(DriversPath, "chromedriver.exe"); chromeDriverService.Start(); _driver = new RemoteWebDriver(chromeDriverService.ServiceUrl, DesiredCapabilities.Chrome()); _driverService = chromeDriverService; break; case "IE": _driver = new InternetExplorerDriver(DriversPath); break; case "PhantomJS": var phantomJsPath = SmokeTestPaths.GetPhantomJsPath(); var phantomJsDriverService = PhantomJSDriverService.CreateDefaultService(phantomJsPath); _driver = new PhantomJSDriver(phantomJsDriverService); _driverService = phantomJsDriverService; break; default: throw new ArgumentException("Unknown browser"); } }
public IBrowserDriver Create(BrowserNames browserName) { if (configuration.WebDriver.IsRemote) { switch (browserName) { case BrowserNames.chrome: return(CreateRemoteWebDriver(DesiredCapabilities.Chrome())); case BrowserNames.firefox: return(CreateRemoteWebDriver(DesiredCapabilities.Firefox())); case BrowserNames.opera: return(CreateRemoteWebDriver(DesiredCapabilities.Opera())); case BrowserNames.safari: return(CreateRemoteWebDriver(DesiredCapabilities.Safari())); case BrowserNames.ie: return(CreateRemoteWebDriver(DesiredCapabilities.InternetExplorer())); default: throw new Exception($"Value Not Supported `{browserName}`!"); } } return(driverFactory[browserName](configuration.WebDriver.BrowserDriversPath)); }
private static ICapabilities GetBrowserCapabilities(BrowserType driverType) { switch (driverType) { case BrowserType.Firefox: return(DesiredCapabilities.Firefox()); case BrowserType.Chrome: return(DesiredCapabilities.Chrome()); case BrowserType.InternetExplorer: return(DesiredCapabilities.InternetExplorer()); case BrowserType.Opera: return(DesiredCapabilities.Opera()); case BrowserType.Safari: return(DesiredCapabilities.Safari()); case BrowserType.Phantom: return(DesiredCapabilities.PhantomJS()); case BrowserType.Edge: return(DesiredCapabilities.Edge()); default: throw new ArgumentOutOfRangeException(nameof(driverType), driverType, null); } }
public static IWebDriver Create(string browser) { DesiredCapabilities capabilities; IWebDriver driver; switch (browser) { case "chrome": capabilities = DesiredCapabilities.Chrome(); driver = new RemoteWebDriver(RemoteWebDriverUri, capabilities); break; case "internet explorer": InternetExplorerOptions options = new InternetExplorerOptions(); options.IgnoreZoomLevel = true; capabilities = (DesiredCapabilities)options.ToCapabilities(); driver = new RemoteWebDriver(RemoteWebDriverUri, capabilities, TimeSpan.FromSeconds(10)); break; case "edge": capabilities = DesiredCapabilities.Edge(); driver = new RemoteWebDriver(RemoteWebDriverUri, capabilities); break; default: capabilities = DesiredCapabilities.Firefox(); driver = new RemoteWebDriver(RemoteWebDriverUri, capabilities); break; } return(driver); }
public static IWebDriver Remote(Uri driverHub, string browserName, string browserVersion) { DesiredCapabilities capabilities = new DesiredCapabilities(); switch (browserName) { case "chrome": ChromeOptions ChrOpt = new ChromeOptions(); ChrOpt.AddArguments("test-type"); capabilities = DesiredCapabilities.Chrome(); capabilities.SetCapability(ChromeOptions.Capability, ChrOpt); capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows)); break; case "internet explorer": capabilities = DesiredCapabilities.InternetExplorer(); capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows)); break; default: FirefoxProfile ffProfile = new FirefoxProfile(); capabilities = DesiredCapabilities.Firefox(); capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, ffProfile); capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows)); break; } capabilities.SetCapability(CapabilityType.BrowserName, browserName); capabilities.SetCapability(CapabilityType.Version, browserVersion); return(new RemoteWebDriver(driverHub, capabilities)); }
private void MyTestInitialize() { baseurl = ConfigurationManager.AppSettings["baseurl"].ToString(); if (ConfigurationManager.AppSettings["usePhantom"].ToString() == "true") { if (ConfigurationManager.AppSettings["useDocker"].ToString() == "true") { baseurl = ConfigurationManager.AppSettings["baseurlDocker"].ToString(); DesiredCapabilities dc = DesiredCapabilities.Chrome(); this.Driver = new RemoteWebDriver(new ChromeOptions()); } else { this.Driver = new PhantomJSDriver(); var driverService = PhantomJSDriverService.CreateDefaultService(); driverService.HideCommandPromptWindow = true; this.Driver = new PhantomJSDriver(driverService); } } else { this.Driver = new ChromeDriver(); } this.Wait = new WebDriverWait(this.Driver, TimeSpan.FromSeconds(30)); }
private static IWebDriver CreateLocalDriver(ICapabilities capabilities) { // Implementation is incomplete: the capabilities are not converted to the options string browserType = capabilities.BrowserName; if (browserType == DesiredCapabilities.Firefox().BrowserName) { return(new FirefoxDriver()); } if (browserType == DesiredCapabilities.InternetExplorer().BrowserName) { return(new InternetExplorerDriver()); } if (browserType == DesiredCapabilities.Chrome().BrowserName) { return(new ChromeDriver()); } if (browserType == DesiredCapabilities.Safari().BrowserName) { return(new SafariDriver()); } if (browserType == DesiredCapabilities.PhantomJS().BrowserName) { return(new PhantomJSDriver()); } throw new Exception("Unrecognized browser type: " + browserType); }
public void DebugBSChrome() { Browser = "Chrome"; Env = "BS Desktop"; Config = false; configurationbool = false; DesiredCapabilities desiredCap = DesiredCapabilities.Chrome(); ChromeOptions chrOpts = new ChromeOptions(); chrOpts.AddArguments("test-type"); chrOpts.AddArguments("--disable-extensions"); //chrOpts.AddArgument("incognito"); //desiredCap.SetCapability(ChromeOptions.Capability, chrOpts); // updated desiredCap = (DesiredCapabilities)chrOpts.ToCapabilities(); desiredCap.SetCapability("browserstack.user", browserstack_user); desiredCap.SetCapability("browserstack.key", browserstack_key); desiredCap.SetCapability("platform", "WINDOWS"); desiredCap.SetCapability("os", "WINDOWS"); desiredCap.SetCapability("os_version", "8"); // desiredCap.SetCapability("build", Environment.GetEnvironmentVariable("BS_AUTOMATE_BUILD")); desiredCap.SetCapability("browserstack.debug", true); // string strTestName = TestContext.CurrentContext.Test.Name.ToString(); desiredCap.SetCapability("project", Environment.GetEnvironmentVariable("BS_AUTOMATE_PROJECT")); desiredCap.SetCapability("build", Environment.GetEnvironmentVariable("BS_AUTOMATE_BUILD")); driver = new RemoteWebDriver( new Uri("http://hub-cloud.browserstack.com/wd/hub/"), desiredCap); SessionId = ((RemoteWebDriver)driver).SessionId.ToString(); driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings.Get("ElementPageLoad")))); driver.Manage().Window.Maximize(); }
/// <summary> /// Create browser given browser type /// </summary> /// <param name="browserType"></param> /// <returns></returns> public IWebDriver CreateBrowser(BrowserType browserType) { if (AbstractionsLocator.Instance.RegistrySystem.GetRegistryKeyValue(Registry.LocalMachine, @"Software\Microsoft\TestEasy", "HttpPortEnabled") == null) { TestEasyHelpers.Firewall.AddPortToFirewall(80, "HttpPort"); AbstractionsLocator.Instance.RegistrySystem.SetRegistryKeyValue(Registry.LocalMachine, @"Software\Microsoft\TestEasy", "HttpPortEnabled", 1); } var capability = DesiredCapabilities.HtmlUnitWithJavaScript(); switch (browserType) { case BrowserType.Ie: capability = DesiredCapabilities.InternetExplorer(); break; case BrowserType.Chrome: capability = DesiredCapabilities.Chrome(); break; case BrowserType.Firefox: capability = DesiredCapabilities.Firefox(); break; case BrowserType.Safari: capability = DesiredCapabilities.Safari(); break; default: // <- case BrowserType.HtmlUnit or BrowserType.Default return(new RemoteWebDriver(capability)); } return(new RemoteWebDriver(new Uri(TestEasyConfig.Instance.Client.RemoteHubUrl), capability, TimeSpan.FromMinutes(5))); }
public static void StartWeb() { capabillities = new DesiredCapabilities(); webLocators = LocatorHelper.LoadLocators("locators/locators.csv"); var browser = ConfigurationManager.AppSettings.Get("Browser"); switch (browser.ToLower()) { case "chrome": capabillities = DesiredCapabilities.Chrome(); StartChromeDriver(); break; case "firefox": capabillities = DesiredCapabilities.Firefox(); StartFireFoxDriver(); break; case "edge": capabillities = DesiredCapabilities.Edge(); StartEdgeDriver(); break; case "htmlunit": capabillities = DesiredCapabilities.HtmlUnit(); StartHtmlUnitDriver(); break; default: break; } }
// Creates an instance of remote webdriver accordingly to assigned browser. // Use Selenium RC server on remote machine for this type of webdriver. private void StartRemotely(string remoteAddress) { DesiredCapabilities capabilities = null; Uri remoteAddressUri = null; if (!Uri.IsWellFormedUriString(remoteAddress, UriKind.RelativeOrAbsolute)) { throw new UriFormatException("Invalid Remote Address URI."); } remoteAddressUri = new Uri(remoteAddress); CorrectRemoteAddress(ref remoteAddressUri); switch (browser) { case BrowserType.Firefox: capabilities = DesiredCapabilities.Firefox(); break; case BrowserType.InternetExplorer: capabilities = DesiredCapabilities.InternetExplorer(); break; case BrowserType.Chrome: capabilities = DesiredCapabilities.Chrome(); break; case BrowserType.Safari: // TODO: so, probably it works. throw new Exception("There is no support for Safari Webdriver yet."); } driver = new RemoteWebDriver(remoteAddressUri, capabilities); }
private static IWebDriver CreateLocalDriver(ICapabilities capabilities) { // Implementation is incomplete: the capabilities are not converted to the options string browserType = capabilities.BrowserName; if (browserType == DesiredCapabilities.Firefox().BrowserName) { FirefoxDriver driver = new FirefoxDriver(); driver.Manage().Window.Maximize(); return(driver); } if (browserType == DesiredCapabilities.InternetExplorer().BrowserName) { return(new InternetExplorerDriver()); } if (browserType == DesiredCapabilities.Chrome().BrowserName) { ChromeOptions options = new ChromeOptions(); options.AddArguments("--start-maximized"); return(new ChromeDriver(options)); } if (browserType == DesiredCapabilities.Safari().BrowserName) { return(new SafariDriver()); } if (browserType == DesiredCapabilities.PhantomJS().BrowserName) { return(new PhantomJSDriver()); } throw new Exception("Unrecognized browser type: " + browserType); }
/// <summary> /// Method to start the application with the specified type of browser, platform and URL /// </summary> public static void Start(BrowserType browserType, PlatformType platformType, string serverUrl, string driverPath, string applicationURL) { string browser = browserType.ToString().ToLower(); DesiredCapabilities compat; switch (browserType) { case BrowserType.InternetExplorer: compat = DesiredCapabilities.InternetExplorer(); break; case BrowserType.Chrome: compat = DesiredCapabilities.Chrome(); break; case BrowserType.Safari: compat = DesiredCapabilities.Safari(); break; case BrowserType.Firefox: default: compat = DesiredCapabilities.Firefox(); break; } compat.IsJavaScriptEnabled = true; compat.Platform = new Platform(platformType); webDriver = new ScreenShotRemoteWebDriver(compat); webDriver.Manage().Window.Maximize(); webDriver.Url = applicationURL; }
private void InitializeSessionManager() { this.defaultDrivers.Add(DesiredCapabilities.InternetExplorer(), "OpenQA.Selenium.IE.InternetExplorerDriver, WebDriver"); this.defaultDrivers.Add(DesiredCapabilities.Firefox(), "OpenQA.Selenium.Firefox.FirefoxDriver, WebDriver"); this.defaultDrivers.Add(DesiredCapabilities.Chrome(), "OpenQA.Selenium.Chrome.ChromeDriver, WebDriver"); this.RegisterDefaultDrivers(); }
//public static void createAndStartService() //{ // ChromeDriverService service; // IWebDriver driver; // service = ChromeDriverService.CreateDefaultService() // .usingChromeDriverExecutable(new File("path/to/my/chromedriver")) // .usingAnyFreePort() // .build(); // service.Start(); //} public static IWebDriver OpenChromeBrowserWithUrl(IWebDriver driver, string strUrlToOpen, Boolean OpenInNewWindow = false) { try { DesiredCapabilities capability = DesiredCapabilities.Chrome(); //ChromeOptions options = new ChromeOptions(); //string[] strPaths = { @"C:\Users\kiwi\Downloads\logmeonce_2.6.8.crx" }; //options.AddExtensions(strPaths); //capability.SetCapability(ChromeOptions.Capability, options); capability.IsJavaScriptEnabled = true; capability.SetCapability(capability.BrowserName, DesiredCapabilities.Chrome().BrowserName); capability.SetCapability("webdriver.chrome.driver", "C:\\chromedriver.exe"); Uri remote_grid = new Uri("http://localhost:4444/wd/hub"); driver = new ScreenShotRemoteWebDriver(remote_grid, capability); //if (OpenInNewWindow) driver = new ScreenShotRemoteWebDriver(remote_grid, capability); driver.Navigate().GoToUrl(strUrlToOpen); driver.Manage().Window.Maximize(); Report.AddToHtmlReportPassed("Chrome Browser Open for '" + strUrlToOpen + "' ."); } catch (Exception ex) { //Console.WriteLine("ex::", ex.Message); Report.AddToHtmlReportFailed(driver, ex, "Chrome Browser Open for '" + strUrlToOpen + "' ."); } return(driver); }
private void SetWebDriverToChrome() { var driverExePath = _driverPaths + "chrome" + Path.DirectorySeparatorChar + _chromedriver; _driverservice = ChromeDriverService.CreateDefaultService(driverExePath); var settings = new ChromeOptions { BinaryLocation = "", LeaveBrowserRunning = true }; try { _driverservice.Start(); } catch (Exception err) { throw new DriverServiceNotFoundException(err.Message); } _capabilities = DesiredCapabilities.Chrome(); SetAdditionalCapabilities(); WebDriver = new ScreenShotRemoteWebDriver(_driverservice.ServiceUrl, _capabilities); }
private static DesiredCapabilities GenerateDesiredCapabilities(Browser browser) { DesiredCapabilities browserCapabilities = null; switch (browser) { case Browser.InternetExplorer: case Browser.InternetExplorer64: browserCapabilities = DesiredCapabilities.InternetExplorer(); break; case Browser.Firefox: browserCapabilities = DesiredCapabilities.Firefox(); break; case Browser.Chrome: browserCapabilities = DesiredCapabilities.Chrome(); break; case Browser.PhantomJs: browserCapabilities = DesiredCapabilities.PhantomJS(); break; case Browser.Safari: browserCapabilities = DesiredCapabilities.Safari(); break; default: throw new AutomationDriverException("Selected browser [{0}] not supported. Unable to determine appropriate capabilities.", browser.ToString()); } browserCapabilities.IsJavaScriptEnabled = true; return(browserCapabilities); }
public WebDriverWrapper(string proxy = null) { DesiredCapabilities capabilities = DesiredCapabilities.Chrome(); string assembliesDirectory = FindAssembliesDirectory(); string chromePath = Path.Combine(assembliesDirectory, "Chrome", "chrome.exe"); SetChromeVersionToRegistry(chromePath); var chromeOptions = new ChromeOptions { BinaryLocation = chromePath }; if (!string.IsNullOrEmpty(proxy)) { chromeOptions.Proxy = new Proxy { HttpProxy = proxy } } ; chromeOptions.AddArguments("start-maximized"); chromeOptions.AddUserProfilePreference("download.prompt_for_download", false); chromeOptions.AddUserProfilePreference("download.default_directory", WebDriverDownloadDirectory.DirectoryPath); chromeOptions.AddUserProfilePreference("download.directory_upgrade", true); chromeOptions.AddUserProfilePreference("profile.content_settings.pattern_pairs", new Dictionary <string, object> { { "http://*,*", new { plugins = 1 } } }); capabilities.SetCapability(ChromeOptions.Capability, chromeOptions); string directory = Path.Combine(assembliesDirectory, "Selenium"); driver = new ChromeDriver(directory, chromeOptions); }
public static DesiredCapabilities BuildRemoteCapabilities(DriverConfigurationSection configSection) { switch (configSection.RemoteBrowser.ToLower()) { case "firefox": var capabilities = DesiredCapabilities.Firefox(); capabilities.IsJavaScriptEnabled = true; return(capabilities); case "chrome": return(DesiredCapabilities.Chrome()); case "internet explorer": return(new DesiredCapabilities(new Dictionary <string, object> { { "browserName", "internet explorer" }, { "version", configSection.RemoteBrowserVersion }, { "javascriptEnabled", true } })); default: throw new ApplicationException( string.Format( "Unrecognized remote browser {0}", configSection.RemoteBrowser)); } }