Пример #1
0
        public static IWebDriver CreateInstance(BrowserType browserType, string hubUrl)
        {
            IWebDriver driver   = null;
            TimeSpan   timeSpan = new TimeSpan(0, 3, 0);

            switch (browserType)
            {
            case BrowserType.Chrome:
                ChromeOptions chromeOptions = new ChromeOptions();
                driver = GetWebDriver(hubUrl, chromeOptions.ToCapabilities());
                break;

            case BrowserType.Edge:
                EdgeOptions options = new EdgeOptions();
                driver = GetWebDriver(hubUrl, options.ToCapabilities());
                break;

            case BrowserType.Firefox:
                FirefoxOptions firefoxOptions = new FirefoxOptions();
                driver = GetWebDriver(hubUrl, firefoxOptions.ToCapabilities());
                break;

            case BrowserType.Opera:
                OperaOptions operaOptions = new OperaOptions();
                driver = GetWebDriver(hubUrl, operaOptions.ToCapabilities());
                break;
            }

            return(driver);
        }
Пример #2
0
        public void AbrirInstancia()
        {
            string navegador = ConfigurationManager.AppSettings["NavegadorDefault"].ToString();
            string nodeURL   = ConfigurationManager.AppSettings["IpHub"].ToString();
            string local     = ConfigurationManager.AppSettings["Local"].ToString();

            if (driver == null)
            {
                if (local.Equals("true"))
                {
                    ChromeOptions chrome = new ChromeOptions();
                    chrome.AddArgument("enable-automation");
                    chrome.AddArgument("--no-sandbox");
                    chrome.AddArgument("--disable-infobars");
                    chrome.AddArgument("--disable-dev-shm-usage");
                    chrome.AddArgument("--disable-browser-side-navigation");
                    chrome.AddArgument("--disable-gpu");
                    chrome.AddArgument("--window-size=1920,1080");
                    chrome.AddArgument("--lang=pt-BR");
                    chrome.PageLoadStrategy = PageLoadStrategy.Normal;
                    driver = new ChromeDriver(chrome);
                    //driver.Manage().Window.Maximize();
                }
                else
                {
                    switch (navegador)
                    {
                    case ("firefox"):
                        FirefoxOptions firefox = new FirefoxOptions();
                        driver = new RemoteWebDriver(new Uri(nodeURL), firefox.ToCapabilities());
                        driver.Manage().Window.Maximize();
                        break;

                    case ("chrome"):
                        ChromeOptions chrome = new ChromeOptions();
                        driver = new RemoteWebDriver(new Uri(nodeURL), chrome.ToCapabilities());
                        driver.Manage().Window.Maximize();
                        break;

                    case ("opera"):
                        OperaOptions opera = new OperaOptions();
                        opera.BinaryLocation = "@" + ConfigurationManager.AppSettings["PatchOperaExe"].ToString();;
                        driver = new RemoteWebDriver(new Uri(nodeURL), opera.ToCapabilities());
                        driver.Manage().Window.Maximize();
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }
                driver.Navigate().GoToUrl(ConfigurationManager.AppSettings["URL"].ToString());
            }
        }
Пример #3
0
        public static void CreateInstance()
        {
            //criado um appconfig com a configuração desejada
            string navegador = ConfigurationManager.AppSettings["NavegadorDefault"].ToString();
            string local     = ConfigurationManager.AppSettings["Local"].ToString();
            string hubURL    = ConfigurationManager.AppSettings["Hublink"].ToString();

            if (INSTANCE == null)
            {
                switch (local)
                {
                case ("true"):     //Execução Local
                    ChromeOptions chromeOptions = new ChromeOptions();
                    INSTANCE = new ChromeDriver(chromeOptions);
                    INSTANCE.Manage().Window.Maximize();
                    break;

                case ("false"):     //Execução Grid
                    switch (navegador)
                    {
                    case ("firefox"):
                        FirefoxOptions firefox = new FirefoxOptions();
                        INSTANCE = new RemoteWebDriver(new Uri(hubURL), firefox.ToCapabilities());
                        INSTANCE.Manage().Window.Maximize();
                        break;

                    case ("chrome"):
                        ChromeOptions chrome = new ChromeOptions();
                        INSTANCE = new RemoteWebDriver(new Uri(hubURL), chrome.ToCapabilities());
                        INSTANCE.Manage().Window.Maximize();
                        break;

                    case ("opera"):
                        OperaOptions opera = new OperaOptions();
                        opera.BinaryLocation = "@" + ConfigurationManager.AppSettings["PathOperaExe"].ToString();
                        INSTANCE             = new RemoteWebDriver(new Uri(hubURL), opera.ToCapabilities());
                        INSTANCE.Manage().Window.Maximize();
                        break;

                    case ("edge"):
                        EdgeOptions edge = new EdgeOptions();
                        INSTANCE = new RemoteWebDriver(new Uri(hubURL), edge.ToCapabilities());
                        INSTANCE.Manage().Window.Maximize();
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                    break;
                }
            }
        }
Пример #4
0
        private static IWebDriver CreateDesktopWebDriver()
        {
            DesiredCapabilities capabilities;

            var browser = Config.Settings.BrowserStackSettings.BsBrowser;

            switch (browser)
            {
            case "Chrome":
                var chromeOptions = new ChromeOptions();
                chromeOptions.AddArguments("--disable-popup-blocking");
                capabilities = chromeOptions.ToCapabilities() as DesiredCapabilities;
                SetCapabilities(capabilities, "Chrome");
                return(CreateRemoteWebDriver(capabilities));

            case "Firefox":
                FirefoxOptions firefoxOptions = new FirefoxOptions();
                capabilities = firefoxOptions.ToCapabilities() as DesiredCapabilities;
                SetCapabilities(capabilities, "Firefox");
                return(CreateRemoteWebDriver(capabilities));

            case "IE":
                InternetExplorerOptions ieOptions = new InternetExplorerOptions();
                capabilities = ieOptions.ToCapabilities() as DesiredCapabilities;
                capabilities.SetCapability("browserstack.ie.enablePopups", "true");
                SetCapabilities(capabilities, "IE");
                return(CreateRemoteWebDriver(capabilities));

            case "Edge":
                var edgeOptions = new EdgeOptions();
                edgeOptions.PageLoadStrategy = PageLoadStrategy.Eager;
                capabilities = edgeOptions.ToCapabilities() as DesiredCapabilities;
                SetCapabilities(capabilities, "Edge");
                return(CreateRemoteWebDriver(capabilities));

            case "Safari":
                SafariOptions safariOptions = new SafariOptions();
                capabilities = safariOptions.ToCapabilities() as DesiredCapabilities;
                capabilities.SetCapability("browserstack.safari.enablePopups", "true");
                SetCapabilities(capabilities, "Safari");
                return(CreateRemoteWebDriver(capabilities));

            case "Opera":
                OperaOptions operaOptions = new OperaOptions();
                capabilities = operaOptions.ToCapabilities() as DesiredCapabilities;
                SetCapabilities(capabilities, "Opera");
                return(CreateRemoteWebDriver(capabilities));

            default:
                throw new ArgumentOutOfRangeException("'Browser' value: " + browser);
            }
        }
Пример #5
0
        public static void Remote(string navegador)
        {
            string Iphub = ConfigurationManager.AppSettings["IpHub"].ToString();

            switch (navegador)
            {
            case ("firefox"):
                FirefoxOptions firefox = new FirefoxOptions();
                firefox.SetPreference("intl.accept_languages", "pt-BR");
                firefox.AddArgument("-width");
                firefox.AddArgument("1920");
                firefox.AddArgument("-height");
                firefox.AddArgument("1080");

                INSTANCE = new RemoteWebDriver(new Uri(Iphub), firefox.ToCapabilities());
                //INSTANCE.Manage().Window.Maximize();
                break;

            case ("chrome"):
                ChromeOptions chrome = new ChromeOptions();
                chrome.AddArgument("no-sandbox");
                chrome.AddArguments("headless");
                chrome.AddArgument("--allow-running-insecure-content");
                chrome.AddArgument("--lang=pt-BR");
                chrome.AddArgument("--window-size=1920,1080");

                INSTANCE = new RemoteWebDriver(new Uri(Iphub), chrome.ToCapabilities());
                //INSTANCE.Manage().Window.Maximize();
                break;

            case ("ie"):
                InternetExplorerOptions ie = new InternetExplorerOptions();
                INSTANCE = new RemoteWebDriver(new Uri(Iphub), ie.ToCapabilities());
                //INSTANCE.Manage().Window.Maximize();
                break;

            case ("opera"):
                OperaOptions opera = new OperaOptions();
                opera.BinaryLocation = "/usr/bin/opera";
                INSTANCE             = new RemoteWebDriver(new Uri(Iphub), opera.ToCapabilities());
                INSTANCE.Manage().Window.Maximize();
                break;

            default:
                throw new NotImplementedException();
            }
        } //fim void
Пример #6
0
        public void SetUp()
        {
            String IndicadorGrid = ConfigurationManager.AppSettings["IndicadorGrid"].ToString();


            if (IndicadorGrid == "N")
            {
                driver = new ChromeDriver(@"C:\");
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60);
                driver.Manage().Timeouts().PageLoad     = TimeSpan.FromSeconds(60);
                driver.Navigate().GoToUrl("http://testlink.claudinei.base2.com.br/login.php");
                driver.Manage().Window.Maximize();
            }
            else
            {
                string navegador = ConfigurationManager.AppSettings["NavegadorDefault"].ToString();
                string nodeURL   = ConfigurationManager.AppSettings["IpHub"].ToString();

                switch (navegador)
                {
                case ("firefox"):
                    FirefoxOptions firefox = new FirefoxOptions();
                    driver = new RemoteWebDriver(new Uri(nodeURL), firefox.ToCapabilities());
                    break;

                case ("chrome"):
                    ChromeOptions chrome = new ChromeOptions();
                    driver = new RemoteWebDriver(new Uri(nodeURL), chrome.ToCapabilities());
                    break;

                case ("opera"):
                    OperaOptions opera = new OperaOptions();
                    opera.BinaryLocation = "@" + ConfigurationManager.AppSettings["OperaLocal"].ToString();

                    driver = new RemoteWebDriver(new Uri(nodeURL), opera.ToCapabilities());
                    break;
                }

                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60);
                driver.Manage().Timeouts().PageLoad     = TimeSpan.FromSeconds(60);
                driver.Navigate().GoToUrl("http://testlink.claudinei.base2.com.br/login.php");
                driver.Manage().Window.Maximize();
            }
        }
Пример #7
0
        public static void CreateInstance()
        {
            string browser     = ConfigurationManager.AppSettings["browser"].ToString();
            string execution   = ConfigurationManager.AppSettings["execution"].ToString();
            string seleniumHub = ConfigurationManager.AppSettings["seleniumHub"].ToString();

            if (INSTANCE == null)
            {
                switch (browser)
                {
                case "chrome":
                    if (execution.Equals("local"))
                    {
                        ChromeOptions chrome = new ChromeOptions();
                        chrome.AddArgument("start-maximized");
                        chrome.AddArgument("--window-size=1920,1080");
                        chrome.AddArgument("enable-automation");
                        chrome.AddArgument("--no-sandbox");
                        chrome.AddArgument("--disable-infobars");
                        chrome.AddArgument("--disable-dev-shm-usage");
                        chrome.AddArgument("--disable-browser-side-navigation");
                        chrome.AddArgument("--disable-gpu");
                        chrome.AddArgument("--headless");
                        chrome.PageLoadStrategy = PageLoadStrategy.Normal;
                        INSTANCE = new ChromeDriver(chrome);
                    }

                    if (execution.Equals("remota"))
                    {
                        ChromeOptions chrome = new ChromeOptions();
                        chrome.AddArgument("no-sandbox");
                        chrome.AddArgument("--allow-running-insecure-content");
                        chrome.AddArgument("--lang=pt-BR");
                        chrome.AddArgument("--window-size=1920,1080");
                        //chrome.AddArgument("maxInstances=5");

                        INSTANCE = new RemoteWebDriver(new Uri(seleniumHub), chrome.ToCapabilities());
                    }

                    break;

                case "ie":
                    if (execution.Equals("local"))
                    {
                        #region implement capabilities
                        //new line code
                        //DesiredCapabilities ie = new DesiredCapabilities();

                        //DesiredCapabilities capabilities = DesiredCapabilities.InternetExplorerOptions();
                        //InternetExplorerOptions ieOptions = new InternetExplorerOptions();

                        //capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);

                        //ie.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
                        //ieOptions.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, true);
                        //ieOptions.EnableNativeEvents("requireWindowFocus", true);

                        //desiredcapabilities capabilities = new desiredcapabilities().;
                        //desiredcapabilities capabilities = new desiredcapabilities.internetexploreroptions();

                        //capabilities.SetCapability("requireWindowFocus", true);
                        //capabilities.SetCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, false);
                        //capabilities.SetCapability("ie.ensureCleanSession", true);
                        //capabilities.SetCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
                        //capabilities.SetCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);
                        #endregion

                        //exist line in projt
                        INSTANCE = new InternetExplorerDriver();
                    }

                    if (execution.Equals("remota"))
                    {
                        InternetExplorerOptions ie = new InternetExplorerOptions();
                        INSTANCE = new RemoteWebDriver(new Uri(seleniumHub), ie.ToCapabilities());
                    }

                    break;

                case "firefox":
                    if (execution.Equals("local"))
                    {
                        INSTANCE = new FirefoxDriver();
                    }

                    if (execution.Equals("remota"))
                    {
                        FirefoxOptions firefox = new FirefoxOptions();
                        firefox.SetPreference("intl.accept_languages", "pt-BR");
                        INSTANCE = new RemoteWebDriver(new Uri(seleniumHub), firefox.ToCapabilities());
                    }

                    break;

                case "edge":
                    if (execution.Equals("local"))
                    {
                        INSTANCE = new EdgeDriver();
                    }

                    if (execution.Equals("remota"))
                    {
                        EdgeOptions edge = new EdgeOptions();
                        INSTANCE = new RemoteWebDriver(new Uri(seleniumHub), edge.ToCapabilities());
                    }

                    break;

                case "opera":
                    if (execution.Equals("local"))
                    {
                        INSTANCE = new OperaDriver();
                    }

                    if (execution.Equals("remota"))
                    {
                        OperaOptions opera = new OperaOptions();
                        INSTANCE = new RemoteWebDriver(new Uri(seleniumHub), opera.ToCapabilities());
                    }

                    break;

                default:
                    throw new Exception("O browser informado não existe ou não é suportado pela automação");
                }
            }
        }
        public IBrowserDriver Create(BrowserNames browserName)
        {
            var mode = (configuration?.WebDriver?.Mode ?? "").ToEnum <Modes>();

            Log.Info($"Browser mode:{mode}");
            switch (mode)
            {
            case Modes.browser:
                var isRemote = configuration?.WebDriver?.Browser?.IsRemote ?? false;
                Log.Info($"WebDriver.IsRemote = {isRemote}");
                if (isRemote)
                {
                    switch (browserName)
                    {
                    case BrowserNames.chrome:
                    {
                        ChromeOptions chromeOptions = BuildChromeOptions();
                        return(CreateRemoteWebDriver(chromeOptions.ToCapabilities()));
                    }

                    case BrowserNames.firefox:
                    {
                        FirefoxOptions firefoxOptions = BuildFirefoxOptions();
                        return(CreateRemoteWebDriver(firefoxOptions.ToCapabilities()));
                    }

                    case BrowserNames.opera:
                    {
                        OperaOptions operaOptions = BuildOperaOptions();
                        return(CreateRemoteWebDriver(operaOptions.ToCapabilities()));
                    }

                    case BrowserNames.safari:
                    {
                        SafariOptions safariOptions = BuildSafariOptions();
                        return(CreateRemoteWebDriver(safariOptions.ToCapabilities()));
                    }

                    case BrowserNames.ie:
                    {
                        InternetExplorerOptions ieOptions = BuildInternetExplorerOptions();
                        return(CreateRemoteWebDriver(ieOptions.ToCapabilities()));
                    }

                    case BrowserNames.edge:
                    {
                        EdgeOptions edgeOptions = BuildEdgeOptions();
                        return(CreateRemoteWebDriver(edgeOptions.ToCapabilities()));
                    }

                    default:
                        throw new ArgumentOutOfRangeException($"SpecDrill: Value Not Supported `{browserName}`!");
                    }
                }
                return(driverFactory[browserName]());

            case Modes.appium:

                AppiumOptions appiumOptions          = new AppiumOptions();
                var           configuredCapabilities = configuration?.WebDriver?.Appium?.Capabilities;
                ExtendCapabilities(appiumOptions, configuredCapabilities);

                IWebDriver   driver;
                const string PLATFORM_NAME = "platformName";
                EnsureCapabilityIsConfigured(configuredCapabilities, PLATFORM_NAME);
                var appiumServerUri = configuration?.WebDriver?.Appium?.ServerUri ?? "";
                switch (configuredCapabilities ![PLATFORM_NAME].ToString().ToEnum <PlatformNames>())