public IWebDriver Create(DriverType driverType)
        {
            switch (driverType)
            {
            case DriverType.Chrome:
            {
                var options = new ChromeOptions();
                options.AddArguments("--no-sandbox", "--disable-infobars", "--disable-save-password-bubble");
                return(new ChromeDriver(options));
            }

            case DriverType.Edge:
            {
                var options = new EdgeOptions
                {
                    PageLoadStrategy = PageLoadStrategy.Eager
                };
                return(new EdgeDriver(options));
            }

            case DriverType.Firefox:
            {
                var options = new FirefoxOptions
                {
                    AcceptInsecureCertificates = true
                };
                return(new FirefoxDriver(options));
            }

            case DriverType.InternetExplorer:
            {
                var options = new InternetExplorerOptions
                {
                    IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                    InitialBrowserUrl  = "about:blank",
                    EnableNativeEvents = true,
                    IgnoreZoomLevel    = true
                };
                return(new InternetExplorerDriver(options));
            }

            case DriverType.Opera:
            {
                var options = new OperaOptions();
                options.AddArguments("--no-sandbox", "--disable-infobars", "--disable-save-password-bubble");
                options.BinaryLocation = @"C:\Program Files\Opera\launcher.exe";
                return(new OperaDriver(options));
            }

            case DriverType.Phantom:
            {
                return(new PhantomJSDriver());
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(driverType), driverType, null);
            }
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        public void CreateMessage_OperaOptions_ReturnString()
        {
            var options = new OperaOptions();

            options.AddArguments(new List <string> {
                "--start-maximized", "--ignore-certificate-errors"
            });
            var str = options.CreateMessage().Replace("\n", "").Replace("\r", "").RemoveWhitespace();

            str.Should().Be(operaOptions);
        }
Esempio n. 5
0
//        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);
        }
        protected override IWebDriver DoBuildAndGetWebDriver(BrowserConfig browserConfig)
        {
            OperaDriverService operaDriverService = OperaDriverService.CreateDefaultService(browserConfig.WebDriverPath);
            OperaOptions       operaOptions       = new OperaOptions();

            operaOptions.BinaryLocation = browserConfig.WebDriverPath + "opera.exe";

            if (browserConfig.BrowserOptions != null)
            {
                operaOptions.AddArguments(browserConfig.BrowserOptions);
            }

            IWebDriver webDriver = new OperaDriver(operaDriverService, operaOptions);

            return(webDriver);
        }
Esempio n. 7
0
        /// <summary>
        /// Inicializa uma nova instância do OperaDriver
        /// </summary>
        /// <param name="folderPath">Pasta onde se encontra o Driver do Opera</param>
        /// <param name="preferences">Preferências do usuário. Opcional</param>
        /// <param name="options">Opções para configurar na inicialização do navegador. Ex: "headless"</param>
        private void OperaInstance(string folderPath, Dictionary <string, object> preferences = null, params string[] options)
        {
            if (string.IsNullOrEmpty(folderPath))
            {
                throw new ArgumentException("É necessário passar o caminho que está localizado o Driver do Browser");
            }

            OperaOptions operaOptions = new OperaOptions();

            operaOptions.AddArguments(options);

            if (preferences != null)
            {
                foreach (KeyValuePair <string, object> preference in preferences)
                {
                    operaOptions.AddUserProfilePreference(preference.Key, preference.Value);
                }
            }

            Driver = new OperaDriver(folderPath, operaOptions);
        }
Esempio n. 8
0
        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 IWebDriver GetDriver(BrowserType browserType)
        {
            IWebDriver webDriver = null;

            if (browserType == BrowserType.Chrome)
            {
                var driverOptions = new ChromeOptions();
                driverOptions.AddArguments("--proxy-server=http://ZefWDt:[email protected]:5500");
                webDriver = new ChromeDriver(driverOptions);
            }
            else if (browserType == BrowserType.Opera)
            {
                var driverOptions = new OperaOptions();
                driverOptions.AddArguments("--proxy-server=http://ZefWDt:[email protected]:5500");
                webDriver = new OperaDriver(driverOptions);
            }

            var manageOptions = webDriver.Manage();

            manageOptions.Window.Size     = new Size(1920, 1080);
            manageOptions.Window.Position = new Point(0, 0);

            return(webDriver);
        }
 public static void EnableHeadless(this OperaOptions options)
 {
     options.AddArguments("headless");
     options.AddArgument("disable-gpu");
 }
Esempio n. 11
0
 public void SetArguments(string[] arguments)
 {
     _options.AddArguments(arguments);
 }
Esempio n. 12
0
 public OperaWebDriver() : base(new OperaDriver(driverService, operaOptions, TimeSpan.FromMinutes(3)))
 {
     driverService.Port = 18406;
     operaOptions.AddArguments(new[] { "--user-data-dir=" + Path.Combine(Environment.CurrentDirectory, "WebDriverProfiles", "Opera"), "start-maximized" });
 }
Esempio n. 13
0
        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;
            }
        }
Esempio n. 14
0
        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);
            }
        }