コード例 #1
0
        private static IWebDriver GetDriver(Browsers browserName)
        {
            IWebDriver webdriver = null;

            switch (browserName)
            {
            case Browsers.Chrome:
                webdriver = new ChromeDriver();
                break;

            case Browsers.Firefox:
                webdriver = new FirefoxDriver();
                break;

            case Browsers.Opera:
                webdriver = new OperaDriver();
                break;

            default:
                webdriver = new OperaDriver();
                break;
            }
            webdriver.Manage().Window.Maximize();
            webdriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

            return(webdriver);
        }
コード例 #2
0
        private static IWebDriver GetDriver(Browsers browserName) //metodas noriu issikviesti ta browseri, kuri uzprasau, paduodu tipa browser
        {
            IWebDriver webdriver = null;                          //kintamasis

            switch (browserName)
            {
            case Browsers.Chrome:
                webdriver = new ChromeDriver();
                break;

            case Browsers.Firefox:
                webdriver = new FirefoxDriver();
                break;

            case Browsers.Opera:
                webdriver = new OperaDriver();
                break;

            default:
                webdriver = new OperaDriver();
                break;
            }
            webdriver.Manage().Window.Maximize();//bet kuris iskviestas metodas tures sias salygas
            webdriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

            return(webdriver);
        }
コード例 #3
0
        private static IWebDriver GetDriver(Browsers browserName)
        {
            IWebDriver driver = null;

            switch (browserName)
            {
            case Browsers.Chrome:
                driver = new ChromeDriver();
                break;

            case Browsers.Firefox:
                driver = new FirefoxDriver();
                break;

            case Browsers.Opera:
                driver = new OperaDriver();
                break;

            case Browsers.IncognitoChrome:
                driver = GetChromeWithOptions();
                break;
            }
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
            driver.Manage().Window.Maximize();
            return(driver);
        }
コード例 #4
0
ファイル: MyWebDriver.cs プロジェクト: 9iru4/AutoRefferal
        /// <summary>
        /// Использование оперы в качестве браузера
        /// </summary>
        public void InitializeOperaDriver()
        {
            OperaOptions options = new OperaOptions();

            options.BinaryLocation = settings.OperaPath;
            options.AddArgument("user-data-dir=" + Directory.GetCurrentDirectory() + @"\opera");
            options.AddArgument("private");
            driver = new OperaDriver(options);
            driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(40);
        }
コード例 #5
0
        private void ChooseDriverInstance(BrowserType browserType)
        {
            if (browserType == BrowserType.Chrome)
            {
                int lrg = 1920; // Longeur ICI
                int lng = 1080; // Largeur ICI

                int lngForScreenShot = lng + (Int32)127;
                int lrgForScreenShot = lrg + 37;

                ChromeOptions options = new ChromeOptions();
                //options.AddArgument("--headless");
                options.AddArgument("--window-size=" + lrg + "," + lngForScreenShot);
                //options.EnableMobileEmulation("iPhone 6 Plus");
                _driver = new ChromeDriver(@"C:/WEBDRIVER", options);
                _driver.Manage().Window.Maximize();
            }
            else if (browserType == BrowserType.Firefox)
            {
                FirefoxBinary  binary         = new FirefoxBinary(@"C:/Program Files/Mozilla Firefox/firefox.exe");
                FirefoxProfile firefoxProfile = new FirefoxProfile();
                //FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
                //service.FirefoxBinaryPath = @"C:\\Program Files\\Mozilla Firefox";
                //service.HideCommandPromptWindow = true;
                //service.SuppressInitialDiagnosticInformation = true;
                //_driver = new FirefoxDriver();
                _driver = new FirefoxDriver(binary, firefoxProfile);
                _driver.Manage().Window.Maximize();
            }
            else if (browserType == BrowserType.IE)
            {
                _driver = new InternetExplorerDriver(@"C:/WEBDRIVER");
                _driver.Manage().Window.Maximize();
            }
            else if (browserType == BrowserType.Edge)
            {
                _driver = new EdgeDriver(@"C:/WEBDRIVER");
                _driver.Manage().Window.Maximize();
            }
            else if (browserType == BrowserType.Opera)
            {
                _driver = new OperaDriver("C:/WEBDRIVER");
                _driver.Manage().Window.Maximize();
            }
            else if (browserType == BrowserType.HeadLess)
            {
                _driver = new PhantomJSDriver("C:/WEBDRIVER");
                _driver.Manage().Window.Maximize();
            }
        }
