Exemplo n.º 1
0
        public IWebDriver LoadFirefoxDriver(bool headless = false)
        {
            var driverService = FirefoxDriverService.CreateDefaultService(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            try
            {
                driverService.HideCommandPromptWindow = true;
                driverService.Host = "::1";

                var options = new FirefoxOptions();
                options.AddArgument("--disable-extensions");
                options.AddArgument("--disable-popup-blocking");
                options.AddArgument("--window-size=1920,1080");
                options.AddArguments("--disable-infobars");

                if (headless == true)
                {
                    options.AddArgument("headless");
                }

                var driver = new OpenQA.Selenium.Firefox.FirefoxDriver(driverService, options);
                driver.Manage().Window.Maximize();
                return(driver);
            }
            catch (WebDriverException we)
            {
                throw new WebDriverException(we.Message);
            }
        }
Exemplo n.º 2
0
        public void OpenBrowser()
        {
            string browserType = "chrome";

            switch (browserType)
            {
            case "chrome":
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.AddArgument("--start-maximized");
                chromeOptions.AddArgument("--incognito");
                //chromeOptions.AddArgument("--headless");
                SetDriver(new ChromeDriver(@"C:\Users\ASUS\seleniumWebDriver", chromeOptions));

                break;

            case "firefox":
                FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.AddArgument("");
                firefoxOptions.AddArgument("--start-maximized");
                firefoxOptions.AddArgument("--incognito");
                //serDriver(new FirefoxOptions(@"C:\Users\ASUS\seleniumWebDriver", firefoxOptions));
                break;
                // ...... add other browsers
            }
            GetDriver().Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30); //tiempo de espera antes de que un control nos de la excepcion de que no encontro el control
            GetDriver().Manage().Timeouts().PageLoad     = TimeSpan.FromSeconds(120);
        }
        private IWebDriver BuildRemoteDriver(string browser)
        {

            var hubUri = new Uri("http://192.168.99.100:4444/wd/hub");

            switch (browser)
            {
                case "chrome":
                    var chromeOptions = new ChromeOptions();
                    chromeOptions.AddArgument("disable-gpu");
                    //chromeOptions.PlatformName = "WINDOWS";
                    chromeOptions.AddArgument("--start-maximized");
                    chromeOptions.EnableMobileEmulation("BlackBerry Z30");


                    _driver = new RemoteWebDriver(hubUri, chromeOptions);
                    break;
                case "firefox":
                    var firefoxOptions = new FirefoxOptions();
                    firefoxOptions.AddArgument("headless");
                    firefoxOptions.AddArgument("disable-gpu");
                    //firefoxOptions.PlatformName = "WINDOWS";
                    firefoxOptions.AddArgument("--start-maximized");

                    _driver = new RemoteWebDriver(hubUri, firefoxOptions);
                    break;
            }

            return _driver;
        }
        private static IWebDriver CreateFirefoxDriver(params string[] addArgument)
        {
            var options = new FirefoxOptions
            {
                BrowserVersion = "79.0",
                PlatformName   = "WINDOWS"
            };

            options.AddArgument("--start-maximized");
            if (Config.IsHeadless)
            {
                options.AddArgument("headless");
            }

            if (addArgument.Length > 0)
            {
                foreach (var argument in addArgument)
                {
                    options.AddArgument(argument);
                }
            }

            var remoteSettings = new RemoteSessionSettings(options);
            var uri            = new Uri(Config.RemoteWebDriverAddress);
            var drv            = new RemoteWebDriver(uri, remoteSettings)
            {
                FileDetector = new LocalFileDetector()
            };

            return(drv);
        }
Exemplo n.º 5
0
        private static FirefoxDriver FirefoxDriverInstance(string path, Size size, bool isHeadless)
        {
            var firefoxOptions = new FirefoxOptions();

            //firefoxOptions.AddArgument($"--window-size={size.Width},{size.Height}");
            if (size != null && size.IsEmpty == false)
            {
                firefoxOptions.AddArgument($"--width={size.Width}");
                firefoxOptions.AddArgument($"--height={size.Height}");
            }

            if (isHeadless)
            {
                firefoxOptions.AddArgument("--headless");
            }

            FirefoxProfile profile = new FirefoxProfile();

            profile.AcceptUntrustedCertificates = true;
            FirefoxOptions options = new FirefoxOptions();

            firefoxOptions.AcceptInsecureCertificates = true;
            firefoxOptions.Profile = profile;

            // Allow Encoding 437 required for ZipStorer in FirefoxDriver
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            return(new FirefoxDriver(path, firefoxOptions));
        }
