Пример #1
0
        private static Task <IWebDriver> GetOperaDriverAsync()
        {
            var options = new OperaOptions()
            {
                AcceptInsecureCertificates = true,
                UnhandledPromptBehavior    = UnhandledPromptBehavior.Accept
            };

            var service = OperaDriverService.CreateDefaultService(
                Path.Combine(
                    Environment.CurrentDirectory,
                    "Drivers"),
                Path.Combine(
                    Environment.GetFolderPath(
                        Environment.SpecialFolder.LocalApplicationData),
                    "Programs",
                    "Opera",
                    "launcher.exe"));

            service.HostName = "127.0.0.1";

            var driver = new OperaDriver(
                service,
                options);

            return(Task.FromResult <IWebDriver>(driver));
        }
Пример #2
0
        public void Initialize()
        {
            OperaDriverService service = OperaDriverService.CreateDefaultService(@"E:/C#/Binary/Binary_Testing/"); //path to OperaDriver
            OperaOptions       options = new OperaOptions();

            options.BinaryLocation = @"C:/Program Files/Opera/launcher.exe"; //path to my Opera browser
            driver = new OperaDriver(service, options);
        }
Пример #3
0
        public IWebDriver GetDriver()
        {
            var currentDirectory = Directory.GetCurrentDirectory();
            var options          = new OperaOptions();

            options.BinaryLocation = @"C:\Program Files\Opera\launcher.exe";
            var service = OperaDriverService.CreateDefaultService($"{currentDirectory}\\drivers\\operadriver_win64\\");

            return(new OpenQA.Selenium.Opera.OperaDriver(service, options, TimeSpan.FromMinutes(3)));
        }
        private RemoteWebDriver CreateOperaWebDriver()
        {
            var operaDriverService = OperaDriverService.CreateDefaultService();

            bool hideCommandPromptWindow = !_plemionaSettings.ShowConsole;

            operaDriverService.HideCommandPromptWindow = hideCommandPromptWindow;

            var operaDriver = new OperaDriver(operaDriverService, new OperaOptions());

            return(operaDriver);
        }
Пример #5
0
        //OperaDriverPath is where the firefox driver is.
        //OperaBrowserPath is where the opera browser is installed.
        //OperaDriverName is the name of the opera driver with its' extension (ex: .exe)
        public static IWebDriver InvokeOpera(String OperaBrowserPath = @"C:\Program Files\Opera\51.0.2830.55\opera.exe",
                                             String OperaDriverPath  = @"C:\Selenium\Browsers drivers\",
                                             String OperaDriverName  = "operadriver.exe")
        {
            InbrowserObject = null;
            OperaDriverService operaDriverService =
                OperaDriverService.CreateDefaultService(OperaDriverPath, "operadriver.exe");
            OperaOptions options = new OperaOptions();

            options.BinaryLocation = (OperaBrowserPath);
            InbrowserObject        = new OperaDriver(operaDriverService, options);
            return(InbrowserObject);
        }
Пример #6
0
        public void OpenAppOpera()
        {
            OperaDriverService service = OperaDriverService.CreateDefaultService("C:\\Users\\OChernovolyk\\source\\operadriver", "operadriver.exe");
            var operaOptions           = new OperaOptions
            {
                BinaryLocation      = "C:\\Users\\OChernovolyk\\AppData\\Local\\Programs\\Opera\\62.0.3331.72\\opera.exe",
                LeaveBrowserRunning = false
            };

            driver = new OperaDriver(service, operaOptions);


            driver.Url = "https://www.google.com.ua/";
            driver.Close();
        }
Пример #7
0
        /// <summary>
        /// Sets the Opera Driver Service setting from the app.config file
        /// </summary>
        private void SetOperaDriverService()
        {
            try
            {
                int android = -1;

                int.TryParse(Opera.AndroidDebugBridgePort, out android);
                bool.TryParse(Opera.EnableVerboseLogging, out bool verbose);
                bool.TryParse(Opera.HideCommandPromptWindow, out bool hidePrompt);
                int.TryParse(Opera.Port, out int port);
                bool.TryParse(Opera.SuppressInitialDiagnosticInformation, out bool sidi);

                string operaLocation = BaseSettings.OperaDriverLocation;

                string logPath    = Opera.LogPath;
                string portServer = Opera.PortServerAddress;
                string prefix     = Opera.UrlPathPrefix;

                OperaDriverService service = OperaDriverService.CreateDefaultService(operaLocation);
                service.AndroidDebugBridgePort  = android >= 0 ? android : -1;
                service.EnableVerboseLogging    = verbose;
                service.HideCommandPromptWindow = hidePrompt;
                service.Port = port;
                service.PortServerAddress = portServer ?? null;
                service.SuppressInitialDiagnosticInformation = sidi;
                Service = service;
            }
            catch (Exception ex)
            {
                switch (BaseSettings.DebugLevel)
                {
                case EnumConsoleDebugLevel.Human:
                    Console.Out.WriteLine("Could not start the opera driver service.");
                    Console.Out.WriteLine("Please investigate the changes you have made to your config file.");
                    break;

                case EnumConsoleDebugLevel.NotSpecified:
                case EnumConsoleDebugLevel.Message:
                    Console.Out.WriteLine(ex.Message);
                    break;

                case EnumConsoleDebugLevel.StackTrace:
                    Console.Out.WriteLine(ex.Message);
                    Console.Out.WriteLine(ex.StackTrace);
                    break;
                }
            }
        }
