예제 #1
0
 public static void ClassInit(TestContext testContext)
 {
     ProxyService.GetListProxies();
     ProxyService.CheckProxiesStatus();
 }
예제 #2
0
        public static IWebDriver CreateDriver(Browser browser)
        {
            string proxyUrl = ProxyService.GetProxyIp();
            var    proxy    = new Proxy
            {
                HttpProxy = proxyUrl,
                SslProxy  = proxyUrl,
                FtpProxy  = proxyUrl,
            };

            IWebDriver webDriver;

            switch (browser)
            {
            case Browser.Chrome:

                var chromeOptions = new ChromeOptions
                {
                    Proxy = proxy
                };
                var chromeDriverService = ChromeDriverService.CreateDefaultService(AssemblyFolder);
                webDriver = new ChromeDriver(chromeDriverService, chromeOptions);
                webDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(ConfigurationService.Instance.GetWebSettings().Chrome.PageLoadTimeout);
                webDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(ConfigurationService.Instance.GetWebSettings().Chrome.ScriptTimeout);
                break;

            case Browser.Firefox:
                var firefoxOptions = new FirefoxOptions()
                {
                    Proxy = proxy
                };
                webDriver = new FirefoxDriver(Environment.CurrentDirectory, firefoxOptions);
                webDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(ConfigurationService.Instance.GetWebSettings().Firefox.PageLoadTimeout);
                webDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(ConfigurationService.Instance.GetWebSettings().Firefox.ScriptTimeout);
                break;

            case Browser.Edge:
                var edgeOptions = new EdgeOptions()
                {
                    Proxy = proxy
                };
                webDriver = new EdgeDriver(Environment.CurrentDirectory, edgeOptions);
                webDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(ConfigurationService.Instance.GetWebSettings().Edge.PageLoadTimeout);
                webDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(ConfigurationService.Instance.GetWebSettings().Edge.ScriptTimeout);
                break;

            case Browser.InternetExplorer:
                var ieOptions = new InternetExplorerOptions()
                {
                    Proxy = proxy
                };
                webDriver = new InternetExplorerDriver(Environment.CurrentDirectory, ieOptions);
                webDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(ConfigurationService.Instance.GetWebSettings().InternetExplorer.PageLoadTimeout);
                webDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(ConfigurationService.Instance.GetWebSettings().InternetExplorer.ScriptTimeout);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(browser), browser, null);
            }

            return(webDriver);
        }