Exemplo n.º 6
0
        private IWebDriver InstaciaRemoteDriver()
        {
            var hubUri = new Uri("http://localhost:4444/wd/hub");

            switch (navegador)
            {
            case "Chrome":
                var chromeOptions = new ChromeOptions();
                //chromeOptions.AddArgument("headless");
                chromeOptions.AddArgument("disable-gpu");
                chromeOptions.PlatformName = "LINUX";
                chromeOptions.AddArgument("--start-maximized");
                //chromeOptions.EnableMobileEmulation("Galaxy S5");

                _driver = new RemoteWebDriver(hubUri, chromeOptions);
                break;


            case "Firefox":
                var firefoxOptions = new FirefoxOptions();
                //firefoxOptions.AddArgument("headless");
                firefoxOptions.AddArgument("disable-gpu");
                firefoxOptions.PlatformName = "LINUX";
                firefoxOptions.AddArgument("--start-maximized");

                _driver = new RemoteWebDriver(hubUri, firefoxOptions);
                break;
            }

            return(_driver);
        }
        public void OpenBrowser()
        {
            string browserType = "Chrome";

            switch (browserType)
            {
            case "Chrome":
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.AddArgument("--start-maximized");
                chromeOptions.AddArgument("--incognito");
                SetDriver(new ChromeDriver(@"C:\SeleniumWebDrivers", chromeOptions));
                break;

            case "Firefox":
                FirefoxOptions firefoxOptions = new FirefoxOptions();
                firefoxOptions.AddArgument("--start-maximized");
                firefoxOptions.AddArgument("--incognito");
                SetDriver(new FirefoxDriver(@"C:\SeleniumWebDrivers", firefoxOptions));
                break;
                ////other browsers
            }
            //implicit timeouts
            GetDriver().Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
            GetDriver().Manage().Timeouts().PageLoad     = TimeSpan.FromSeconds(60);
        }
        // Construtor da classe.
        public DriverFactory()
        {
            FirefoxDriverService service = FirefoxDriverService.CreateDefaultService("/usr/share/applications/");

            // Faz criação de porta para abrir o browser.
            service.Port = new Random().Next(64000, 64800);

            CodePagesEncodingProvider.Instance.GetEncoding(437);
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            FirefoxOptions options = new FirefoxOptions();

            options.AddArgument("-headless");
            options.AddArgument("-safe-mode");
            options.AddArgument("-ignore-certificate-errors");
            FirefoxProfile profile = new FirefoxProfile();

            profile.AcceptUntrustedCertificates      = true;
            profile.AssumeUntrustedCertificateIssuer = false;
            options.Profile = profile;

            _driver = new FirefoxDriver(service, options);

            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
            _driver.Manage().Window.Maximize();
        }
Exemplo n.º 9
0
        //[Test]
        public void Firefox5()
        {
            FirefoxOptions options = new FirefoxOptions();

            //options.BrowserExecutableLocation = "calc.exe";
            // Start application with a debugging console. Windows only.
            options.AddArgument("-console");
            // Runs Firefox in headless mode. Available in Firefox 56+
            options.AddArgument("-headless");
            IWebDriver driver = new FirefoxDriver(options);

            //
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
            driver.Navigate().GoToUrl("https://www.google.com.ua/");
            //
            driver.FindElement(By.Name("q")).SendKeys("Cheese");
            Thread.Sleep(1000);
            //
            ITakesScreenshot takesScreenshot = driver as ITakesScreenshot;
            Screenshot       screenshot      = takesScreenshot.GetScreenshot();

            screenshot.SaveAsFile("d:/ScreenshotGoogle0.png", ScreenshotImageFormat.Png);
            //
            driver.Quit();
        }
Exemplo n.º 10
0
        private IWebDriver GetFireFoxDriver()
        {
            var options = new FirefoxOptions();

            options.AddArgument("--start-maximized");
            options.AddArgument("--ignore-certificate-errors");
            return(new FirefoxDriver(options));
        }
Exemplo n.º 11
0
        private static FirefoxOptions GetFirefoxOptions()
        {
            var option = new FirefoxOptions();

            option.AddArgument("--width=1920,height=1080");
            option.AddArgument("--headless");
            return(option);
        }