Пример #8
0
        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);
        }
Пример #9
0
        /// <summary>
        /// Gets the capabilities for Opera
        /// </summary>
        /// <param name="_alertBehaviour"></param>
        /// <param name="acceptSlefSignedSSL"></param>
        /// <param name="_loadStrategy"></param>
        /// <returns></returns>
        private OperaOptions GetOperaBrowserOptions(UnhandledPromptBehavior _alertBehaviour = UnhandledPromptBehavior.Default,
                                                    bool acceptSlefSignedSSL       = true,
                                                    bool _leaveBrowserRunning      = false,
                                                    PageLoadStrategy _loadStrategy = PageLoadStrategy.Default)
        {
            OperaService = OperaDriverService.CreateDefaultService(Directory.GetCurrentDirectory(), @"operadriver.exe");
            OperaService.EnableVerboseLogging    = true;
            OperaService.HideCommandPromptWindow = true;
            OperaService.Start();

            return(new OperaOptions()
            {
                UnhandledPromptBehavior = _alertBehaviour,
                LeaveBrowserRunning = _leaveBrowserRunning,
                PageLoadStrategy = _loadStrategy,
                AcceptInsecureCertificates = acceptSlefSignedSSL
            });
        }
Пример #10
0
        public RemoteWebDriver CreateDriver()
        {
            var options = optionsCreator?.Invoke() ?? new OperaOptions();

            foreach (var optionsInitializer in optionsInitializers)
            {
                optionsInitializer(options);
            }

            OperaDriverService driverService = driverServiceCreator?.Invoke()
                                               ?? (driverPath != null && driverExecutableFileName != null
                    ? OperaDriverService.CreateDefaultService(driverPath, driverExecutableFileName)
                    : driverPath != null
                        ? OperaDriverService.CreateDefaultService(driverPath)
                        : OperaDriverService.CreateDefaultService());

            return(new OperaDriver(driverService, options, commandTimeout ?? TimeSpan.FromSeconds(60)));
        }
Пример #11
0
        public override IWebDriver LocalDriver(object options)
        {
            OperaDriverService driverService = null;
            IWebDriver         driver;

            try
            {
                driverService = GetDefaultService <OperaDriverService>();
                var operaOptions = options == null?OperaOptions() : (OperaOptions)options;

                driver = new OperaDriver(driverService, operaOptions, Timeout);
            }
            catch
            {
                driverService?.Dispose();
                throw;
            }
            return(driver);
        }
Пример #12
0
        public Opera()
        {
            var options = CreateOptions();

            if (BrowserSettings.Settings.IsRemoteRun())
            {
                Log.Logger().LogInformation($@"Start remote opera browser...");
                DriverProvider.CreateDriver(() => new RemoteWebDriver(new Uri(BrowserSettings.Settings.Remote.Url), options.ToCapabilities()));
                SessionId = (DriverProvider.GetDriver() as RemoteWebDriver)?.SessionId;
                Log.Logger().LogInformation($@"Remote opera browser (SessionId is {SessionId}) is starting with options: {Helpers.Message.CreateMessage(options)}");
                return;
            }
            Log.Logger().LogInformation($@"Start opera browser...");
            var service = OperaDriverService.CreateDefaultService();

            service.HideCommandPromptWindow = true;
            DriverProvider.CreateDriver(() => new OperaDriver(service, options));
            SessionId = (DriverProvider.GetDriver() as OperaDriver)?.SessionId;
            Log.Logger().LogInformation($@"Local opera browser (SessionId is {SessionId}) is starting with options: {Helpers.Message.CreateMessage(options)}");
        }