コード例 #6
0
ファイル: Insert_Special.cs プロジェクト: DefPavel/Bot
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text.Length != 0)
                {
                    using (IWebDriver Browser = new OperaDriver())
                    {
                        Browser.Manage().Window.Maximize();

                        System.Threading.Thread.Sleep(1000);

                        Browser.Navigate().GoToUrl(@"http://ltsu.ru/login/index.php");

                        Browser.FindElement(By.Id("username")).SendKeys("admin");
                        Browser.FindElement(By.Id("password")).SendKeys("ULT@015um");
                        Browser.FindElement(By.Id("loginbtn")).Click();



                        foreach (Predmet p in listP)
                        {
                            Browser.Navigate().GoToUrl(textBox1.Text);

                            System.Threading.Thread.Sleep(1000);

                            Browser.FindElement(By.CssSelector(".listing-actions.category-listing-actions a:first-child")).Click();

                            Browser.FindElement(By.Id("id_name")).SendKeys(p.namePredmet);

                            Browser.FindElement(By.Id("id_submitbutton")).Click();

                            System.Threading.Thread.Sleep(1000);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Введите URL!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #7
0
        /// <summary>
        /// Builds a web driver of the specified type.
        /// </summary>
        /// <param name="driverType">The type of browser the driver represents.</param>
        /// <returns></returns>
        public IWebDriver Build(BrowserType driverType, TestSuiteConfiguration testSuiteConfiguration)
        {
            DriverManager driverManager = new DriverManager();

            IWebDriver driver = null;

            switch (driverType)
            {
            case BrowserType.Chrome:
                driverManager.SetUpDriver(new ChromeConfig());
                driver = new ChromeDriver(new ChromeOptions());
                break;

            case BrowserType.IE:
                driverManager.SetUpDriver(new InternetExplorerConfig());
                driver = new InternetExplorerDriver(new InternetExplorerOptions());
                break;

            case BrowserType.Firefox:
                driverManager.SetUpDriver(new FirefoxConfig());
                driver = new FirefoxDriver(new FirefoxOptions());
                break;

            case BrowserType.Opera:
                driverManager.SetUpDriver(new OperaConfig());
                driver = new OperaDriver(new OperaOptions());
                break;

            default:
                break;
            }

            if (driver != null)
            {
                //This waits for the page to load.
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(testSuiteConfiguration.ElementLoadWaitTimeInSeconds);
                if (ConfigurationManager.Current.RunBrowserInFullScreenMode)
                {
                    driver.MakeFullScreen();
                }
            }

            return(driver);
        }
コード例 #8
0
ファイル: Driver.cs プロジェクト: pithas93/PobucaTests
        /// <summary>
        /// Instantiates a web driver singleton that drives the selected browser through pages
        /// </summary>
        public static void Initialize(Browser type)
        {
            switch (type)
            {
            case Browser.Chrome:
            {
                Instance = new ChromeDriver("C:/Selenium/Chrome_Driver/");
                break;
            }

            case Browser.Firefox:
            {
                Instance = new FirefoxDriver();


                break;
            }

            case Browser.IE:
            {
                var o = new InternetExplorerOptions {
                    RequireWindowFocus = true, EnablePersistentHover = false
                };
                Instance = new InternetExplorerDriver("C:/Selenium/IE_Driver/", o);
                break;
            }

            case Browser.Safari:
            {
                Instance = new SafariDriver();
                break;
            }

            case Browser.Opera:
            {
                Instance = new OperaDriver("C:/Selenium/Opera_Driver/");
                break;
            }
            }


            Instance.Manage().Window.Maximize();
            TurnOnWait();
        }
コード例 #9
0
        public static void StartBrowser(BrowserTypes browserType = BrowserTypes.Opera, int defaultTimeOut = 30)
        {
            switch (browserType)
            {
            case BrowserTypes.Opera:
                Browser = new OperaDriver();
                break;

            case BrowserTypes.InternetExplorer:
                break;

            case BrowserTypes.FireFox:
                break;

            case BrowserTypes.Chrome:
                break;

            default:
                break;
            }
            Browser.Manage().Window.Maximize();
            BrowserWait = new WebDriverWait(Browser, TimeSpan.FromSeconds(defaultTimeOut));
        }
コード例 #10
0
        static void Main(string[] args)
        {
            IWebDriver driver = new OperaDriver();

            driver.Navigate().GoToUrl("https://localhost:44346");
            driver.Manage().Window.Maximize();
            IWebElement btnsearch = driver.FindElement(By.Id("btnSignLog"));

            btnsearch.Click();

            IWebElement input = driver.FindElement(By.Id("UsernameSignLog"));

            input.SendKeys("admin");

            IWebElement input1 = driver.FindElement(By.Id("PasswordSignLog"));

            input1.SendKeys("admin");
            //"id = "PasswordSignLog

            //btnAdd
            IWebElement btnsearch1 = driver.FindElement(By.Id("btnAdd"));

            btnsearch1.Click();
        }
コード例 #11
0
        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);
        }
コード例 #12
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);
        }
