Example #1
0
        static void Main(string[] args)
        {
            // -browser [chrome] [firefox]
            BrowserTypeEnum browser = BrowserTypeEnum.Chrome;

            Logger.Instance.LogMessage(Constants.AppStarted);

            if (args != null && args.Any())
            {
                var browserName = args[1].Trim();
                if (!string.IsNullOrWhiteSpace(browserName) && browserName.ToLower() == Browsers.Firefox)
                {
                    browser = BrowserTypeEnum.Firefox;
                }
            }

            Logger.Instance.LogMessage(string.Format(Constants.CurrentBrowser, Enum.GetName(typeof(BrowserTypeEnum), browser)));

            string username = string.Empty;

            using (var scrapper = new MeshimerScrapper(browser))
            {
                Thread.Sleep(1500);
                Logger.Instance.LogMessage(Constants.BrowserOpened);
                username = scrapper.GetUserNameFromMeshimerPageAndHandle(UsernameMismatchHandler);
                var logMessage = string.Format(Constants.UserNameFromMeshimerPage, username);

                Logger.Instance.LogMessage(logMessage);

                System.Console.Clear();
                System.Console.WriteLine(logMessage);
            }
        }
Example #2
0
        public void SetBrowserWindowSize(BrowserTypeEnum browserTypeEnum)
        {
            var browserKey = browserTypeEnum + "WindowSize";
            var value      = ConfigurationManager.AppSettings[browserKey];

            if (value != null && value.Contains('x'))
            {
                var size = value.Split('x');
                Driver.Manage().Window.Position = new Point(0, 0);
                Driver.Manage().Window.Size = new Size(int.Parse(size[0]), int.Parse(size[1]));
            }
        }
Example #3
0
        public Selenium(string baseUrl, BrowserTypeEnum browserType)
        {
            BaseUrl     = baseUrl;
            BrowserType = browserType;
            switch (browserType)
            {
            case BrowserTypeEnum.Firefox:
                Driver = new FirefoxDriver();
                break;

            case BrowserTypeEnum.Chrome:
                Driver = new ChromeDriver();
                break;

            case BrowserTypeEnum.InternetExplorer:
                Driver = new InternetExplorerDriver();
                break;

            case BrowserTypeEnum.Edge:
                Driver = new EdgeDriver();
                break;

            case BrowserTypeEnum.Opera:
                Driver = new OperaDriver();
                break;

            //case BrowserTypeEnum.PhantomJS:
            //	Driver = new PhantomJSDriver();
            //	break;
            //case BrowserTypeEnum.RemoteWebDriver:
            //	ICapabilities capabilities = DesiredCapabilities.PhantomJS();
            //	Driver = new RemoteWebDriver(capabilities);
            //	break;
            case BrowserTypeEnum.Safari:
                Driver = new SafariDriver();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(browserType), browserType, null);
            }
            var implicitWait = ConfigurationManager.AppSettings["ImplicitWaitMilliseconds"];

            SetBrowserWindowSize(browserType);
            int result;
            var wait = TimeSpan.Zero;

            if (int.TryParse(implicitWait, out result))
            {
                wait = TimeSpan.FromMilliseconds(result);
            }
            SetImplicitWait(wait);
        }