Пример #13
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);
        }
        private static IWebDriver InitializeDriverRegularMode(BrowserConfiguration executionConfiguration, OpenQA.Selenium.Proxy webDriverProxy)
        {
            IWebDriver wrappedWebDriver;

            switch (executionConfiguration.BrowserType)
            {
            case BrowserType.Chrome:
                new DriverManager().SetUpDriver(new ChromeConfig());
                var chromeDriverService = ChromeDriverService.CreateDefaultService(_driverExecutablePath);
                chromeDriverService.SuppressInitialDiagnosticInformation = true;
                chromeDriverService.EnableVerboseLogging = false;
                chromeDriverService.Port = GetFreeTcpPort();
                var chromeOptions = GetChromeOptions(executionConfiguration.ClassFullName);
                chromeOptions.AddArguments("--log-level=3");
                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    chromeOptions.Proxy = webDriverProxy;
                }

                wrappedWebDriver = new ChromeDriver(chromeDriverService, chromeOptions);
                var chromePageLoadTimeout = ConfigurationService.GetSection <WebSettings>().Chrome.PageLoadTimeout;
                wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(chromePageLoadTimeout);
                var chromeScriptTimeout = ConfigurationService.GetSection <WebSettings>().Chrome.ScriptTimeout;
                wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(chromeScriptTimeout);
                BrowserSettings = ConfigurationService.GetSection <WebSettings>().Chrome;
                break;

            case BrowserType.ChromeHeadless:
                new DriverManager().SetUpDriver(new ChromeConfig());
                var chromeHeadlessDriverService = ChromeDriverService.CreateDefaultService(_driverExecutablePath);
                chromeHeadlessDriverService.SuppressInitialDiagnosticInformation = true;
                chromeHeadlessDriverService.Port = GetFreeTcpPort();
                var chromeHeadlessOptions = GetChromeOptions(executionConfiguration.ClassFullName);
                chromeHeadlessOptions.AddArguments("--headless");
                chromeHeadlessOptions.AddArguments("--log-level=3");
                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    chromeHeadlessOptions.Proxy = webDriverProxy;
                }

                wrappedWebDriver = new ChromeDriver(chromeHeadlessDriverService, chromeHeadlessOptions);
                var chromeHeadlessPageLoadTimeout             = ConfigurationService.GetSection <WebSettings>().ChromeHeadless.PageLoadTimeout;
                wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(chromeHeadlessPageLoadTimeout);
                var chromeHeadlessScriptTimeout = ConfigurationService.GetSection <WebSettings>().ChromeHeadless.ScriptTimeout;
                wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(chromeHeadlessScriptTimeout);
                BrowserSettings = ConfigurationService.GetSection <WebSettings>().ChromeHeadless;
                break;

            case BrowserType.Firefox:
                new DriverManager().SetUpDriver(new FirefoxConfig());
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
                var firefoxOptions = GetFirefoxOptions(executionConfiguration.ClassFullName);
                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    firefoxOptions.Proxy = webDriverProxy;
                }

                var firefoxService = FirefoxDriverService.CreateDefaultService(_driverExecutablePath);
                firefoxService.SuppressInitialDiagnosticInformation = true;
                firefoxService.Port = GetFreeTcpPort();
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    if (File.Exists(@"C:\Program Files\Mozilla Firefox\firefox.exe"))
                    {
                        firefoxService.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                    }
                    else
                    {
                        firefoxService.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
                    }

                    // TODO: Anton(15.12.2019): Add option to set the path via environment variable.
                }

                var firefoxProfile = ServicesCollection.Current.Resolve <FirefoxProfile>(executionConfiguration.ClassFullName);
                if (firefoxProfile != null)
                {
                    firefoxOptions.Profile = firefoxProfile;
                }

                var firefoxTimeout = TimeSpan.FromSeconds(180);
                wrappedWebDriver = new FirefoxDriver(firefoxService, firefoxOptions, firefoxTimeout);
                var firefoxPageLoadTimeout = ConfigurationService.GetSection <WebSettings>().Firefox.PageLoadTimeout;
                wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(firefoxPageLoadTimeout);
                var firefoxScriptTimeout = ConfigurationService.GetSection <WebSettings>().Firefox.ScriptTimeout;
                wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(firefoxScriptTimeout);
                BrowserSettings = ConfigurationService.GetSection <WebSettings>().Firefox;
                break;

            case BrowserType.FirefoxHeadless:
                new DriverManager().SetUpDriver(new FirefoxConfig());
                var firefoxHeadlessOptions = GetFirefoxOptions(executionConfiguration.ClassFullName);
                firefoxHeadlessOptions.AddArguments("--headless");
                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    firefoxHeadlessOptions.Proxy = webDriverProxy;
                }

                var service = FirefoxDriverService.CreateDefaultService(_driverExecutablePath);
                service.SuppressInitialDiagnosticInformation = true;
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    if (File.Exists(@"C:\Program Files\Mozilla Firefox\firefox.exe"))
                    {
                        service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                    }
                    else
                    {
                        service.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
                    }

                    // TODO: Anton(15.12.2019): Add option to set the path via environment variable.
                }

                service.Port     = GetFreeTcpPort();
                wrappedWebDriver = new FirefoxDriver(service, firefoxHeadlessOptions);
                var firefoxHeadlessPageLoadTimeout            = ConfigurationService.GetSection <WebSettings>().FirefoxHeadless.PageLoadTimeout;
                wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(firefoxHeadlessPageLoadTimeout);
                var firefoxHeadlessScriptTimeout = ConfigurationService.GetSection <WebSettings>().FirefoxHeadless.ScriptTimeout;
                wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(firefoxHeadlessScriptTimeout);
                BrowserSettings = ConfigurationService.GetSection <WebSettings>().FirefoxHeadless;
                break;

            case BrowserType.Edge:
                new DriverManager().SetUpDriver(new EdgeConfig());
                var edgeDriverService = Microsoft.Edge.SeleniumTools.EdgeDriverService.CreateChromiumService(_driverExecutablePath);
                edgeDriverService.SuppressInitialDiagnosticInformation = true;
                var edgeOptions = GetEdgeOptions(executionConfiguration.ClassFullName);
                edgeOptions.PageLoadStrategy = PageLoadStrategy.Normal;
                edgeOptions.UseChromium      = true;
                edgeOptions.AddArguments("--log-level=3");
                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    edgeOptions.Proxy = webDriverProxy;
                }

                wrappedWebDriver = new Microsoft.Edge.SeleniumTools.EdgeDriver(edgeDriverService, edgeOptions);
                var edgePageLoadTimeout = ConfigurationService.GetSection <WebSettings>().Edge.PageLoadTimeout;
                wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(edgePageLoadTimeout);
                var edgeScriptTimeout = ConfigurationService.GetSection <WebSettings>().Edge.ScriptTimeout;
                wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(edgeScriptTimeout);
                BrowserSettings = ConfigurationService.GetSection <WebSettings>().Edge;
                break;

            case BrowserType.EdgeHeadless:
                new DriverManager().SetUpDriver(new EdgeConfig());
                var edgeHeadlessDriverService = Microsoft.Edge.SeleniumTools.EdgeDriverService.CreateChromiumService(_driverExecutablePath);
                edgeHeadlessDriverService.SuppressInitialDiagnosticInformation = true;
                var edgeHeadlessOptions = GetEdgeOptions(executionConfiguration.ClassFullName);
                edgeHeadlessOptions.AddArguments("--headless");
                edgeHeadlessOptions.AddArguments("--log-level=3");
                edgeHeadlessOptions.PageLoadStrategy = PageLoadStrategy.Normal;
                edgeHeadlessOptions.UseChromium      = true;
                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    edgeHeadlessOptions.Proxy = webDriverProxy;
                }

                wrappedWebDriver = new Microsoft.Edge.SeleniumTools.EdgeDriver(edgeHeadlessDriverService, edgeHeadlessOptions);
                var edgeHeadlessPageLoadTimeout = ConfigurationService.GetSection <WebSettings>().Edge.PageLoadTimeout;
                wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(edgeHeadlessPageLoadTimeout);
                var edgeHeadlessScriptTimeout = ConfigurationService.GetSection <WebSettings>().Edge.ScriptTimeout;
                wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(edgeHeadlessScriptTimeout);
                BrowserSettings = ConfigurationService.GetSection <WebSettings>().Edge;
                break;

            case BrowserType.Opera:
                new DriverManager().SetUpDriver(new OperaConfig());

                // the driver will be different for different OS.
                // Check for different releases- https://github.com/operasoftware/operachromiumdriver/releases
                var operaOptions = GetOperaOptions(executionConfiguration.ClassFullName);

                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    operaOptions.Proxy = webDriverProxy;
                }

                var operaService = OperaDriverService.CreateDefaultService(_driverExecutablePath);
                operaService.SuppressInitialDiagnosticInformation = true;
                operaService.Port = GetFreeTcpPort();

                try
                {
                    wrappedWebDriver = new OperaDriver(operaService, operaOptions);
                }
                catch (WebDriverException ex) when(ex.Message.Contains("DevToolsActivePort file doesn't exist"))
                {
                    throw new Exception("This is a known issue in the latest versions of Opera driver. It is reported to the Opera team. As soon it is fixed we will update BELLATRIX.", ex);
                }

                var operaPageLoadTimeout = ConfigurationService.GetSection <WebSettings>().Opera.PageLoadTimeout;
                wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(operaPageLoadTimeout);
                var operaScriptTimeout = ConfigurationService.GetSection <WebSettings>().Opera.ScriptTimeout;
                wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(operaScriptTimeout);
                BrowserSettings = ConfigurationService.GetSection <WebSettings>().Opera;
                break;

            case BrowserType.InternetExplorer:
                new DriverManager().SetUpDriver(new InternetExplorerConfig());

                // Steps to configure IE to always allow blocked content:
                // From Internet Explorer, select the Tools menu, then the Options...
                // In the Internet Options dialog, select the Advanced tab...
                // Scroll down until you see the Security options. Enable the checkbox "Allow active content to run in files on My Computer"
                // Also, check https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration
                // in case of OpenQA.Selenium.NoSuchWindowException: Unable to get browser --> Uncheck IE Options --> Security Tab -> Uncheck "Enable Protected Mode"
                var ieOptions = GetInternetExplorerOptions(executionConfiguration.ClassFullName);
                ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                ieOptions.IgnoreZoomLevel      = true;
                ieOptions.EnableNativeEvents   = false;
                ieOptions.EnsureCleanSession   = true;
                ieOptions.PageLoadStrategy     = PageLoadStrategy.Eager;
                ieOptions.ForceShellWindowsApi = true;
                ieOptions.AddAdditionalCapability("disable-popup-blocking", true);

                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    ieOptions.Proxy = webDriverProxy;
                }

                wrappedWebDriver = new InternetExplorerDriver(_driverExecutablePath, ieOptions);

                var iePageLoadTimeout = ConfigurationService.GetSection <WebSettings>().InternetExplorer.PageLoadTimeout;
                wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(iePageLoadTimeout);
                var ieScriptTimeout = ConfigurationService.GetSection <WebSettings>().InternetExplorer.ScriptTimeout;
                wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(ieScriptTimeout);
                BrowserSettings = ConfigurationService.GetSection <WebSettings>().InternetExplorer;
                break;

            case BrowserType.Safari:
                var safariOptions = GetSafariOptions(executionConfiguration.ClassFullName);

                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    safariOptions.Proxy = webDriverProxy;
                }

                wrappedWebDriver = new SafariDriver(safariOptions);

                var safariPageLoadTimeout = ConfigurationService.GetSection <WebSettings>().Safari.PageLoadTimeout;
                wrappedWebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(safariPageLoadTimeout);
                var safariScriptTimeout = ConfigurationService.GetSection <WebSettings>().Safari.ScriptTimeout;
                wrappedWebDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(safariScriptTimeout);
                BrowserSettings = ConfigurationService.GetSection <WebSettings>().Safari;
                break;

            default:
                throw new NotSupportedException($"Not supported browser {executionConfiguration.BrowserType}");
            }

            return(wrappedWebDriver);
        }