コード例 #13
0
ファイル: Sinhro.cs プロジェクト: DefPavel/Bot
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                using (IWebDriver Browser = new OperaDriver())
                {
                    //Ожидание
                    // WebDriverWait wait = new WebDriverWait(Browser, TimeSpan.FromSeconds(5));

                    Browser.Manage().Window.Maximize();

                    Browser.Navigate().GoToUrl(@"http://ltsu.ru/login/index.php");
                    Browser.FindElement(By.Id("username")).SendKeys("operator-228");
                    Browser.FindElement(By.Id("password")).SendKeys("14976");
                    Browser.FindElement(By.Id("loginbtn")).Click();
                    Browser.Navigate().GoToUrl(textURL.Text);

                    System.Threading.Thread.Sleep(int.Parse(textTime.Text));

                    Browser.FindElement(By.CssSelector(".course-listing-actions div:nth-child(3) .dropdown a:first-child")).Click();

                    System.Threading.Thread.Sleep(int.Parse(textTime.Text));

                    Browser.FindElement(By.CssSelector(".dropdown-menu.dropdown-menu-right.menu.align-tr-br.show > a:nth-child(6)")).Click();
                    System.Threading.Thread.Sleep(2000);

                    List <IWebElement> items    = Browser.FindElements(By.CssSelector("#course-category-listings #course-listing .listitem .coursename")).ToList();
                    List <string>      new_item = new List <string>();

                    for (int i = 0; i < items.Count; i++)
                    {
                        new_item.Add(items[i].GetAttribute("href"));
                    }

                    for (int i = 0; i < new_item.Count; i++)
                    {
                        Browser.Navigate().GoToUrl(new_item[i].ToString());

                        // wait.Until(item => item.FindElement(By.CssSelector(".listing-actions.course-detail-listing-actions > a:nth-child(3)")).Displayed);
                        System.Threading.Thread.Sleep(1000);

                        Browser.FindElement(By.CssSelector(".listing-actions.course-detail-listing-actions > a:nth-child(3)")).Click();
                        System.Threading.Thread.Sleep(1000);
                        //папап
                        Browser.FindElement(By.CssSelector("#region-main-box .dropdown:first-child a:first-child")).Click();
                        System.Threading.Thread.Sleep(1000);

                        Browser.FindElement(By.CssSelector(".dropdown-menu.dropdown-menu-right.menu.align-tr-br.show div:nth-child(2)")).Click();

                        System.Threading.Thread.Sleep(1000);

                        Browser.FindElement(By.CssSelector(".custom-select.urlselect option:nth-child(3)")).Click();

                        System.Threading.Thread.Sleep(1000);

                        Browser.FindElement(By.Id("id_name")).SendKeys("Синхронизация с глобальной группой");

                        Browser.FindElement(By.CssSelector(".fcontainer.clearfix input:nth-child(3)")).SendKeys(textGroup.Text);

                        //Browser.FindElement()

                        System.Threading.Thread.Sleep(1000);

                        Browser.FindElement(By.CssSelector(".form-autocomplete-suggestions li:first-child")).Click();

                        Browser.FindElement(By.Id("mform1")).Submit();

                        System.Threading.Thread.Sleep(1000);

                        /* Browser.FindElement(By.CssSelector(".pull-right input")).Click();
                         * System.Threading.Thread.Sleep(2000);
                         * Browser.FindElement(By.CssSelector(".fcontainer.clearfix > #fitem_id_cohortlist > .felement > input")).SendKeys(textGroup.Text.Trim());
                         * System.Threading.Thread.Sleep(2000);
                         * Browser.FindElement(By.CssSelector(".fcontainer.clearfix > #fitem_id_cohortlist > .felement > ul > li:first-child")).Click();
                         * //Может быть Здесь еще нужно поставить Sleep
                         * Browser.FindElement(By.CssSelector(".modal-body > form")).Submit();
                         * System.Threading.Thread.Sleep(int.Parse(textTime.Text));*/
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
コード例 #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (textURL.Text.Length != 0)
                {
                    using (IWebDriver Browser = new OperaDriver())
                    {
                        string idGroup = string.Empty;

                        Browser.Manage().Window.Maximize();

                        System.Threading.Thread.Sleep(1000);

                        Browser.Navigate().GoToUrl(@"http://ltsu.ru/login/index.php");

                        Browser.FindElement(By.Id("username")).SendKeys("admin");
                        Browser.FindElement(By.Id("password")).SendKeys("ULT@015um");
                        Browser.FindElement(By.Id("loginbtn")).Click();

                        Browser.Navigate().GoToUrl(textURL.Text);

                        MatchCollection match = Regex.Matches(textURL.Text, @"(\d+)");

                        foreach (Match m in match)
                        {
                            idGroup = (m.Groups[1].ToString());
                        }

                        System.Threading.Thread.Sleep(2000);

                        Browser.Navigate().GoToUrl($"http://ltsu.ru/course/edit.php?category={idGroup}&returnto=catmanage");

                        System.Threading.Thread.Sleep(2000);

                        foreach (Predmet p in listP)
                        {
                            int random = Randoms();

                            Browser.FindElement(By.Id("id_fullname")).Clear();
                            Browser.FindElement(By.Id("id_shortname")).Clear();
                            Browser.FindElement(By.Id("id_fullname")).SendKeys(p.namePredmet);
                            if (p.namePredmet.Length < 100)
                            {
                                Browser.FindElement(By.Id("id_shortname")).SendKeys(p.namePredmet + "_" + random.ToString());
                            }
                            else
                            {
                                Browser.FindElement(By.Id("id_shortname")).SendKeys(p.namePredmet.Split(' ') + "_" + random.ToString());
                            }
                            System.Threading.Thread.Sleep(1000);
                            Browser.FindElement(By.Id("id_saveanddisplay")).Click();

                            System.Threading.Thread.Sleep(1000);
                            Browser.Navigate().Back();

                            System.Threading.Thread.Sleep(2000);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Введите URL");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #15
0
        /// <summary>
        /// Opens new browser window by browser type and sets web driver object up
        /// </summary>
        /// <param name="driver">Driver object. Will be setup at the end of the method.</param>
        /// <param name="browserType">Browser type (see <see cref="BrowserType"/>)</param>
        internal static void OpenBrowser(ref IWebDriver driver, BrowserType browserType)
        {
            if (driver != null)
            {
                CurrentDriver = driver;
                ActionManager.CloseAlert();
                return;
            }
            switch (browserType)
            {
            case BrowserType.Chrome:
            case BrowserType.ChromeIncognito:
                var chromeOptions = new ChromeOptions();
                chromeOptions.AddArguments("disable-infobars", "disable-geolocation", "disable-gpu", "no-sandbox");
                chromeOptions.AddUserProfilePreference("download.default_directory", TestConfig.BrowserDownloadFolder);
                if (browserType == BrowserType.ChromeIncognito)
                {
                    chromeOptions.AddArgument("incognito");
                }
                driver = new ChromeDriver(chromeOptions);
                break;

            case BrowserType.Firefox:
                var ffOptions = new FirefoxOptions();
                ffOptions.SetPreference("app.update.auto", false);
                ffOptions.SetPreference("app.update.enabled", false);
                ffOptions.SetPreference("app.update.silent", false);
                ffOptions.SetPreference("geo.enabled", false);
                ffOptions.SetPreference("geo.provider.use_corelocation", false);
                ffOptions.SetPreference("geo.prompt.testing", false);
                ffOptions.SetPreference("geo.prompt.testing.allow", false);
                ffOptions.SetPreference("browser.download.folderList", 2);
                ffOptions.SetPreference("browser.download.dir", TestConfig.BrowserDownloadFolder);
                ffOptions.SetPreference("browser.download.manager.showWhenStarting", false);
                ffOptions.SetPreference("browser.helperApps.neverAsk.saveToDisk", "image/jpeg");
                ffOptions.SetPreference("layers.acceleration.disabled", true);
                driver = new FirefoxDriver(ffOptions);
                break;

            // Cannot be used due to browser GUI "open file" dialog calls from CX Manager.
            // AutoItX cannot control invisible dialogs.
            //
            //case BrowserType.ChromeHeadless:
            //    chromeOptions.AddArguments("headless", "disable-gpu", "disable-infobars", "window-size=1920x1080");
            //    driver = new ChromeDriver(chromeOptions);
            //    break;
            case BrowserType.InternetExplorer:
                driver = new InternetExplorerDriver();
                break;

            case BrowserType.Edge:
                driver = new EdgeDriver();
                break;

            case BrowserType.Safari:
                driver = new SafariDriver();
                break;

            case BrowserType.Opera:
                driver = new OperaDriver();
                break;

            default:
                throw new WebDriverException("Unsupported browser type is set in TestConfig.xlsx");
            }

            driver.SwitchTo().DefaultContent();
            driver.Manage().Window.Maximize();
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(TestConfig.ImplicitWaitTimeout);
            driver.Manage().Timeouts().PageLoad     = TimeSpan.FromSeconds(TestConfig.PageLoadWaitTimeout);
            CurrentDriver = driver;
            WindowHandles.Add(AutoIt.AutoItX.WinGetHandle());
        }
コード例 #16
0
        private void button1_Click(object sender, EventArgs e)
        {
            //IWebDriver Browser = new OperaDriver();
            try
            {
                if ((textGroup.Text.Length != 0) || (textURL.Text.Length != 0))
                {
                    using (IWebDriver Browser = new OperaDriver())
                    {
                        //Ожидание
                        // WebDriverWait wait = new WebDriverWait(Browser, TimeSpan.FromSeconds(5));

                        Browser.Manage().Window.Maximize();

                        Browser.Navigate().GoToUrl(@"http://ltsu.ru/login/index.php");
                        Browser.FindElement(By.Id("username")).SendKeys("admin");
                        Browser.FindElement(By.Id("password")).SendKeys("ULT@015um");
                        Browser.FindElement(By.Id("loginbtn")).Click();
                        Browser.Navigate().GoToUrl(textURL.Text);

                        System.Threading.Thread.Sleep(int.Parse(textTime.Text));

                        Browser.FindElement(By.CssSelector(".course-listing-actions div:nth-child(3) .dropdown a:first-child")).Click();

                        System.Threading.Thread.Sleep(int.Parse(textTime.Text));

                        Browser.FindElement(By.CssSelector(".dropdown-menu.dropdown-menu-right.menu.align-tr-br.show > a:nth-child(6)")).Click();
                        System.Threading.Thread.Sleep(2000);

                        List <IWebElement> items    = Browser.FindElements(By.CssSelector("#course-category-listings #course-listing .listitem .coursename")).ToList();
                        List <string>      new_item = new List <string>();

                        for (int i = 0; i < items.Count; i++)
                        {
                            new_item.Add(items[i].GetAttribute("href"));
                        }

                        for (int i = 0; i < new_item.Count; i++)
                        {
                            Browser.Navigate().GoToUrl(new_item[i].ToString());

                            // wait.Until(item => item.FindElement(By.CssSelector(".listing-actions.course-detail-listing-actions > a:nth-child(3)")).Displayed);
                            System.Threading.Thread.Sleep(1000);

                            Browser.FindElement(By.CssSelector(".listing-actions.course-detail-listing-actions > a:nth-child(3)")).Click();
                            System.Threading.Thread.Sleep(1000);
                            //папап
                            Browser.FindElement(By.CssSelector(".pull-right input")).Click();
                            System.Threading.Thread.Sleep(2000);
                            Browser.FindElement(By.CssSelector(".fcontainer.clearfix > #fitem_id_cohortlist > .felement > input")).SendKeys(textGroup.Text.Trim());
                            System.Threading.Thread.Sleep(2000);
                            Browser.FindElement(By.CssSelector(".fcontainer.clearfix > #fitem_id_cohortlist > .felement > ul > li:first-child")).Click();
                            //Может быть Здесь еще нужно поставить Sleep
                            Browser.FindElement(By.CssSelector(".modal-body > form")).Submit();
                            System.Threading.Thread.Sleep(int.Parse(textTime.Text));
                        }
                    }
                }

                else
                {
                    MessageBox.Show("Введите текст");
                }
            }
            catch (NoSuchElementException element)
            {
                MessageBox.Show("Не найден элемент на сайте!!!!" + "\n" + element.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            // finally { Browser.Dispose(); }
        }