Example #4
0
        public static bool CheckBrowserEnabled(BrowserTypeEnum browserTypeEnum)
        {
            var appSettings = ConfigurationManager.AppSettings;

            foreach (var s in appSettings.AllKeys)
            {
                if (s.ToLowerInvariant().Contains($"{browserTypeEnum}{BrowserEnabledSuffix}".ToLowerInvariant()) && (IsNullOrEmpty(appSettings[s]) || appSettings[s].ToLowerInvariant().Contains("true")))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #5
0
        public static IWebDriver GetWebDriver(BrowserTypeEnum browserType)
        {
            switch (browserType)
            {
            case BrowserTypeEnum.Firefox: return(new FirefoxDriver());

            case BrowserTypeEnum.Chrome: return(new ChromeDriver());

            case BrowserTypeEnum.Ie: return(new InternetExplorerDriver());
            }

            return(new ChromeDriver());
        }
Example #6
0
        void InitializeWebDriver(BrowserTypeEnum browserType)
        {
            switch (browserType)
            {
            case BrowserTypeEnum.Chrome:
                InitializeChromeDriverOptions();
                _webDriver = new ChromeDriver(_chromeOptions);
                break;

            case BrowserTypeEnum.Firefox:
                InitializeFirefoxDriverOptions();
                _webDriver = new FirefoxDriver(_fireFoxOptions);
                break;

            default:
                InitializeIEDriverOptions();
                _webDriver = new InternetExplorerDriver(_explorerOptions);
                break;
            }
        }
        public WebBrowserModel(BrowserTypeEnum browserType)
        {
            try
            {
                Type = browserType;
                switch (browserType)
                {
                case BrowserTypeEnum.Chrome:
                    WebDriver = new ChromeDriver(DriverLocation);
                    break;

                case BrowserTypeEnum.Edge:
                    WebDriver = new EdgeDriver(DriverLocation);
                    break;

                case BrowserTypeEnum.InternetExplorer:
                    WebDriver = new InternetExplorerDriver(DriverLocation);
                    break;

                case BrowserTypeEnum.Firefox:
                    WebDriver = new FirefoxDriver(DriverLocation);
                    break;

                case BrowserTypeEnum.Safari:
                    WebDriver = new SafariDriver(DriverLocation);
                    break;

                case BrowserTypeEnum.Opera:
                    WebDriver = new OperaDriver(DriverLocation);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(browserType), browserType, "Browser not listed");
                }
            }
            catch
            {
                Console.WriteLine("Driver not in specified location");
                throw;
            }
        }
Example #8
0
        private static IWebDriver GetBrowserDriver(BrowserTypeEnum browserType, bool isJenkinsEnvironment = false)
        {
            IWebDriver driver = null;

            //BasicAuth = new BasicAuthWebDriverWrapper();
            //BasicAuthSettings.BrowserType = BrowserType.IE;
            //BasicAuthSettings.Domain = "ads";
            //BasicAuthSettings.Username = "******";
            //BasicAuthSettings.Password = "******";

            switch (browserType)
            {
            case BrowserTypeEnum.Chrome:
                if (!isJenkinsEnvironment)
                {
                    DesiredCapabilities capabilities  = DesiredCapabilities.Chrome();
                    ChromeOptions       chromeOptions = new ChromeOptions();
                    chromeOptions.AddArguments("test-type");
                    capabilities.SetCapability(ChromeOptions.Capability, chromeOptions);
                    driver = new ChromeDriver(chromeOptions);
                }
                else
                {
                    DesiredCapabilities desiredCapabilites = new DesiredCapabilities(EnvironmentVariableByKey("SELENIUM_BROWSER"),
                                                                                     EnvironmentVariableByKey("SELENIUM_VERSION"), OpenQA.Selenium.Platform.CurrentPlatform); // set the desired browser

                    desiredCapabilites.SetCapability("username", EnvironmentVariableByKey("SAUCE_USER_NAME"));                                                                // supply sauce labs username
                    desiredCapabilites.SetCapability("accessKey", EnvironmentVariableByKey("SAUCE_API_KEY"));                                                                 // supply sauce labs account key

                    desiredCapabilites.SetCapability("name", JobName);                                                                                                        // Job Name

                    //System.Diagnostics.Debug.WriteLineIf(!String.IsNullOrEmpty(GenericCSTFunctionalities.EnvironmentVariableByKey("SELENIUM_HOST")), "SELENIUM_HOST: " + GenericCSTFunctionalities.EnvironmentVariableByKey("SELENIUM_HOST"));
                    //System.Diagnostics.Debug.WriteLineIf(!String.IsNullOrEmpty(GenericCSTFunctionalities.EnvironmentVariableByKey("SELENIUM_PORT")), "SELENIUM_PORT: " + GenericCSTFunctionalities.EnvironmentVariableByKey("SELENIUM_PORT"));
                    //System.Diagnostics.Debug.WriteLineIf(!String.IsNullOrEmpty(GenericCSTFunctionalities.EnvironmentVariableByKey("SELENIUM_PLATFORM")), "SELENIUM_PLATFORM: " + GenericCSTFunctionalities.EnvironmentVariableByKey("SELENIUM_PLATFORM"));
                    //System.Diagnostics.Debug.WriteLineIf(!String.IsNullOrEmpty(GenericCSTFunctionalities.EnvironmentVariableByKey("SELENIUM_VERSION")), "SELENIUM_VERSION: " + GenericCSTFunctionalities.EnvironmentVariableByKey("SELENIUM_VERSION"));
                    //System.Diagnostics.Debug.WriteLineIf(!String.IsNullOrEmpty(GenericCSTFunctionalities.EnvironmentVariableByKey("SELENIUM_BROWSER")), "SELENIUM_BROWSER: " + GenericCSTFunctionalities.EnvironmentVariableByKey("SELENIUM_BROWSER"));
                    ////System.Diagnostics.Debug.WriteLineIf (!String.IsNullOrEmpty(GenericCSTFunctionalities.EnvironmentVariableByKey ("SELENIUM_DEVICE")),"SELENIUM_DEVICE: " + GenericCSTFunctionalities.EnvironmentVariableByKey ("SELENIUM_DEVICE"));
                    ////System.Diagnostics.Debug.WriteLineIf (!String.IsNullOrEmpty(GenericCSTFunctionalities.EnvironmentVariableByKey ("SELENIUM_DEVICE_TYPE")),"SELENIUM_DEVICE_TYPE: " + GenericCSTFunctionalities.EnvironmentVariableByKey ("SELENIUM_DEVICE_TYPE"));
                    ////System.Diagnostics.Debug.WriteLineIf (!String.IsNullOrEmpty(GenericCSTFunctionalities.EnvironmentVariableByKey ("SELENIUM_DRIVER")),"SELENIUM_DRIVER: " + GenericCSTFunctionalities.EnvironmentVariableByKey ("SELENIUM_DRIVER"));
                    //System.Diagnostics.Debug.WriteLineIf(!String.IsNullOrEmpty(GenericCSTFunctionalities.EnvironmentVariableByKey("SAUCE_ONDEMAND_BROWSERS")), "SAUCE_ONDEMAND_BROWSERS: " + GenericCSTFunctionalities.EnvironmentVariableByKey("SAUCE_ONDEMAND_BROWSERS"));
                    ////System.Diagnostics.Debug.WriteLineIf (!String.IsNullOrEmpty(GenericCSTFunctionalities.EnvironmentVariableByKey ("SELENIUM_URL")),"SELENIUM_URL: " + GenericCSTFunctionalities.EnvironmentVariableByKey ("SELENIUM_URL"));
                    //System.Diagnostics.Debug.WriteLineIf(!String.IsNullOrEmpty(GenericCSTFunctionalities.EnvironmentVariableByKey("SAUCE_USER_NAME")), "SAUCE_USER_NAME: " + GenericCSTFunctionalities.EnvironmentVariableByKey("SAUCE_USER_NAME"));
                    //System.Diagnostics.Debug.WriteLineIf(!String.IsNullOrEmpty(GenericCSTFunctionalities.EnvironmentVariableByKey("SAUCE_API_KEY")), "SAUCE_API_KEY: " + GenericCSTFunctionalities.EnvironmentVariableByKey("SAUCE_API_KEY"));
                    //System.Diagnostics.Debug.WriteLineIf(!String.IsNullOrEmpty(GenericCSTFunctionalities.EnvironmentVariableByKey("SELENIUM_STARTING_URL")), "SELENIUM_STARTING_URL: " + GenericCSTFunctionalities.EnvironmentVariableByKey("SELENIUM_STARTING_URL"));
                    //System.Diagnostics.Debug.WriteLineIf(!String.IsNullOrEmpty(GenericCSTFunctionalities.EnvironmentVariableByKey("APP_USERNAME")), "APP_USERNAME: "******"APP_USERNAME"));
                    //System.Diagnostics.Debug.WriteLineIf(!String.IsNullOrEmpty(GenericCSTFunctionalities.EnvironmentVariableByKey("APP_PASSWORD")), "APP_PASSWORD: IS NOT NULL");


                    string strURI = String.Format("http://{0}:{1}@{2}", EnvironmentVariableByKey("SAUCE_USER_NAME"),
                                                  EnvironmentVariableByKey("SAUCE_API_KEY"), EnvironmentVariableByKey("SELENIUM_STARTING_URL"));
                    System.Diagnostics.Debug.WriteLine("URI:   " + strURI);


                    Uri commandExecutorUri = new Uri(strURI);

                    driver = new RemoteWebDriver(commandExecutorUri, desiredCapabilites);
                    driver.Manage().Window.Maximize();
                }
                break;

            case BrowserTypeEnum.Firefox:
                driver = new FirefoxDriver()
                {
                };

                throw new Exception("Driver not ready yet");
                break;

            case BrowserTypeEnum.InternetExplorer:
                if (!isJenkinsEnvironment)
                {
                    var options = new InternetExplorerOptions
                    {
                        IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                        IgnoreZoomLevel         = true,
                        UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Ignore,
                    };

                    driver = new InternetExplorerDriver(options);
                    //driver = (InternetExplorerDriver) BasicAuth.AuthenticatedDriver;
                }
                else
                {
                    var desiredCapabilities = DesiredCapabilities.InternetExplorer();
                    driver = new RemoteWebDriver(new Uri(Convert.ToString(ConfigurationManager.AppSettings["RemoteWebDriverURL"])),
                                                 desiredCapabilities);
                }

                break;
            }

            //            driver.Manage().Window.Maximize();

            return(driver ?? null);
        }
Example #9
0
 public Selenium(string baseUrl, BrowserTypeEnum browserType, TimeSpan implicitWait) : this(baseUrl, browserType)
 {
     SetImplicitWait(implicitWait);
 }
Example #10
0
 public MeshimerScrapper(BrowserTypeEnum browserType = BrowserTypeEnum.Chrome)
 {
     _browserType = browserType;
     InitializeWebDriver(_browserType);
 }