Пример #15
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);
            }
        }
        private static IWebDriver InitializeDriverRegularMode(BrowserConfiguration executionConfiguration, OpenQA.Selenium.Proxy webDriverProxy)
        {
            IWebDriver wrappedWebDriver;

            switch (executionConfiguration.BrowserType)
            {
            case BrowserType.Chrome:
                new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);
                var chromeDriverService = ChromeDriverService.CreateDefaultService();
                chromeDriverService.SuppressInitialDiagnosticInformation = true;
                chromeDriverService.EnableVerboseLogging = false;
                var chromeOptions = executionConfiguration.DriverOptions;
                chromeOptions.AddArguments("--log-level=3");
                Port = GetFreeTcpPort();
                chromeDriverService.Port = Port;
                DebuggerPort             = GetFreeTcpPort();

                if (executionConfiguration.IsLighthouseEnabled)
                {
                    chromeOptions.AddArgument("--remote-debugging-address=0.0.0.0");
                    chromeOptions.AddArgument($"--remote-debugging-port={DebuggerPort}");
                    ////ProcessProvider.StartCLIProcess($"chrome-debug --port={Port}");
                    ////chromeOptions.DebuggerAddress = $"127.0.0.1:{Port}";
                }

                if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath != null)
                {
                    string packedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath.NormalizeAppPath();
                    Logger.LogInformation($"Trying to load packed extension from path: {packedExtensionPath}");
                    chromeOptions.AddExtension(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath);
                }

                if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath != null)
                {
                    string unpackedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath.NormalizeAppPath();
                    Logger.LogInformation($"Trying to load unpacked extension from path: {unpackedExtensionPath}");
                    chromeOptions.AddArguments($"load-extension={unpackedExtensionPath}");
                }

                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled && !executionConfiguration.IsLighthouseEnabled)
                {
                    chromeOptions.Proxy = webDriverProxy;
                }

                chromeOptions.AddArgument("hide-scrollbars");
                chromeOptions.SetLoggingPreference(LogType.Browser, LogLevel.All);
                chromeOptions.SetLoggingPreference("performance", LogLevel.All);

                wrappedWebDriver = new ChromeDriver(chromeDriverService, chromeOptions);
                break;

            case BrowserType.ChromeHeadless:
                new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);
                var chromeHeadlessDriverService = ChromeDriverService.CreateDefaultService();
                chromeHeadlessDriverService.SuppressInitialDiagnosticInformation = true;
                Port = GetFreeTcpPort();
                chromeHeadlessDriverService.Port = Port;
                var chromeHeadlessOptions = executionConfiguration.DriverOptions;
                chromeHeadlessOptions.AddArguments("--headless");
                chromeHeadlessOptions.AddArguments("--log-level=3");

                chromeHeadlessOptions.AddArguments("--test-type");
                chromeHeadlessOptions.AddArguments("--disable-infobars");
                chromeHeadlessOptions.AddArguments("--allow-no-sandbox-job");
                chromeHeadlessOptions.AddArguments("--ignore-certificate-errors");
                chromeHeadlessOptions.AddArguments("--disable-gpu");
                chromeHeadlessOptions.AddArguments("--no-sandbox");
                chromeHeadlessOptions.AddUserProfilePreference("credentials_enable_service", false);
                chromeHeadlessOptions.AddUserProfilePreference("profile.password_manager_enabled", false);
                chromeHeadlessOptions.AddArgument("hide-scrollbars");
                chromeHeadlessOptions.UnhandledPromptBehavior = UnhandledPromptBehavior.Dismiss;

                Port = GetFreeTcpPort();
                chromeHeadlessDriverService.Port = Port;
                DebuggerPort = GetFreeTcpPort();

                if (executionConfiguration.IsLighthouseEnabled)
                {
                    chromeHeadlessOptions.AddArgument("--remote-debugging-address=0.0.0.0");
                    chromeHeadlessOptions.AddArgument($"--remote-debugging-port={DebuggerPort}");
                }

                if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath != null)
                {
                    string packedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath.NormalizeAppPath();
                    Logger.LogInformation($"Trying to load packed extension from path: {packedExtensionPath}");
                    chromeHeadlessOptions.AddExtension(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath);
                }

                if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath != null)
                {
                    string unpackedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath.NormalizeAppPath();
                    Logger.LogInformation($"Trying to load unpacked extension from path: {unpackedExtensionPath}");
                    chromeHeadlessOptions.AddArguments($"load-extension={unpackedExtensionPath}");
                }

                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    chromeHeadlessOptions.Proxy = webDriverProxy;
                }

                chromeHeadlessOptions.SetLoggingPreference(LogType.Browser, LogLevel.All);
                chromeHeadlessOptions.SetLoggingPreference("performance", LogLevel.All);

                wrappedWebDriver = new ChromeDriver(chromeHeadlessDriverService, chromeHeadlessOptions);
                break;

            case BrowserType.Firefox:
                new DriverManager().SetUpDriver(new FirefoxConfig(), VersionResolveStrategy.Latest);
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
                var firefoxOptions = executionConfiguration.DriverOptions;
                firefoxOptions.AddAdditionalOption("acceptInsecureCerts", true);
                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    firefoxOptions.Proxy = webDriverProxy;
                }

                var firefoxService = FirefoxDriverService.CreateDefaultService();
                firefoxService.SuppressInitialDiagnosticInformation = true;
                firefoxService.Port = GetFreeTcpPort();
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    if (File.Exists(@"C:\Program Files\Mozilla Firefox\firefox.exe"))
                    {
                        firefoxService.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                    }
                    else
                    {
                        firefoxService.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
                    }

                    // TODO: Anton(15.12.2019): Add option to set the path via environment variable.
                }

                var firefoxProfile = ServicesCollection.Current.Resolve <FirefoxProfile>(executionConfiguration.ClassFullName);
                if (firefoxProfile == null)
                {
                    firefoxOptions.Profile = new FirefoxProfile(_driverExecutablePath);
                    ServicesCollection.Current.RegisterInstance(firefoxOptions.Profile, executionConfiguration.ClassFullName);
                }

                if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath != null)
                {
                    Logger.LogError($"Packed Extension loading not supported in Firefox!");

                    // 05-Nov-2020 navramov: Extension loading does not work
                    ////string packedExtensionPath = ConfigurationService.GetSection<WebSettings>().Firefox.PackedExtensionPath.NormalizeAppPath();
                    ////Logger.LogInformation($"Trying to load packed extension from path: {packedExtensionPath}");
                    ////firefoxOptions.Profile.AddExtension(ConfigurationService.GetSection<WebSettings>().Firefox.PackedExtensionPath);
                }

                if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath != null)
                {
                    Logger.LogError($"Unpacked Extension loading not supported in Firefox!");
                }

                var firefoxTimeout = TimeSpan.FromSeconds(180);
                wrappedWebDriver = new FirefoxDriver(firefoxService, firefoxOptions, firefoxTimeout);
                break;

            case BrowserType.FirefoxHeadless:
                new DriverManager().SetUpDriver(new FirefoxConfig());
                var firefoxHeadlessOptions = executionConfiguration.DriverOptions;
                firefoxHeadlessOptions.AddArguments("--headless");
                firefoxHeadlessOptions.AddAdditionalOption("acceptInsecureCerts", true);
                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    firefoxHeadlessOptions.Proxy = webDriverProxy;
                }

                if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath != null)
                {
                    string packedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath.NormalizeAppPath();
                    Logger.LogInformation($"Trying to load packed extension from path: {packedExtensionPath}");
                    firefoxHeadlessOptions.Profile.AddExtension(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath);
                }

                if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath != null)
                {
                    Logger.LogError($"Unpacked Extension loading not supported in Firefox!");
                }

                var service = FirefoxDriverService.CreateDefaultService();
                service.SuppressInitialDiagnosticInformation = true;
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    if (File.Exists(@"C:\Program Files\Mozilla Firefox\firefox.exe"))
                    {
                        service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                    }
                    else
                    {
                        service.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
                    }

                    // TODO: Anton(15.12.2019): Add option to set the path via environment variable.
                }

                service.Port     = GetFreeTcpPort();
                wrappedWebDriver = new FirefoxDriver(service, firefoxHeadlessOptions);
                break;

            case BrowserType.Edge:
                new DriverManager().SetUpDriver(new EdgeConfig());
                var edgeDriverService = Microsoft.Edge.SeleniumTools.EdgeDriverService.CreateChromiumService();
                edgeDriverService.SuppressInitialDiagnosticInformation = true;
                var edgeOptions = executionConfiguration.DriverOptions;
                edgeOptions.PageLoadStrategy = PageLoadStrategy.Normal;
                edgeOptions.UseChromium      = true;
                edgeOptions.AddArguments("--log-level=3");
                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    edgeOptions.Proxy = webDriverProxy;
                }

                if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath != null)
                {
                    string packedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath.NormalizeAppPath();
                    Logger.LogInformation($"Trying to load packed extension from path: {packedExtensionPath}");
                    edgeOptions.AddExtension(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath);
                }

                if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath != null)
                {
                    string unpackedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath.NormalizeAppPath();
                    Logger.LogInformation($"Trying to load unpacked extension from path: {unpackedExtensionPath}");
                    edgeOptions.AddArguments($"load-extension={unpackedExtensionPath}");
                }

                edgeOptions.SetLoggingPreference(LogType.Browser, LogLevel.Severe);
                edgeOptions.SetLoggingPreference("performance", LogLevel.All);


                wrappedWebDriver = new Microsoft.Edge.SeleniumTools.EdgeDriver(edgeDriverService, edgeOptions);
                break;

            case BrowserType.EdgeHeadless:
                new DriverManager().SetUpDriver(new EdgeConfig());
                var edgeHeadlessDriverService = Microsoft.Edge.SeleniumTools.EdgeDriverService.CreateChromiumService();
                edgeHeadlessDriverService.SuppressInitialDiagnosticInformation = true;
                var edgeHeadlessOptions = executionConfiguration.DriverOptions;
                edgeHeadlessOptions.AddArguments("--headless");
                edgeHeadlessOptions.AddArguments("--log-level=3");

                edgeHeadlessOptions.AddArguments("--test-type");
                edgeHeadlessOptions.AddArguments("--disable-infobars");
                edgeHeadlessOptions.AddArguments("--allow-no-sandbox-job");
                edgeHeadlessOptions.AddArguments("--ignore-certificate-errors");
                edgeHeadlessOptions.AddArguments("--disable-gpu");
                edgeHeadlessOptions.AddArguments("--no-sandbox");
                edgeHeadlessOptions.AddUserProfilePreference("credentials_enable_service", false);
                edgeHeadlessOptions.AddUserProfilePreference("profile.password_manager_enabled", false);
                edgeHeadlessOptions.AddArgument("hide-scrollbars");
                edgeHeadlessOptions.UnhandledPromptBehavior = UnhandledPromptBehavior.Dismiss;

                edgeHeadlessOptions.PageLoadStrategy = PageLoadStrategy.Normal;
                edgeHeadlessOptions.UseChromium      = true;
                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    edgeHeadlessOptions.Proxy = webDriverProxy;
                }

                if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath != null)
                {
                    string packedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath.NormalizeAppPath();
                    Logger.LogInformation($"Trying to load packed extension from path: {packedExtensionPath}");
                    edgeHeadlessOptions.AddExtension(ConfigurationService.GetSection <WebSettings>().ExecutionSettings.PackedExtensionPath);
                }

                if (ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath != null)
                {
                    string unpackedExtensionPath = ConfigurationService.GetSection <WebSettings>().ExecutionSettings.UnpackedExtensionPath.NormalizeAppPath();
                    Logger.LogInformation($"Trying to load unpacked extension from path: {unpackedExtensionPath}");
                    edgeHeadlessOptions.AddExtensionPath(unpackedExtensionPath);
                }

                edgeHeadlessOptions.SetLoggingPreference(LogType.Browser, LogLevel.Severe);
                edgeHeadlessOptions.SetLoggingPreference("performance", LogLevel.All);

                wrappedWebDriver = new Microsoft.Edge.SeleniumTools.EdgeDriver(edgeHeadlessDriverService, edgeHeadlessOptions);
                break;

            case BrowserType.Opera:
                new DriverManager().SetUpDriver(new OperaConfig());

                // the driver will be different for different OS.
                // Check for different releases- https://github.com/operasoftware/operachromiumdriver/releases
                var operaOptions = executionConfiguration.DriverOptions;

                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    operaOptions.Proxy = webDriverProxy;
                }

                var operaService = OperaDriverService.CreateDefaultService();
                operaService.SuppressInitialDiagnosticInformation = true;
                operaService.Port = GetFreeTcpPort();

                try
                {
                    wrappedWebDriver = new OperaDriver(operaService, operaOptions);
                }
                catch (WebDriverException ex) when(ex.Message.Contains("DevToolsActivePort file doesn't exist"))
                {
                    throw new Exception("This is a known issue in the latest versions of Opera driver. It is reported to the Opera team. As soon it is fixed we will update BELLATRIX.", ex);
                }

                break;

            case BrowserType.InternetExplorer:
                new DriverManager().SetUpDriver(new InternetExplorerConfig());

                // Steps to configure IE to always allow blocked content:
                // From Internet Explorer, select the Tools menu, then the Options...
                // In the Internet Options dialog, select the Advanced tab...
                // Scroll down until you see the Security options. Enable the checkbox "Allow active content to run in files on My Computer"
                // Also, check https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration
                // in case of OpenQA.Selenium.NoSuchWindowException: Unable to get browser --> Uncheck IE Options --> Security Tab -> Uncheck "Enable Protected Mode"
                var ieOptions = executionConfiguration.DriverOptions;
                ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                ieOptions.IgnoreZoomLevel      = true;
                ieOptions.EnableNativeEvents   = false;
                ieOptions.EnsureCleanSession   = true;
                ieOptions.PageLoadStrategy     = PageLoadStrategy.Eager;
                ieOptions.ForceShellWindowsApi = true;
                ieOptions.AddAdditionalCapability("disable-popup-blocking", true);

                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    ieOptions.Proxy = webDriverProxy;
                }

                wrappedWebDriver = new InternetExplorerDriver(_driverExecutablePath, ieOptions);
                break;

            case BrowserType.Safari:
                var safariOptions = executionConfiguration.DriverOptions;

                if (executionConfiguration.ShouldCaptureHttpTraffic && _proxyService.IsEnabled)
                {
                    safariOptions.Proxy = webDriverProxy;
                }

                wrappedWebDriver = new SafariDriver(safariOptions);
                break;

            default:
                throw new NotSupportedException($"Not supported browser {executionConfiguration.BrowserType}");
            }

            return(wrappedWebDriver);
        }
