private OperaOptions CreateOptions() { var options = new OperaOptions(); if (BrowserSettings.Settings.IsRemoteRun()) { options.AddAdditionalCapability("version", BrowserSettings.Settings.Remote.Version ?? Constants.DEFAULT_VERSION, true); options.AddAdditionalCapability("enableVNC", true, true); options.AddAdditionalCapability("platform", BrowserSettings.Settings.Remote.Platform ?? Constants.DEFAULT_PLATFORM, true); options.AddAdditionalCapability("name", BrowserSettings.Settings.Remote.Project ?? Constants.DEFAULT_PROJECT, true); } if (BrowserSettings.Settings.IsOptions()) { options.AddArguments(BrowserSettings.Settings.Options); } if (!BrowserSettings.Settings.IsBinaryPath()) { options.BinaryLocation = BrowserSettings.Settings.BinaryLocation; } if (BrowserSettings.Settings.CheckCapability()) { options.AddCapabilities(BrowserSettings.Settings.Capabilities); } return(options); }
private static RemoteWebDriver StartOperaDriver(DriverSettings settings) { var options = new OperaOptions(); settings.Capabilities?.ForEach(cap => options.AddAdditionalCapability(cap.Key, cap.Value)); if (!string.IsNullOrEmpty(settings.BrowserBinaryPath)) { options.BinaryLocation = settings.BrowserBinaryPath; } if (!string.IsNullOrEmpty(settings.Proxy)) { options.Proxy = new Proxy { HttpProxy = settings.Proxy } } ; if (settings.BrowserBinaryPath != null) { options.BinaryLocation = settings.BrowserBinaryPath; } if (settings.CmdArgs != null) { options.AddArguments(settings.CmdArgs); } if (settings.Extensions != null) { options.AddExtensions(settings.Extensions); } return(new OperaDriver(options)); }
private OperaOptions GetOperaDriverOptions() { OperaOptions options = new OperaOptions(); if (_config.ExtensionsList.Count > 0) { options.AddExtensions(_config.ExtensionsList); } if (_config.ArgumentsList.Count > 0) { options.AddArguments(_config.ArgumentsList); } foreach (KeyValuePair <string, object> keyValuePair in _config.AdditionalCapability) { options.AddAdditionalCapability(keyValuePair.Key, keyValuePair.Value); } foreach (KeyValuePair <string, object> keyValuePair in _config.UserProfilePreferences) { options.AddUserProfilePreference(keyValuePair.Key, keyValuePair.Value); } return(options); }
public static void Initialize(string baseUrl, int COD_BROWSER, string IE_DRIVER_PATH, string CHROME_DRIVER_PATH, string FIREFOX_DRIVER_PATH, string SAFARI_DRIVER_PATH, string EDGE_DRIVER_PATH, string OPERA_DRIVER_PATH) { //Overall Config isWebDriverOpen = true; TopDown_QA_FrameWork.Driver.baseUrl = baseUrl; PRINT_CONT = 0; switch (COD_BROWSER) { case IE_BROWSER: //IE Configurações opcoesIE = new InternetExplorerOptions(); //new //opcoesIE.RequireWindowFocus = true; //opcoesIE.PageLoadStrategy = InternetExplorerPageLoadStrategy.Eager; //opcoesIE.EnablePersistentHover = true; //opcoesIE.ElementScrollBehavior = InternetExplorerElementScrollBehavior.Top; // //opcoesIE.ForceCreateProcessApi = true; opcoesIE.EnableNativeEvents = true; opcoesIE.EnsureCleanSession = true; //opcoesIE.RequireWindowFocus = true; opcoesIE.PageLoadStrategy = InternetExplorerPageLoadStrategy.Normal; opcoesIE.IntroduceInstabilityByIgnoringProtectedModeSettings = true; ieService = InternetExplorerDriverService.CreateDefaultService(IE_DRIVER_PATH); //ieService = InternetExplorerDriverService.CreateDefaultService(@"D:\Peterson\Projetos\QADynamicFramework\UI_test_player_TD\bin\Debug\WebDriver\IEDriverServer_Win32_2.53.1"); //ieService = InternetExplorerDriverService.CreateDefaultService(); ieService.HideCommandPromptWindow = true; webDriver = new InternetExplorerDriver(ieService, opcoesIE); break; case CHROME_BROWSER: //// Chrome opcoesChrome = new ChromeOptions(); ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService(CHROME_DRIVER_PATH); chromeDriverService.HideCommandPromptWindow = true; webDriver = new ChromeDriver(chromeDriverService, opcoesChrome); break; case FIREFOX_BROWSER: //Firefox Configurações opcoesFirefox = new FirefoxOptions(); FirefoxDriverService firefoxDriverService = FirefoxDriverService.CreateDefaultService(FIREFOX_DRIVER_PATH); firefoxDriverService.HideCommandPromptWindow = true; FirefoxProfile ffProfile = new FirefoxProfile(); ffProfile.EnableNativeEvents = true; webDriver = new FirefoxDriver(firefoxDriverService); break; case SAFARI_BROWSER: opcoesSafari = new SafariOptions(); SafariDriverService safariDriverservice = SafariDriverService.CreateDefaultService(); webDriver = new SafariDriver(); //Logger.abrir(); //DesiredCapabilities caps = new DesiredCapabilities(); //caps.SetCapability("browserName", "safari"); //caps.SetCapability("plataform", "WINDOWS"); //webDriver = new RemoteWebDriver(new Uri("http://google.com"), caps); break; case EDGE_BROWSER: opcoesEdge = new EdgeOptions(); EdgeDriverService edgeDriverService = EdgeDriverService.CreateDefaultService(EDGE_DRIVER_PATH); opcoesEdge.AddAdditionalCapability("nativeEvents", true); edgeDriverService.HideCommandPromptWindow = true; webDriver = new EdgeDriver(edgeDriverService, opcoesEdge); break; case OPERA_BROWSER: opcoesOpera = new OperaOptions(); OperaDriverService operaDriverService = OperaDriverService.CreateDefaultService(OPERA_DRIVER_PATH); opcoesOpera.AddAdditionalCapability("nativeEvents", true); operaDriverService.HideCommandPromptWindow = true; webDriver = new OperaDriver(operaDriverService, opcoesOpera); break; } //Post Configuration wait = new WebDriverWait(webDriver, new TimeSpan(0, 0, 30)); acoes = new Actions(webDriver); webDriver.Navigate().GoToUrl(baseUrl); webDriver.Manage().Window.Maximize(); //webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30)); }
public void BeforeScenarioOptions() { //This pre-requesite step will set options for the various browsers types. As selenium 3, this is per browser. ChromeOptions SetChromeOptions(string version = "", string[] parameters = null, Dictionary <string, object> extraAdditionalCaps = null) { var options = new ChromeOptions(); //Set Chrome GeoLocation for an scenario matching the tag if (scenarioContext.ScenarioInfo.Tags.Any(x => x == "ScenarioThatRequiresGeoLocForInstance")) { options.AddUserProfilePreference("profile.default_content_setting_values.geolocation", 2); } options.AddArgument("disable-infobars"); options.SetLoggingPreference(LogType.Browser, LogLevel.Severe); try { options.AddArguments(EnvironmentConfig.Instance.BrowserArgs); } catch (Exception) { // } if (!String.IsNullOrEmpty(version)) { options.BrowserVersion = version; } if (parameters != null) { options.AddArguments(parameters); } if (extraAdditionalCaps != null) { foreach (KeyValuePair <string, object> ac in extraAdditionalCaps) { options.AddAdditionalCapability(ac.Key, ac.Value); } } return(options); } FirefoxOptions SetFirefoxOptions(string[] parameters = null, Dictionary <string, object> extraAdditionalCaps = null) { var options = new FirefoxOptions(); options.AcceptInsecureCertificates = true; try { options.AddArguments(EnvironmentConfig.Instance.BrowserArgs); } catch (Exception) { // } if (parameters != null) { options.AddArguments(parameters); } if (extraAdditionalCaps != null) { foreach (KeyValuePair <string, object> ac in extraAdditionalCaps) { options.AddAdditionalCapability(ac.Key, ac.Value); } } return(options); } AppiumOptions SetAndroidWebMobileOptions(string device, string platformVersion, string androidVersion, Dictionary <string, object> extraAdditionalCaps = null) { var options = new AppiumOptions(); options.AddAdditionalCapability(MobileCapabilityType.BrowserName, "chrome"); options.AddAdditionalCapability(MobileCapabilityType.PlatformName, MobilePlatform.Android); options.AddAdditionalCapability(MobileCapabilityType.FullReset, false); options.AddAdditionalCapability(MobileCapabilityType.NoReset, true); options.AddAdditionalCapability(MobileCapabilityType.DeviceName, device); options.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, platformVersion); options.AddAdditionalCapability("version", androidVersion); if (extraAdditionalCaps != null) { foreach (KeyValuePair <string, object> ac in extraAdditionalCaps) { options.AddAdditionalCapability(ac.Key, ac.Value); } } return(options); } OperaOptions SetOperaOptions(string version, string[] parameters = null, Dictionary <string, object> extraAdditionalCaps = null) { var options = new OperaOptions(); options.AddAdditionalCapability("version", version); if (parameters != null) { options.AddArguments(parameters); } if (extraAdditionalCaps != null) { foreach (KeyValuePair <string, object> ac in extraAdditionalCaps) { options.AddAdditionalCapability(ac.Key, ac.Value); } } return(options); } SafariOptions SetSafariOptions(Dictionary <string, object> extraAdditionalCaps = null) { SafariOptions options = new SafariOptions(); if (extraAdditionalCaps != null) { foreach (KeyValuePair <string, object> ac in extraAdditionalCaps) { options.AddAdditionalCapability(ac.Key, ac.Value); } } return(options); } //Gets the browser tag of the test for crossbrowser testing to set options before instantiating driver, defaults to chrome scenarioContext.TryGetValue("Browser", out var browser); /*Switch browser and set options * These are examples for local, grid and cloud (Browserstack) browsers */ switch (browser) { case "BrowserStack_iOS11": Dictionary <string, object> browserstackOptions = new Dictionary <string, object>(); browserstackOptions.Add("osVersion", "14"); browserstackOptions.Add("deviceName", "iPhone 11"); browserstackOptions.Add("realMobile", "true"); browserstackOptions.Add("appiumVersion", "1.16.0"); browserstackOptions.Add("local", "false"); browserstackOptions.Add("debug", "true"); browserstackOptions.Add("networkLogs", "true"); browserstackOptions.Add("userName", EnvironmentConfig.Instance.BrowserStack.Username); browserstackOptions.Add("accessKey", EnvironmentConfig.Instance.BrowserStack.AutomateKey); scenarioContext.Add("options", SetSafariOptions(extraAdditionalCaps: new Dictionary <string, object> { { "bstack:options", browserstackOptions } } )); break; case "Grid_Android_Chrome": scenarioContext.Add("options", SetAndroidWebMobileOptions(device: "samsung_galaxy_s10_11.0", platformVersion: "11.0.0", androidVersion: "11.0")); break; case "Grid_OperaBlink": //must use desired capabilities to use custom browser name var gridOperaBlinkOptions = new DesiredCapabilities(); gridOperaBlinkOptions.SetCapability("browserName", "operablink"); scenarioContext.Add("options", gridOperaBlinkOptions); break; case "Grid_Chrome_Headless": scenarioContext.Add("options", SetChromeOptions(version: "88.0.4324.96", parameters: new string[] { "headless" })); break; case "Headless": scenarioContext.Add("options", SetChromeOptions(parameters: new string[] { "headless" })); break; case "Grid_Firefox": case "Firefox": scenarioContext.Add("options", SetFirefoxOptions()); break; case "Grid_Chrome": scenarioContext.Add("options", SetChromeOptions(version: "88.0.4324.96")); break; case "Chrome": default: scenarioContext.Add("options", SetChromeOptions()); break; } }
public static void Main(string[] args) { string currentUser = string.Empty; try { new DriverManager().SetUpDriver(new OperaConfig(), "Latest", Architecture.Auto); string OperaProfilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Opera Software\\Opera Stable"); var jsonText = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "accounts.json")); var jsonAccounts = JsonConvert.DeserializeObject <List <Account> >(jsonText); OperaOptions opt = new OperaOptions(); opt.PageLoadStrategy = PageLoadStrategy.Eager; opt.AddArgument($"user-data-dir={OperaProfilePath}"); opt.AddArguments(new[] { "--incognito" }); opt.AddAdditionalCapability("useAutomationExtension", false); opt.AddExcludedArgument("enable-automation"); OperaDriverService driverService = OperaDriverService.CreateDefaultService(); driverService.HideCommandPromptWindow = true; for (int i = 0; i <= jsonAccounts.Count; i++) { currentUser = jsonAccounts[i].name; KillAllDrivers(); IWebDriver driver = new OperaDriver(driverService, opt); try { driver.Url = "https://giris.hepsiburada.com"; driver.WaitForPageLoad(); IWebElement elMail = driver.IsElementPresent(By.XPath("//input[@id='txtUserName']")); IWebElement elPass = driver.IsElementPresent(By.XPath("//input[@id='txtPassword']")); IWebElement elBtnLogin = driver.IsElementPresent(By.XPath("//button[contains(text(),'Giriş')]")); if (elMail == null && elPass == null && elBtnLogin == null) { throw new Exception("CANNOT_FIND_LOGINPAGE"); } elMail.Click(); elMail?.Clear(); elMail?.SendKeys(jsonAccounts[i].name); WaitSomeSecond(1); elPass?.Clear(); elPass?.SendKeys(jsonAccounts[i].pass); WaitSomeSecond(1); var touchActions = new Actions(driver); touchActions.MoveToElement(elBtnLogin).Perform(); touchActions.SendKeys(Keys.Enter).Perform(); WaitSomeSecond(1); driver.WaitForPageLoad(); WaitSomeSecond(6); if (!CheckIsLoggedorRegistered(driver, true)) { throw new Exception("CANNOT_LOGIN"); } driver.Navigate().GoToUrl("https://hesabim.hepsiburada.com/iletisim-tercihlerim"); driver.WaitForPageLoad(); WaitSomeSecond(5); var mailNotify = driver.RunJsCommand("return document.querySelector('div.x0LYwM_8u4ipmQOzUpbEM:nth-child(2) > div:nth-child(2) > div:nth-child(1) > label:nth-child(1) > input');"); if (mailNotify != null) { var checkState = (bool)driver.RunJsCommand("return arguments[0].checked", new[] { mailNotify }); if (checkState) { driver.RunJsCommand("arguments[0].click()", new[] { mailNotify }); Console.WriteLine($"{jsonAccounts[i].name} başarılı"); WaitSomeSecond(3); } else { Console.WriteLine($"{jsonAccounts[i].name} zaten kapatılmış"); } } else { throw new Exception("CANNOT_FOUND_MAIL_NOTIFY"); } } catch (Exception e) { Console.WriteLine($"Hesap Adı : {jsonAccounts[i].name}"); Console.WriteLine(e); Thread.Sleep(TimeSpan.FromSeconds(new Random().Next(5, 10))); } driver.Quit(); Thread.Sleep(TimeSpan.FromSeconds(new Random().Next(30, 70))); } } catch (Exception e) { Console.WriteLine(e); } }