Exemplo n.º 12
0
        public object DesiredCapabilities()
        {
            FirefoxOptions options = new FirefoxOptions();

            options.AddArgument(@"--start-maximized");
            options.AddArgument(@"--incognito");
            return(options);
        }
Exemplo n.º 13
0
        public static IWebDriver GetFireFoxWithOptions()
        {
            FirefoxOptions options = new FirefoxOptions();

            options.AddArgument("start-maximized");
            options.AddArgument("incognito");

            return(new FirefoxDriver(options));
        }
Exemplo n.º 14
0
        private IWebDriver GetFireFoxDriver()
        {
            var options     = new FirefoxOptions();
            var firefoxPath = "C:/Users/cameliadorhoi/.nuget/packages/selenium.firefox.webdriver/0.24.0/driver";

            options.AddArgument("--start-maximized");
            options.AddArgument("--ignore-certificate-errors");
            return(new FirefoxDriver(firefoxPath, options));
        }
Exemplo n.º 15
0
        public override IWebDriver CreateDriver(DriverProperty driverProperty)
        {
            ParameterValidator.ValidateNotNull(driverProperty, "Driver Property");

            FirefoxOptions options = new FirefoxOptions();

            if (driverProperty.Headless)
            {
                options.AddArgument("--headless");
                options.SetPreference("intl.accept_languages", "en,en_US");
            }

            if (driverProperty.DownloadLocation != null)
            {
                options.SetPreference("browser.download.folderList", 2);
                options.SetPreference("browser.download.dir", driverProperty.DownloadLocation);
            }

            if (driverProperty.Arguments != null)
            {
                options.AddArguments(driverProperty.GetArgumentsAsArray());
            }

            if (DriverVersion == null)
            {
                lock (Instancelock)
                {
                    if (DriverVersion == null)
                    {
                        if (string.IsNullOrEmpty(driverProperty.DriverVersion))
                        {
                            DriverVersion = GetStableVersion();
                        }
                        else
                        {
                            DriverVersion = driverProperty.DriverVersion;
                        }
                    }
                }
            }

            // run in private mode
            options.AddArgument("--private");

            // Setup driver binary
            try
            {
                new WebDriverManager.DriverManager().SetUpDriver(new FirefoxConfig(), DriverVersion);
            }
            catch (Exception)
            {
                throw new Exception($"Cannot get Firefox driver version {DriverVersion}");
            }

            return(new FirefoxDriver(options));
        }
Exemplo n.º 16
0
        private static FirefoxDriver BuildFirefoxDriver()
        {
            var options = new FirefoxOptions();

            if (Constants.Headless)
            {
                options.AddArgument("-headless");
            }
            options.AddArgument("-foreground");
            return(new FirefoxDriver(FirefoxDriverService.CreateDefaultService(), options, TimeSpan.FromSeconds(Constants.NavigationTimeout)));
        }
Exemplo n.º 17
0
        public void InitializeTest()
        {
            FirefoxOptions options = new FirefoxOptions();

            options.AddArgument("--start-maximized");
            options.AddArgument("--no-sandbox");
            driver = new FirefoxDriver("C:\\Users\\ADMQA.user\\Documents\\geckodriver", options);
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
            baseURL            = "https://app.softrestaurant.com.mx";
            verificationErrors = new StringBuilder();
        }
Exemplo n.º 18
0
        public static void Initialize(
            string driverType,
            bool isPrivateMode = true,
            bool isHeadless    = false)
        {
            switch (driverType)
            {
            case "Chrome":
                var svc           = ChromeDriverService.CreateDefaultService();
                var chromeOptions = new ChromeOptions();
                if (isPrivateMode)
                {
                    chromeOptions.AddArgument("incognito");
                }
                if (isHeadless)
                {
                    chromeOptions.AddArgument("headless");
                }

                chromeOptions.AddArgument("no-sandbox");

                Instance = new ChromeDriver(svc, chromeOptions);
                break;

            case "Firefox":
                var ffsvc     = FirefoxDriverService.CreateDefaultService();
                var ffoptions = new FirefoxOptions
                {
                    AcceptInsecureCertificates = true
                };

                if (isPrivateMode)
                {
                    ffoptions.AddArgument("-private");
                }
                if (isHeadless)
                {
                    ffoptions.AddArgument("-headless");
                }

                Instance = new FirefoxDriver(ffsvc, ffoptions);
                break;

            default:
                Instance = new ChromeDriver();
                break;
            }

            Instance.Manage().Window.Maximize();
            Instance.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
        }