Пример #17
0
        public static IWebDriver BuildAndGetWebDriver(Browsers browser, IList <string> options)
        {
            IWebDriver webDriver;

            switch (browser)
            {
            case Browsers.EXPLORER:
                webDriver = new InternetExplorerDriver(_webDriversPath);
                break;

            case Browsers.FIREFOX:
                FirefoxOptions       FirefoxOptions       = new FirefoxOptions();
                FirefoxDriverService FirefoxDriverService = FirefoxDriverService.CreateDefaultService(_webDriversPath);
                FirefoxOptions.BrowserExecutableLocation = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                TimeSpan TimeSpan = new TimeSpan(1, 0, 0);

                webDriver = new FirefoxDriver(FirefoxDriverService, FirefoxOptions, TimeSpan);

                break;

            case Browsers.CHROME:

                if (options != null)
                {
                    ChromeOptions crhomeOptions = new ChromeOptions();

                    foreach (string option in options)
                    {
                        crhomeOptions.AddArgument(option);
                    }

                    webDriver = new ChromeDriver(_webDriversPath, crhomeOptions);
                }
                else
                {
                    webDriver = new ChromeDriver(_webDriversPath);
                }

                break;

            case Browsers.EDGE:
                webDriver = new EdgeDriver(_webDriversPath);
                break;

            case Browsers.OPERA:
                OperaDriverService OperaDriverService = OperaDriverService.CreateDefaultService(_webDriversPath);
                OperaOptions       OperaOptions       = new OperaOptions();
                OperaOptions.BinaryLocation = @"C:\Program Files\Opera\54.0.2952.71\opera.exe";

                webDriver = new OperaDriver(OperaDriverService, OperaOptions);

                break;

            default:
                throw new Exception();
            }

            webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(_milisecondsToWait);
            webDriver.Manage().Timeouts().PageLoad     = TimeSpan.FromMilliseconds(int.MaxValue);

            return(webDriver);
        }
        /// <summary>
        /// Initialize the web driver that the user has selected in the settings screen
        /// </summary>
        private void InitializeWebDriver()
        {
            switch (SettingsManager.Settings.ScraperWebDriver)
            {
            case "Chrome":
                var pathChrome = Path.Combine(SettingsManager.Settings.WebDriversPath, "chromedriver.exe");
                if (File.Exists(pathChrome))
                {
                    // Environment.SetEnvironmentVariable("webdriver.chrome.driver", pathChrome);

                    var chromeDriverService = ChromeDriverService.CreateDefaultService(SettingsManager.Settings.WebDriversPath);
                    chromeDriverService.HideCommandPromptWindow = true;

                    var chromeOptions = new ChromeOptions();
                    chromeOptions.AddArgument("--start-maximized");

                    Driver = new ChromeDriver(chromeDriverService, chromeOptions);
                }
                break;

            case "Headless Chrome":
                var pathChrome2 = Path.Combine(SettingsManager.Settings.WebDriversPath, "chromedriver.exe");
                if (File.Exists(pathChrome2))
                {
                    // Environment.SetEnvironmentVariable("webdriver.chrome.driver", pathChrome2);

                    var chromeDriverService = ChromeDriverService.CreateDefaultService(SettingsManager.Settings.WebDriversPath);
                    chromeDriverService.HideCommandPromptWindow = true;

                    var chromeOptions = new ChromeOptions();
                    chromeOptions.AddArgument("--headless");
                    chromeOptions.AddArgument("--start-maximized");

                    Driver = new ChromeDriver(chromeDriverService, chromeOptions);
                }
                break;

            case "Firefox":
                var pathFirefox = Path.Combine(SettingsManager.Settings.WebDriversPath, "geckodriver.exe");
                if (File.Exists(pathFirefox))
                {
                    // Environment.SetEnvironmentVariable("webdriver.gecko.driver", pathFirefox);

                    var firefoxDriverService = FirefoxDriverService.CreateDefaultService(SettingsManager.Settings.WebDriversPath);
                    firefoxDriverService.HideCommandPromptWindow = true;
                    firefoxDriverService.FirefoxBinaryPath       = pathFirefox;

                    Driver = new FirefoxDriver(firefoxDriverService);
                }
                break;

            case "Internet Explorer":
                var pathIE = Path.Combine(SettingsManager.Settings.WebDriversPath, "IEDriverServer.exe");
                if (File.Exists(pathIE))
                {
                    var ieDriverService = InternetExplorerDriverService.CreateDefaultService(SettingsManager.Settings.WebDriversPath);
                    ieDriverService.HideCommandPromptWindow = true;

                    Driver = new InternetExplorerDriver(ieDriverService);
                }
                break;

            case "Edge":
                var pathEdge = Path.Combine(SettingsManager.Settings.WebDriversPath, "MicrosoftWebDriver.exe");
                if (File.Exists(pathEdge))
                {
                    var edgeDriverService = EdgeDriverService.CreateDefaultService(SettingsManager.Settings.WebDriversPath);
                    edgeDriverService.HideCommandPromptWindow = true;

                    Driver = new EdgeDriver(edgeDriverService);
                }
                break;

            case "Opera":
                var pathOpera = Path.Combine(SettingsManager.Settings.WebDriversPath, "operadriver.exe");
                if (File.Exists(pathOpera))
                {
                    var operaDriverService = OperaDriverService.CreateDefaultService(SettingsManager.Settings.WebDriversPath);
                    operaDriverService.HideCommandPromptWindow = true;

                    var operaOptions = new OperaOptions();
                    operaOptions.BinaryLocation = pathOpera;

                    Driver = new OperaDriver(operaDriverService, operaOptions);
                }
                break;

            default:
                break;
            }
        }
Пример #19
0
        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));
        }