/// <summary> /// Использование оперы в качестве браузера /// </summary> public void InitializeOperaDriver() { OperaOptions options = new OperaOptions(); options.BinaryLocation = settings.OperaPath; options.AddArgument("user-data-dir=" + Directory.GetCurrentDirectory() + @"\opera"); options.AddArgument("private"); driver = new OperaDriver(options); driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(40); }
/// <summary> /// Instantiates a RemoteWebDriver instance based on the browser passed to this method. Opens the browser and maximizes its window. /// </summary> /// <param name="browser">The browser to get instantiate the Web Driver for.</param> /// <param name="browserProfilePath">The folder path to the browser user profile to use with the browser.</param> /// <returns>The RemoteWebDriver of the browser passed in to the method.</returns> public static RemoteWebDriver CreateDriverAndMaximize(string browser, string browserProfilePath = "") { // Create a webdriver for the respective browser, depending on what we're testing. RemoteWebDriver driver = null; switch (browser) { case "opera": case "operabeta": OperaOptions oOption = new OperaOptions(); oOption.AddArgument("--disable-popup-blocking"); oOption.AddArgument("--power-save-mode=on"); // TODO: This shouldn't be a hardcoded path, but Opera appeared to need this speficied directly to run well oOption.BinaryLocation = @"C:\Program Files (x86)\Opera\launcher.exe"; if (browser == "operabeta") { // TODO: Ideally, this code would look inside the Opera beta folder for opera.exe // rather than depending on flaky hard-coded version in directory oOption.BinaryLocation = @"C:\Program Files (x86)\Opera beta\38.0.2220.25\opera.exe"; } driver = new OperaDriver(oOption); break; case "firefox": driver = new FirefoxDriver(); break; case "chrome": ChromeOptions option = new ChromeOptions(); option.AddUserProfilePreference("profile.default_content_setting_values.notifications", 1); if (!string.IsNullOrEmpty(browserProfilePath)) { option.AddArgument("--user-data-dir=" + browserProfilePath); } driver = new ChromeDriver(option); break; default: // Warning: this blows away all Microsoft Edge data, including bookmarks, cookies, passwords, etc EdgeDriverService svc = EdgeDriverService.CreateDefaultService(); driver = new EdgeDriver(svc); Thread.Sleep(2000); HttpClient client = new HttpClient(); client.DeleteAsync($"http://localhost:{svc.Port}/session/{driver.SessionId}/ms/history").Wait(); break; } driver.Manage().Window.Maximize(); Thread.Sleep(1000); return(driver); }
public void StartHeadless(Browser browser) { var argument = "-headless"; switch (browser) { case Browser.Chrome: ChromeOptions optionsChrome = new ChromeOptions(); optionsChrome.AddArgument(argument); WrappedDriver = new ChromeDriver(Environment.CurrentDirectory, optionsChrome); break; case Browser.Firefox: FirefoxOptions optionsFirefox = new FirefoxOptions(); optionsFirefox.AddArgument(argument); WrappedDriver = new FirefoxDriver(Environment.CurrentDirectory, optionsFirefox); break; case Browser.Opera: OperaOptions optionsOpera = new OperaOptions(); optionsOpera.AddArgument(argument); WrappedDriver = new OperaDriver(Environment.CurrentDirectory, optionsOpera); break; default: throw new ArgumentOutOfRangeException(nameof(browser), browser, null); } _webDriverWait = new WebDriverWait(WrappedDriver, TimeSpan.FromSeconds(30)); }
static public IWebDriver OpenOpera(Browser browser) { OperaOptions options = new OperaOptions(); options.AddArgument("--start-maximized"); options.BinaryLocation = $"{browser.SeleniumWebDriverPath}\\operadriver.exe"; options.BinaryLocation = @"C:\Opera\launcher.exe"; options.BinaryLocation = @"C:\Opera\73.0.3856.344\opera.exe"; IWebDriver driver = new OperaDriver(options); //OperaOptions options = new OperaOptions(); //options.AddArgument("--start-maximized"); //IWebDriver driver = new OperaDriver(browser.SeleniumWebDriverPath, options); return(driver); }
// testSettings.BrowserName = "Edge " + browserVersion; // var driverService = EdgeDriverService.CreateDefaultService(AssemblyDirectory, // "MicrosoftWebDriver.exe"); // var options = new EdgeOptions // { // PageLoadStrategy = EdgePageLoadStrategy.Default // }; // var driver = new EdgeDriver(driverService, options, testSettings.TimeoutTimeSpan); // if (testSettings.DeleteAllCookies) // { // driver.Manage().Cookies.DeleteAllCookies(); // } // driver.Manage().Timeouts().ImplicitlyWait(testSettings.TimeoutTimeSpan); // if (testSettings.MaximiseBrowser) // { // driver.Manage().Window.Maximize(); // } //var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper); //TestWebDriver = extendedWebDriver; // return extendedWebDriver; public static IWebDriver BuildOpera(bool showScraper = true) { OperaDriverService service = OperaDriverService.CreateDefaultService(System.IO.Directory.GetCurrentDirectory()); service.HideCommandPromptWindow = true; OperaOptions options = new OperaOptions() { }; options.BinaryLocation = @"C:\Users\rytal\AppData\Local\Programs\Opera\launcher.exe"; if (showScraper == false) { options.AddArgument("headless"); } options.AddArguments("--no-sandbox"); options.AddArguments("--disable-dev-shm-usage"); TimeSpan time = TimeSpan.FromSeconds(10); var driver = new OperaDriver(service, options, time); return(driver); }
public static void EnableHeadless(this OperaOptions options) { options.AddArguments("headless"); options.AddArgument("disable-gpu"); }
/// <summary> /// Instantiates a RemoteWebDriver instance based on the browser passed to this method. Opens the browser and maximizes its window. /// </summary> /// <param name="browser">The browser to get instantiate the Web Driver for.</param> /// <param name="browserProfilePath">The folder path to the browser user profile to use with the browser.</param> /// <returns>The RemoteWebDriver of the browser passed in to the method.</returns> public static RemoteWebDriver CreateDriverAndMaximize(string browser, bool clearBrowserCache, bool enableVerboseLogging = false, string browserProfilePath = "", List <string> extensionPaths = null, int port = 17556, string hostName = "localhost") { // Create a webdriver for the respective browser, depending on what we're testing. RemoteWebDriver driver = null; _browser = browser.ToLowerInvariant(); switch (browser) { case "opera": case "operabeta": OperaOptions oOption = new OperaOptions(); oOption.AddArgument("--disable-popup-blocking"); oOption.AddArgument("--power-save-mode=on"); // TODO: This shouldn't be a hardcoded path, but Opera appeared to need this speficied directly to run well oOption.BinaryLocation = @"C:\Program Files (x86)\Opera\launcher.exe"; if (browser == "operabeta") { // TODO: Ideally, this code would look inside the Opera beta folder for opera.exe // rather than depending on flaky hard-coded version in directory oOption.BinaryLocation = @"C:\Program Files (x86)\Opera beta\38.0.2220.25\opera.exe"; } ScenarioEventSourceProvider.EventLog.LaunchWebDriver(browser); driver = new OperaDriver(oOption); break; case "firefox": ScenarioEventSourceProvider.EventLog.LaunchWebDriver(browser); driver = new FirefoxDriver(); break; case "chrome": ChromeOptions option = new ChromeOptions(); option.AddUserProfilePreference("profile.default_content_setting_values.notifications", 1); ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService(); if (enableVerboseLogging) { chromeDriverService.EnableVerboseLogging = true; } if (!string.IsNullOrEmpty(browserProfilePath)) { option.AddArgument("--user-data-dir=" + browserProfilePath); } ScenarioEventSourceProvider.EventLog.LaunchWebDriver(browser); driver = new ChromeDriver(chromeDriverService, option); break; default: EdgeOptions edgeOptions = new EdgeOptions(); edgeOptions.AddAdditionalCapability("browserName", "Microsoft Edge"); EdgeDriverService edgeDriverService = null; if (extensionPaths != null && extensionPaths.Count != 0) { // Create the extensionPaths capability object edgeOptions.AddAdditionalCapability("extensionPaths", extensionPaths); foreach (var path in extensionPaths) { Logger.LogWriteLine("Sideloading extension(s) from " + path); } } if (hostName.Equals("localhost", StringComparison.InvariantCultureIgnoreCase)) { // Using localhost so create a local EdgeDriverService and instantiate an EdgeDriver object with it. // We have to use EdgeDriver here instead of RemoteWebDriver because we need a // DriverServiceCommandExecutor object which EdgeDriver creates when instantiated edgeDriverService = EdgeDriverService.CreateDefaultService(); if (enableVerboseLogging) { edgeDriverService.UseVerboseLogging = true; } _port = edgeDriverService.Port; _hostName = hostName; Logger.LogWriteLine(string.Format(" Instantiating EdgeDriver object for local execution - Host: {0} Port: {1}", _hostName, _port)); ScenarioEventSourceProvider.EventLog.LaunchWebDriver(browser); driver = new EdgeDriver(edgeDriverService, edgeOptions); } else { // Using a different host name. // We will make the assumption that this host name is the host of a remote webdriver instance. // We have to use RemoteWebDriver here since it is capable of being instantiated without automatically // opening a local MicrosoftWebDriver.exe instance (EdgeDriver automatically launches a local process with // MicrosoftWebDriver.exe). _port = port; _hostName = hostName; var remoteUri = new Uri("http://" + _hostName + ":" + _port + "/"); Logger.LogWriteLine(string.Format(" Instantiating RemoteWebDriver object for remote execution - Host: {0} Port: {1}", _hostName, _port)); ScenarioEventSourceProvider.EventLog.LaunchWebDriver(browser); driver = new RemoteWebDriver(remoteUri, edgeOptions.ToCapabilities()); } driver.Wait(2); if (clearBrowserCache) { Logger.LogWriteLine(" Clearing Edge browser cache..."); ScenarioEventSourceProvider.EventLog.ClearEdgeBrowserCacheStart(); // Warning: this blows away all Microsoft Edge data, including bookmarks, cookies, passwords, etc HttpClient client = new HttpClient(); client.DeleteAsync($"http://{_hostName}:{_port}/session/{driver.SessionId}/ms/history").Wait(); ScenarioEventSourceProvider.EventLog.ClearEdgeBrowserCacheStop(); } _edgeBrowserBuildNumber = GetEdgeBuildNumber(driver); Logger.LogWriteLine(string.Format(" Browser Version - MicrosoftEdge Build Version: {0}", _edgeBrowserBuildNumber)); string webDriverServerVersion = GetEdgeWebDriverVersion(driver); Logger.LogWriteLine(string.Format(" WebDriver Server Version - MicrosoftWebDriver.exe File Version: {0}", webDriverServerVersion)); _edgeWebDriverBuildNumber = Convert.ToInt32(webDriverServerVersion.Split('.')[2]); break; } ScenarioEventSourceProvider.EventLog.MaximizeBrowser(browser); driver.Manage().Window.Maximize(); driver.Wait(1); return(driver); }
/// <summary> /// Instantiates a RemoteWebDriver instance based on the browser passed to this method. Opens the browser and maximizes its window. /// </summary> /// <param name="browser">The browser to get instantiate the Web Driver for.</param> /// <param name="browserProfilePath">The folder path to the browser user profile to use with the browser.</param> /// <returns>The RemoteWebDriver of the browser passed in to the method.</returns> public static RemoteWebDriver CreateDriverAndMaximize(string browser, string browserProfilePath = "", List <string> extensionPaths = null) { // Create a webdriver for the respective browser, depending on what we're testing. RemoteWebDriver driver = null; ScenarioEventSourceProvider.EventLog.LaunchWebDriver(browser); switch (browser) { case "opera": case "operabeta": OperaOptions oOption = new OperaOptions(); oOption.AddArgument("--disable-popup-blocking"); oOption.AddArgument("--power-save-mode=on"); // TODO: This shouldn't be a hardcoded path, but Opera appeared to need this speficied directly to run well oOption.BinaryLocation = @"C:\Program Files (x86)\Opera\launcher.exe"; if (browser == "operabeta") { // TODO: Ideally, this code would look inside the Opera beta folder for opera.exe // rather than depending on flaky hard-coded version in directory oOption.BinaryLocation = @"C:\Program Files (x86)\Opera beta\38.0.2220.25\opera.exe"; } driver = new OperaDriver(oOption); break; case "firefox": driver = new FirefoxDriver(); break; case "chrome": ChromeOptions option = new ChromeOptions(); option.AddUserProfilePreference("profile.default_content_setting_values.notifications", 1); if (!string.IsNullOrEmpty(browserProfilePath)) { option.AddArgument("--user-data-dir=" + browserProfilePath); } driver = new ChromeDriver(option); break; default: // Warning: this blows away all Microsoft Edge data, including bookmarks, cookies, passwords, etc EdgeDriverService svc = EdgeDriverService.CreateDefaultService(); _port = svc.Port; if (extensionPaths != null && extensionPaths.Count != 0) { var edgeOptions = new EdgeOptions(); // Create the extensionPaths capability object edgeOptions.AddAdditionalCapability("extensionPaths", extensionPaths); foreach (var path in extensionPaths) { Logger.LogWriteLine("Sideloading extension(s) from " + path); } driver = new EdgeDriver(svc, edgeOptions); } else { driver = new EdgeDriver(svc); } FileVersionInfo edgeBrowserVersion = GetEdgeFileVersion(); Logger.LogWriteLine(string.Format(" Browser Version - MicrosoftEdge File Version: {0}", edgeBrowserVersion.FileVersion)); _edgeBrowserFileVersionBuildPart = edgeBrowserVersion.FileBuildPart; string webDriverServerVersion = GetEdgeWebDriverVersion(driver); Logger.LogWriteLine(string.Format(" WebDriver Server Version - MicrosoftWebDriver.exe File Version: {0}", webDriverServerVersion)); _edgeWebDriverFileVersionBuildPart = Convert.ToInt32(webDriverServerVersion.Split('.')[2]); Thread.Sleep(2000); HttpClient client = new HttpClient(); client.DeleteAsync($"http://localhost:{svc.Port}/session/{driver.SessionId}/ms/history").Wait(); break; } ScenarioEventSourceProvider.EventLog.MaximizeBrowser(browser); driver.Manage().Window.Maximize(); Thread.Sleep(1000); return(driver); }
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); } }