Exemplo n.º 19
0
        public static RemoteWebDriver initDriver(string _browser)
        {
            lock (_synclock)
            {
                try
                {
                    var proxy = "proxygol.sede.gol.com:80";
                    _driver = null;
                    switch (_browser)
                    {
                    case "Firefox":
                        FirefoxOptions fx = new FirefoxOptions();
                        Proxy          p  = new Proxy();
                        p.HttpProxy = proxy;
                        p.SslProxy  = proxy;
                        p.FtpProxy  = proxy;
                        fx.Proxy    = p;
                        fx.AddArgument("--width=1920");
                        fx.AddArgument("--height=1080");
                        _driver = new FirefoxDriver(fx);
                        break;

                    case "Chrome":
                        var options = new ChromeOptions();
                        options.AddArgument("--no-sandbox");
                        _driver = new ChromeDriver(pathchromedriver, options);
                        break;

                    default:
                        _driver = new ChromeDriver(pathchromedriver);
                        break;
                    }


                    _driver.Manage().Timeouts().PageLoad     = TimeSpan.FromSeconds(300);
                    _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
                    _driver.Manage().Window.Maximize();
                    return(_driver);
                }
                catch (Exception e)
                {
                    if (_driver != null)
                    {
                        _driver.Quit();
                        _driver.Dispose();
                    }
                    return(_driver);
                }
            }
        }
Exemplo n.º 20
0
        public static FirefoxOptions FirefoxDesiredCapabilities()
        {
            FirefoxOptions options = new FirefoxOptions();

            options.AddArgument("no-sandbox");
            return(options);
        }
Exemplo n.º 21
0
        public static IWebDriver CreateWebDriver(WebDriverEnum webDriverEnum, string urlRemoteWebDriver = null)
        {
            string path = @"WebDrivers\";

            switch (webDriverEnum)
            {
            case WebDriverEnum.Chrome:
                return(new ChromeDriver(new ChromeOptions()));

            case WebDriverEnum.HeadlessChrome:

                ChromeOptions opt = new ChromeOptions();
                opt.AddArgument("--headless");
                return(new ChromeDriver(opt));

            case WebDriverEnum.RemoteWebDriverChrome:
                var remoteWebDrive = new RemoteWebDriver(new Uri(urlRemoteWebDriver), new ChromeOptions());
                return(remoteWebDrive);

            case WebDriverEnum.Firefox:
                return(new FirefoxDriver(path, new FirefoxOptions()));

            case WebDriverEnum.HeadlessFirefox:
                var firefoxOptions = new FirefoxOptions();
                firefoxOptions.AddArgument("--headless");
                return(new FirefoxDriver(path, firefoxOptions));

            default:
                throw new Exception("Invalid WebDriverEnum.");
            }
        }
Exemplo n.º 22
0
        public static FirefoxOptions GetFirefoxOptions(bool headless = false, PlatformType platformType = PlatformType.Any, string proxy = null)
        {
            FirefoxOptions options = new FirefoxOptions
            {
                AcceptInsecureCertificates = true
            };

            if (headless)
            {
                options.AddArgument("--headless");
            }

            if (proxy != null)
            {
                options.Proxy = new Proxy()
                {
                    HttpProxy = proxy,
                    SslProxy  = proxy
                };
            }
            ;

            SetPlatform(options, platformType);
            return(options);
        }
        public ChangeEmailConfirmationSteps()
        {
            FirefoxOptions options = new FirefoxOptions();

            options.AddArgument("--headless");
            _webDriver = new FirefoxDriver(options);
        }
 private void execute_navegador(object sender, EventArgs e)
 {
     try
     {
         //Chrome
         if (rb_navegador_chorme.Checked == true)
         {
             var driverService = ChromeDriverService.CreateDefaultService();
             driverService.HideCommandPromptWindow = true;
             ChromeOptions options = new ChromeOptions();
             options.AddArgument("--start-maximized");
             driver     = new ChromeDriver(driverService, options);
             driver.Url = url;
         }
         // Firefox
         else if (rb_navegador_firefox.Checked == true)
         {
             var driverService = FirefoxDriverService.CreateDefaultService();
             driverService.HideCommandPromptWindow = true;
             FirefoxOptions options = new FirefoxOptions();
             options.AddArgument("--start-maximized");
             driver = new FirefoxDriver(driverService, options);
             //driver.Url = url;
             driver.Navigate().GoToUrl(url);
         }
         else
         {
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Tivemos algum erro ao tentar abrir o navegador de internet", "Mensagem");
         Console.WriteLine(ex);
     }
 }
Exemplo n.º 25
0
        public static IWebDriver CreateWebDriver(
            Browser browser, string pathDriver, bool headless)
        {
            IWebDriver webDriver = null;

            switch (browser)
            {
            case Browser.Firefox:
                FirefoxOptions optionsFF = new FirefoxOptions();
                if (headless)
                {
                    optionsFF.AddArgument("--headless");
                }

                webDriver = new FirefoxDriver(pathDriver, optionsFF);

                break;

            case Browser.Chrome:
                ChromeOptions options = new ChromeOptions();
                if (headless)
                {
                    options.AddArgument("--headless");
                }

                webDriver = new ChromeDriver(pathDriver, options);

                break;
            }

            return(webDriver);
        }
Exemplo n.º 26
0
        internal void SetUp()
        {
            switch (browserType)
            {
            case "Chrome":
                string chromeDriverDirectory = AppDomain.CurrentDomain.BaseDirectory;
                var    options = new ChromeOptions();
                options.AddArgument("-no-sandbox");
                driver = new ChromeDriver(chromeDriverDirectory, options, TimeSpan.FromMinutes(3));
                break;

            case "IE":
                driver = new InternetExplorerDriver();

                break;

            case "Firefox":
                string firefoxDriverDirectory = AppDomain.CurrentDomain.BaseDirectory;
                var    firefoxOptions         = new FirefoxOptions();
                firefoxOptions.AddArgument("-no-sandbox");
                driver = new FirefoxDriver(firefoxDriverDirectory, firefoxOptions, TimeSpan.FromMinutes(3));
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMinutes(3);
                break;
            }
            driver.Manage().Window.Maximize();
        }
        public PasswordResetConfirmationSteps()
        {
            FirefoxOptions options = new FirefoxOptions();

            options.AddArgument("--headless");
            _webDriver = new FirefoxDriver(options);
        }
        public void InitBrowser()
        {
            var options = new FirefoxOptions();

            options.AddArgument("--headless");
            WebDriver = new FirefoxDriver(Environment.CurrentDirectory, options);
        }
        public static IWebDriver CreateWebDriver(Browser browser, string caminhoDriver, bool headless)
        {
            IWebDriver webDriver = null;

            switch (browser)
            {
            case Browser.Firefox:
                var optionsFireFox = new FirefoxOptions();
                if (headless)
                {
                    optionsFireFox.AddArgument("--headless");
                }

                webDriver = new FirefoxDriver(caminhoDriver, optionsFireFox);

                break;

            case Browser.Chrome:
                var options = new ChromeOptions();
                if (headless)
                {
                    options.AddArgument("--headless");
                }

                webDriver = new ChromeDriver(caminhoDriver, options);

                break;
            }

            return(webDriver);
        }
Exemplo n.º 30
0
        public static IContainer BuildContainer()
        {
            var        builder   = new ContainerBuilder();
            IWebDriver webDriver = null;

#if !DEBUG
            var firefoxOptions = new FirefoxOptions();
            firefoxOptions.AddArgument("--headless");
            var driverService = FirefoxDriverService.CreateDefaultService();
            driverService.FirefoxBinaryPath       = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
            driverService.HideCommandPromptWindow = true;
            driverService.SuppressInitialDiagnosticInformation = true;
            webDriver = new FirefoxDriver(driverService, firefoxOptions, TimeSpan.FromSeconds(60));
#endif
#if DEBUG
            webDriver = new ChromeDriver(ChromeDriverService.CreateDefaultService(Environment.CurrentDirectory));
#endif

            builder.RegisterInstance(webDriver)
            .As <IWebDriver>()
            .As <IJavaScriptExecutor>()
            .SingleInstance()
            .OnRelease(firefoxDriver =>
            {
                firefoxDriver.Quit();
                firefoxDriver.Dispose();
            });
            builder.RegisterType <PageObjectFactory>();
            builder.RegisterType <TestPageObject>();

            return(builder.Build());
        }