Provides a way to access Internet Explorer to run your tests by creating a InternetExplorerDriver instance
When the WebDriver object has been instantiated the browser will load. The test can then navigate to the URL under test and start your test.
Inheritance: IWebDriver, ISearchContext, IJavaScriptExecutor, ITakesScreenshot
Exemplo n.º 1
1
        /// <summary>
        /// Launches the Selenium WebDriver driven browser specified in the Environments.cs file
        /// </summary>
        public IWebDriver LaunchBrowser(IWebDriver driver)
        {
            switch(this.environment.browser)
            {
                case "*firefox":
                    _ffp = new FirefoxProfile();
                    _ffp.AcceptUntrustedCertificates = true;
                    driver = new FirefoxDriver(_ffp);
                    break;
                case "*iexplore":
                    driver = new InternetExplorerDriver();
                    break;
                case "*googlechrome":
                    driver = new ChromeDriver();
                    break;
                case "Android":
                    capabilities = new DesiredCapabilities("android", "", null);
                    capabilities.IsJavaScriptEnabled = true;
                    driver = new RemoteWebDriver(new Uri(string.Format("http://{0}:{1}/hub", environment.host, environment.port)), capabilities);
                    break;
                case "RemoteWebDriver":
                    capabilities = DesiredCapabilities.Firefox();
                    var remoteAddress = new Uri(string.Format("http://{0}:{1}/wd/hub", environment.host, environment.port));
                    driver = new RemoteWebDriver(remoteAddress, capabilities);
                    break;
            }

            return driver;
        }
 public static IWebDriver GetDriver(string driver, Devices device)
 {
     DeviceModel model = Device.Get(device);
     IWebDriver webDriver;
     switch (driver.ToLower())
     {
         case "safari":
             webDriver = new SafariDriver();
             break;
         case "chrome":
             webDriver = new ChromeDriver();
             break;
         case "ie":
             webDriver = new InternetExplorerDriver();
             break;
         //case "firefox":
         default:
             var profile = new FirefoxProfile();
             profile.SetPreference("general.useragent.override", model.UserAgent);
             webDriver = new FirefoxDriver(profile);
             webDriver.Manage().Window.Size = model.ScreenSize;
             break;
     }
     return webDriver;
 }
Exemplo n.º 3
1
        /// <summary>
        /// Creates the web driver.
        /// </summary>
        /// <param name="browserType">Type of the browser.</param>
        /// <param name="browserFactoryConfiguration">The browser factory configuration.</param>
        /// <returns>The created web driver.</returns>
        /// <exception cref="System.InvalidOperationException">Thrown if the browser is not supported.</exception>
        internal static IWebDriver CreateWebDriver(BrowserType browserType, BrowserFactoryConfigurationElement browserFactoryConfiguration)
        {
            IWebDriver driver;
            if (!RemoteDriverExists(browserFactoryConfiguration.Settings, browserType, out driver))
            {
                switch (browserType)
                {
                    case BrowserType.IE:
                        var explorerOptions = new InternetExplorerOptions { EnsureCleanSession = browserFactoryConfiguration.EnsureCleanSession };
                        var internetExplorerDriverService = InternetExplorerDriverService.CreateDefaultService();
                        internetExplorerDriverService.HideCommandPromptWindow = true;
                        driver = new InternetExplorerDriver(internetExplorerDriverService, explorerOptions);
                        break;
                    case BrowserType.FireFox:
                        driver = GetFireFoxDriver(browserFactoryConfiguration);
                        break;
                    case BrowserType.Chrome:
                        var chromeOptions = new ChromeOptions { LeaveBrowserRunning = false };
                        var chromeDriverService = ChromeDriverService.CreateDefaultService();
                        chromeDriverService.HideCommandPromptWindow = true;

                        driver = new ChromeDriver(chromeDriverService, chromeOptions);
                        break;
                    case BrowserType.PhantomJS:
                        var phantomJsDriverService = PhantomJSDriverService.CreateDefaultService();
                        phantomJsDriverService.HideCommandPromptWindow = true;
                        driver = new PhantomJSDriver(phantomJsDriverService);
                        break;
                    case BrowserType.Safari:
                        driver = new SafariDriver();
                        break;
                    default:
                        throw new InvalidOperationException(string.Format("Browser type '{0}' is not supported in Selenium local mode. Did you mean to configure a remote driver?", browserType));
                }
            }

            // Set Driver Settings
            var managementSettings = driver.Manage();
           
            // Set timeouts

			var applicationConfiguration = SpecBind.Helpers.SettingHelper.GetConfigurationSection().Application;

            managementSettings.Timeouts()
                .ImplicitlyWait(browserFactoryConfiguration.ElementLocateTimeout)
                .SetPageLoadTimeout(browserFactoryConfiguration.PageLoadTimeout);

			ActionBase.DefaultTimeout = browserFactoryConfiguration.ElementLocateTimeout;
            WaitForPageAction.DefaultTimeout = browserFactoryConfiguration.PageLoadTimeout;
			ActionBase.RetryValidationUntilTimeout = applicationConfiguration.RetryValidationUntilTimeout;

            // Maximize window
            managementSettings.Window.Maximize();

            return driver;
        }
        public void logging_in_with_invalid_credentials()
        {
            var capabilities = new DesiredCapabilities();
            capabilities.SetCapability(InternetExplorerDriver.IntroduceInstabilityByIgnoringProtectedModeSettings, true);

            var driver = new InternetExplorerDriver(capabilities);
            driver.Navigate().GoToUrl(TargetAppUrl + "/Authentication/LogOff");

            try
            {
                driver.Navigate().GoToUrl(TargetAppUrl + "/LogOn");

                driver.FindElement(By.Name("EmailAddress")).SendKeys("*****@*****.**");
                driver.FindElement(By.Name("Password")).SendKeys("BadPass");
                driver.FindElement(By.TagName("form")).Submit();

                driver.Url.ShouldEqual(TargetAppUrl + "/LogOn");

                driver.FindElement(By.ClassName("validation-summary-errors")).Text.ShouldContain(
                    "The user name or password provided is incorrect.");
            }
            finally
            {
                driver.Close();
            }
        }
Exemplo n.º 5
0
        public static IWebDriver GetConfigBrowser(string browserName)
        {
            string AppRoot = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string strDriverPath = null;
            IWebDriver webDriver = null;
            if (browserName.Equals("Firefox", StringComparison.InvariantCultureIgnoreCase))
            {
                webDriver = new FirefoxDriver();
            }
            else if (browserName.Equals("chrome", StringComparison.InvariantCultureIgnoreCase))
            {
                strDriverPath = Path.Combine(AppRoot, @"CodedUITests\Drivers\chromedriver_win32");
                webDriver = new ChromeDriver(strDriverPath);

            }
            else if (browserName.Equals("IE", StringComparison.InvariantCultureIgnoreCase))
            {
                InternetExplorerOptions options = new InternetExplorerOptions()
                {
                    EnableNativeEvents = true,
                    IgnoreZoomLevel = true
                };
                strDriverPath = Path.Combine(AppRoot, @"CodedUITests\Drivers\IEDriverServer_Win32_2.44.0");
                webDriver = new InternetExplorerDriver(strDriverPath, options, TimeSpan.FromMinutes(3.0));
            }
            if (webDriver == null)
                throw new Exception("must configure browsername in aap.config");
            else
                return webDriver;
        }
        public void Should_page_through_items_in_IE()
        {
            IWebDriver ieDriver = new InternetExplorerDriver();
            ieDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
            ieDriver.Navigate().GoToUrl("http://localhost:1392/");
            Login(ieDriver);

            ieDriver.FindElement(By.LinkText("Orders")).Click();

            for (int i = 0; i < 20; i++)
            {
                IWebElement nextButton = ieDriver.FindElement(By.Id("ContentPlaceHolder1_GridView1_ctl00_ImageButtonNext"));

                nextButton.Click();

                IWebElement pageCount = ieDriver.FindElement(By.Id("ContentPlaceHolder1_GridView1_ctl00_TextBoxPage"));

                int pageNumber = int.Parse(pageCount.GetAttribute("value"));

                Assert.AreEqual(i + 2, pageNumber);
            }

            ieDriver.FindElement(By.Id("LoginStatus1")).Click();
            ieDriver.Quit();
        }
Exemplo n.º 7
0
		public static IWebDriver StartDriver (string browserType)
		{
			Trace.WriteLine("Start browser: '" + browserType + "'");

			IWebDriver driver = null;
			switch (browserType)
			{
				case "ie":
					{
						driver = new InternetExplorerDriver("Drivers");
						break;
					}
				case "firefox":
					{
						FirefoxProfile firefoxProfile = new FirefoxProfile();
						firefoxProfile.EnableNativeEvents = true;
						firefoxProfile.AcceptUntrustedCertificates = true;

						driver = new FirefoxDriver(firefoxProfile);
						break;
					}
				case "chrome":
					{
						ChromeOptions chromeOptions = new ChromeOptions();
						chromeOptions.AddArgument("--disable-keep-alive");

						driver = new ChromeDriver("Drivers", chromeOptions);
						break;
					}
			}

			driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(3));
			driver.Manage().Window.Maximize();
			return driver;
		}
Exemplo n.º 8
0
        /// <summary>
        /// Creates a driver if it has not been created yet. 
        /// </summary>
        public void SetupDriver()
        {
            if (_driver == null)
            {
                switch (DriverType)
                {
                    case DriverTypes.Phantom:
                        _driver = new PhantomJSDriver(DriversPath);
                        break;
                    case DriverTypes.Firefox:
                        _driver = new FirefoxDriver();
                        break;
                    case DriverTypes.InternetExplorer:
                        var options = new InternetExplorerOptions();
                        options.IgnoreZoomLevel = true;
                        _driver = new InternetExplorerDriver(DriversPath, options);

                        break;
                    case DriverTypes.Chrome:
                    default:
                        if (!File.Exists("chromedriver.exe"))
                        {
                            _driver = new ChromeDriver(DriversPath);
                        }
                        else
                            _driver = new ChromeDriver();
                        break;
                }
            }

        }
 public IWebDriver CreateWebDriver()
 {
     var driver = new InternetExplorerDriver();
     driver.Manage().Window.Maximize();
     driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(3));
     return driver;
 }
        public void when_logging_in_with_an_invalid_username_and_password()
        {
            var capabilities = new DesiredCapabilities();
            capabilities.SetCapability(InternetExplorerDriver.IntroduceInstabilityByIgnoringProtectedModeSettings, true);

            var driver = new InternetExplorerDriver(capabilities);

            try
            {
                driver.Navigate().GoToUrl("http://*****:*****@user.com");
                driver.FindElement(By.Name("Password")).SendKeys("BadPass");
                driver.FindElement(By.TagName("form")).Submit();

                driver.Url.ShouldEqual("http://localhost:52125/Account/LogOn");

                driver.FindElement(By.ClassName("validation-summary-errors")).Text.ShouldContain(
                    "The user name or password provided is incorrect.");
            }
            finally
            {
                driver.Close();
            }
        }
Exemplo n.º 11
0
        public static IWebDriver GetDriver(DriverType typeOfDriver)
        {
            IWebDriver browser;
            switch (typeOfDriver)
            {
                // NOTE REMOTE DRIVER IS NOT SUPPORTED
                case DriverType.Chrome:
                    ChromeOptions co = new ChromeOptions();
                    browser = new ChromeDriver();
                    break;
                case DriverType.IE:
                    InternetExplorerOptions ieo = new InternetExplorerOptions();
                    browser = new InternetExplorerDriver();
                    break;
                case DriverType.Firefox:    
                default:
                    FirefoxProfile ffp = new FirefoxProfile();
                    ffp.AcceptUntrustedCertificates = true;
                    ffp.Port = 8181;

                    browser = new FirefoxDriver(ffp);
                    break;
            }
            return browser;
        }
        private static IWebDriver CreateWebDriver()
        {
            IWebDriver driver = null;

            var type = ConfigurationManager.AppSettings["WebDriver"];
            switch (type)
            {
                case "Firefox":
                    {
                        var profile = new FirefoxProfile
                        {
                            AcceptUntrustedCertificates = true,
                            EnableNativeEvents = true
                        };
                        driver = new FirefoxDriver(profile);

                        break;
                    }
                case "InternetExplorer":
                    {
                        // Currently not working
                        var options = new InternetExplorerOptions
                        {
                            IgnoreZoomLevel = true
                        };
                        driver = new InternetExplorerDriver(options);

                        break;
                    }                    
                case "Chrome":
                default:
                    throw new NotSupportedException();
            }
            return driver;
        }
Exemplo n.º 13
0
 public static IWebDriver ConfigureDriver(IWebDriver driver, string driverType, string driverPath)
 {
     switch (driverType)
     {
         case "ie":
             {
                 driver = new InternetExplorerDriver(driverPath);
                 driver.Manage().Window.Maximize();
                 return driver;
             }
         case "firefox":
             {
                 driver = new FirefoxDriver();
                 driver.Manage().Window.Maximize();
                 return driver;
             }
         case "chrome":
             {
                 driver = new ChromeDriver(driverPath);
                 driver.Manage().Window.Maximize();
                 return driver;
             }
     }
     return driver;
 }
		/// <summary>
		/// Get a RemoteWebDriver
		/// </summary>
		/// <param name="browser">the Browser to test on</param>
		/// <param name="languageCode">The language that the browser should accept.</param>
		/// <returns>a IWebDriver</returns>
		IWebDriver IWebDriverFactory.GetWebDriver(Browser browser, string languageCode)
		{
			//What browser to test on?s
			IWebDriver webDriver;
			switch (browser.Browserstring.ToLowerInvariant())
			{
				case "firefox":
					var firefoxProfile = new FirefoxProfile();
					firefoxProfile.SetPreference("intl.accept_languages", languageCode);
					webDriver = new FirefoxDriver(firefoxProfile);
					break;
				case "chrome":
					ChromeOptions chromeOptions = new ChromeOptions();
					chromeOptions.AddArguments("--test-type", "--disable-hang-monitor", "--new-window", "--no-sandbox", "--lang=" + languageCode);
					webDriver = new ChromeDriver(chromeOptions);
					break;
				case "internet explorer":
					webDriver = new InternetExplorerDriver(new InternetExplorerOptions { BrowserCommandLineArguments = "singleWindow=true", IntroduceInstabilityByIgnoringProtectedModeSettings = true, EnsureCleanSession = true, EnablePersistentHover = false });
					break;
				case "phantomjs":
					webDriver = new PhantomJSDriver(new PhantomJSOptions() {});
					break;
				default:
					throw new NotSupportedException("Not supported browser");
			}

			return webDriver;
		}
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            //Create an instance of HTTPWatch Controller
            Controller control = new Controller();

            //Start IE Driver. IE Driver Server is located in C:\\
            IWebDriver driver = new InternetExplorerDriver(@"C:\");

            // Set a unique initial page title so that HttpWatch can attach to it
            string uniqueTitle = Guid.NewGuid().ToString();
            IJavaScriptExecutor js = driver as IJavaScriptExecutor;
            js.ExecuteScript("document.title = '" + uniqueTitle + "';");

            // Attach HttpWatch to the instance of Internet Explorer created through WebDriver
            Plugin plugin = control.AttachByTitle(uniqueTitle);

            //Open the HTTPWatch Window
            plugin.OpenWindow(false);

            //Navigate to the BMI Application Page
            driver.Navigate().GoToUrl("http://dl.dropbox.com/u/55228056/bmicalculator.html");

            //Perform some steps
            driver.FindElement(By.Id("heightCMS")).SendKeys("181");
            driver.FindElement(By.Id("weightKg")).SendKeys("80");
            driver.FindElement(By.Id("Calculate")).Click();

            //Export the HAR Log generated to a file
            plugin.Log.Save(@"C:\bmicalc.hwl");

            //Close the Internet Explorer
            driver.Close();
        }
Exemplo n.º 16
0
 static void Main(string[] args)
 {
     try
     {
         var stopWatch = Stopwatch.StartNew();
         DesiredCapabilities capabilities = new DesiredCapabilities();
         var driverService = ChromeDriverService.CreateDefaultService(@"E:\");
         driverService.HideCommandPromptWindow = true;
         var webDriver = new InternetExplorerDriver();
         webDriver.Navigate().GoToUrl("http://www.udebug.com/UVa/10812");
         IWebElement inputBox = webDriver.FindElement(By.Id("edit-input-data"));
         inputBox.SendKeys("3\n2035415231 1462621774\n1545574401 1640829072\n2057229440 1467906174");
         IWebElement submitButton = webDriver.FindElement(By.Id("edit-output"));
         submitButton.SendKeys("\n");
         submitButton.Click();
         string answer = webDriver.PageSource;
         int begin = answer.IndexOf("<pre>") + 5;
         answer = answer.Substring(begin, answer.IndexOf("</pre>") - begin);
         Console.WriteLine(answer);
         webDriver.Close();
         Console.WriteLine(stopWatch.ElapsedMilliseconds);
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.Message);
     }
 }
Exemplo n.º 17
0
        public void Execute(IDictionary<string, object> variables, Dictionary<string, ObjectInfo> library, string[] parameters)
        {
            return;
            var browserType = (variables.ContainsKey("Browser") && (string)variables["Browser"] != "") ? (string)variables["Browser"] : parameters[0];

            Console.WriteLine("OpenBrowser.Execute");
            IWebDriver browser = null;

            if (browserType == "Firefox")
            {
                browser = new FirefoxDriver();
            }
            else if (browserType == "IE")
            {
                browser = new InternetExplorerDriver(@"C:\projects\poc\pcg.qa.webtester\pcg.qa.webtester\Tools\");
            }
            else
            {
                throw new TestingException("Non Supported Browser!");
            }

            if (browser != null)
            {
                variables["BrowserInstance"] = browser;
            }
            else
            {
                throw new TestingException("Browser Instance not found!");
            }
        }
Exemplo n.º 18
0
        public void GivenUserOpensMessagesSectionOnVKWebsite()
        {
            IWebDriver driver = new InternetExplorerDriver();

            ScenarioContext.Current.Add("driver", driver);

            driver.Navigate().GoToUrl("http://vk.com/im");
        }
Exemplo n.º 19
0
 public void TestIE()
 {
     driver = new InternetExplorerDriver();
     //OpenPage needs to run twice because of an initialization bug with the IE driver
     OpenPage<GoogleHomePage>("http://www.google.com/");
     OpenPage<GoogleHomePage>("http://www.google.com/");
     driver.Quit();
 }
Exemplo n.º 20
0
        public void TestInitialize()
        {
            // Start IISExpress
            StartIIS();

            // Start Selenium drivers
            this.InternetExplorerDriver = new InternetExplorerDriver();
        }
Exemplo n.º 21
0
        public void TestHappyPathInternetExplorer()
        {
            InternetExplorerOptions options = new InternetExplorerOptions();
            options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;

            InternetExplorerDriver ied = new InternetExplorerDriver(options);
            TestHappyPath(ied);
        }
Exemplo n.º 22
0
 public void BeforeScenario()
 {
     var internetExplorerOptions = new InternetExplorerOptions
                                   {
                                       IntroduceInstabilityByIgnoringProtectedModeSettings = true
                                   };
     var driver = new InternetExplorerDriver(internetExplorerOptions);
     ScenarioContext.Current.Set(driver, "WebDriver");
 }
Exemplo n.º 23
0
 public static IWebDriver getIEDriver()
 {
     DriverFactory.DeleteIECookiesAndData();
     InternetExplorerOptions options = new InternetExplorerOptions();
     options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
     IWebDriver driver = new InternetExplorerDriver(options);
     driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(waitsec));
     return driver;
 }
Exemplo n.º 24
0
 public void ShouldBeAbleToCallQuitConsecutively()
 {
     driver.Url = simpleTestPage;
     driver.Quit();
     driver.Quit();
     driver = new InternetExplorerDriver();
     driver.Url = xhtmlTestPage;
     driver.Quit();
 }
Exemplo n.º 25
0
        public void EdgeDriverInitialize()
        {
            // Initialize edge driver
            var options = new InternetExplorerOptions
            {
                PageLoadStrategy = PageLoadStrategy.Normal
            };

            _driver = new InternetExplorerDriver(options);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Gets a driver of perticular type.
        /// </summary>
        /// <param name="driverType">Type of the driver</param>
        /// <param name="testCaseName">The TC requesting the driver</param>
        /// <returns></returns>
        public IWebDriver GetDriver(string testCaseName)
        {
            switch (ConfigurationSettings.AppSettings["TargetDriver"].ToString())
            {
                case "IE":
                    {
                        var options = new InternetExplorerOptions();
                        options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                        options.IgnoreZoomLevel = true;
                        IWebDriver driver = new InternetExplorerDriver(ConfigurationSettings.AppSettings["IEDriverServerPath"].ToString(),options);
                        InitializeDriverOperations(driver);

                        //For Grid
                        //System.Environment.SetEnvironmentVariable("webdriver.ie.driver", ConfigurationSettings.AppSettings["IEDriverServerPath"].ToString() +"\\IEDriverServer.exe");
                        //DesiredCapabilities capability = DesiredCapabilities.InternetExplorer();
                        //IWebDriver driver = new ScreenShotRemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capability);

                        DriverSessions.AddSession(testCaseName, driver);

                        return driver;
                    }
                case "Firefox":
                    {

                        IWebDriver driver = new FirefoxDriver();
                        InitializeDriverOperations(driver);

                        //For Grid
                        //DesiredCapabilities capability = DesiredCapabilities.Firefox();
                        //IWebDriver driver = new ScreenShotRemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capability);

                        DriverSessions.AddSession(testCaseName, driver);

                        return driver;
                    }
                case "Chrome":
                    {
                        IWebDriver driver = new ChromeDriver(ConfigurationSettings.AppSettings["ChromeDriverServerPath"].ToString());
                        InitializeDriverOperations(driver);

                        //For Grid
                         //System.Environment.SetEnvironmentVariable("webdriver.ie.driver", ConfigurationSettings.AppSettings["IEDriverServerPath"].ToString() +"\\IEDriverServer.exe");
                        //DesiredCapabilities capability = DesiredCapabilities.Chrome();
                        //IWebDriver driver = new ScreenShotRemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capability);

                        DriverSessions.AddSession(testCaseName, driver);

                        return driver;

                    }
                default:
                    return null;

            }
        }
Exemplo n.º 27
0
 public void ShouldBeAbleToCallQuitAfterCallingCloseOnOnlyOpenWindow()
 {
     EnvironmentManager.Instance.CloseCurrentDriver();
     IWebDriver testDriver = new InternetExplorerDriver();
     testDriver.Url = simpleTestPage;
     testDriver.Close();
     testDriver.Quit();
     testDriver = new InternetExplorerDriver();
     testDriver.Url = xhtmlTestPage;
     Assert.AreEqual("XHTML Test Page", testDriver.Title);
     testDriver.Quit();
 }
Exemplo n.º 28
0
        public void OpenGoogle()
        {
            IWebDriver driver = new InternetExplorerDriver();
            //IWebDriver driver = new FirefoxDriver();

            driver.Navigate().GoToUrl("http://www.google.com/");
            IWebElement query = driver.FindElement(By.Name("q"));
            query.SendKeys("Cheese");
            System.Console.WriteLine("Page title is: " + driver.Title);
            // TODO add wait
            driver.Quit();
        }
    static void Main()
    {
        using (var driver = new OpenQA.Selenium.IE.InternetExplorerDriver())
        {
            driver.Navigate().GoToUrl("https://www.bing.com/");
            driver.FindElement(By.Id("sb_form_q")).SendKeys("Selenium WebDriver");
            driver.FindElement(By.Id("sb_form_go")).Click();

            Console.WriteLine("OK");
            Console.ReadKey(intercept: true);
        }
    }
Exemplo n.º 30
0
 public void EndToEnd()
 {
     const string iisexpress = "iisexpress";
     Process iis = null;
     var iises = Process.GetProcessesByName(iisexpress);
     while (iises.Length > 0)
     {
         iis = iises[0];
         iis.Kill();
         iis.WaitForExit();
         iises = Process.GetProcessesByName(iisexpress);
     }
     iis = new Process();
     try
     {
         iis.StartInfo.FileName = @"C:\Program Files\IIS Express\iisexpress.exe";
         iis.StartInfo.Arguments = "/site:Website1";
         iis.Start();
         using (var driver = new ChromeDriver())
         {
             EndToEnd(driver);
         }
         using (var driver = new FirefoxDriver())
         {
             EndToEnd(driver);
         }
         var profile = new FirefoxProfile();
         profile.SetPreference
         (
             "general.useragent.override",
             "Mozilla/5.0 (iPhone; CPU iPhone OS 8_4_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) GSA/8.0.57838 Mobile/12H321 Safari/600.1.4"
         );
         using (var driver = new FirefoxDriver(profile))
         {
             var options = driver.Manage();
             options.Window.Size = new Size { Width = 100, Height = 550};
             driver.Url = url;
             TestNavigationMobile(driver, instructions, howToUse);
             TestNavigationMobile(driver, home, enterNumber);
             TestNavigation(driver, nsc, enterNumber);
             TestCalc(driver);
             TestNavigationMobile(driver, contact, contactDetails);
         }
         using (var driver = new InternetExplorerDriver())
         {
             EndToEnd(driver);
         }
     }
     finally
     {
         iis.CloseMainWindow();
     }
 }
Exemplo n.º 31
0
 public IWebDriver Create()
 {
     if (browserType == Type)
     {
         var profileIE = new InternetExplorerOptions();
         profileIE.EnableNativeEvents = true;
         var browser = new InternetExplorerDriver(profileIE);
         browser.Manage().Cookies.DeleteAllCookies();
         return browser;
     }
     return null;
 }
Exemplo n.º 32
0
        static void Main(string[] args)
        {
            var options = new InternetExplorerOptions
            {
                IgnoreZoomLevel = true
            };
            IWebDriver driver = new OpenQA.Selenium.IE.InternetExplorerDriver(options);

            driver.Navigate().GoToUrl("https://www.tomasvasquez.com.br/blog");

            IWebElement elemento = driver.FindElement(By.TagName("h1"));

            Console.WriteLine("O título do site é: {0}", elemento.Text);
            Console.Read();

            driver.Quit();
        }
Exemplo n.º 33
0
        static void Run()
        {
            var driverService = InternetExplorerDriverService.CreateDefaultService();

            driverService.HideCommandPromptWindow = true;

            var chromeDriverService = ChromeDriverService.CreateDefaultService();

            chromeDriverService.HideCommandPromptWindow = true;



            using (IWebDriver driver = new OpenQA.Selenium.IE.InternetExplorerDriver(driverService, new InternetExplorerOptions()))
            {
                driver.Navigate().GoToUrl("http://www.baidu.com");  //driver.Url = "http://www.baidu.com"是一样的

                var source = driver.PageSource;

                Console.WriteLine(source);
            }
        }
        static void Main(string[] args)
        {
            // Please keep your IE configuration settings:
            // 1. Check on "Enable Protected Mode" at ALL zones in "Security" tab of Internet Options dialog.
            // 2. Browser zoom level keep to 100%.
            var ieOptions = new InternetExplorerOptions
            {
                // Uncomment these lines if you use Microsoft Edge IE mode.
                // AttachToEdgeChrome = true,
                // EdgeExecutablePath = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe",
                IgnoreZoomLevel = true,
            };

            using (var driver = new OpenQA.Selenium.IE.InternetExplorerDriver(ieOptions))
            {
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
                driver.Navigate().GoToUrl("https://www.bing.com/");
                driver.FindElement(By.Id("sb_form_q")).SendKeys("Selenium WebDriver");
                driver.FindElement(By.ClassName("search")).Click();

                Console.WriteLine("OK");
                Console.ReadKey(intercept: true);
            }
        }
Exemplo n.º 35
0
 /// <summary>
 /// Initializes a new instance of the InternetExplorerTimeouts class
 /// </summary>
 /// <param name="driver">The driver that is currently in use</param>
 public InternetExplorerTimeouts(InternetExplorerDriver driver)
 {
     this.driver = driver;
 }
Exemplo n.º 36
0
 /// <summary>
 /// Initializes a new instance of the InternetExplorerNavigation class.
 /// </summary>
 /// <param name="driver">Driver in use</param>
 public InternetExplorerNavigation(InternetExplorerDriver driver)
 {
     this.driver = driver;
 }
Exemplo n.º 37
0
        private QA.IWebDriver InitWebDriver()
        {
            QA.IWebDriver theDriver = null;
            switch (this.browser)
            {
            case Browsers.IE:
            {
                InternetExplorerDriverService driverService = InternetExplorerDriverService.CreateDefaultService(Application.StartupPath + "\\drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;
                QA.IE.InternetExplorerOptions _ieOptions = new QA.IE.InternetExplorerOptions();
                _ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                theDriver = new QA.IE.InternetExplorerDriver(driverService, _ieOptions);
                ProcessID = driverService.ProcessId;
            }; break;

            case Browsers.PhantomJS:
            {
                PhantomJSDriverService driverService = PhantomJSDriverService.CreateDefaultService(Application.StartupPath + "\\Drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;

                theDriver = new QA.PhantomJS.PhantomJSDriver(driverService);
            }; break;

            case Browsers.Chrome:
            {
                ChromeDriverService driverService = ChromeDriverService.CreateDefaultService(Application.StartupPath + "\\drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;

                ChromeOptions options = new QA.Chrome.ChromeOptions();
                options.AddUserProfilePreference("profile.managed_default_content_settings.images", _IsLoadPicture ? 1 : 2);
                options.AddUserProfilePreference("profile.managed_default_content_settings.javascript", _IsLoadJS ? 1 : 2);

                //options.AddArgument(@"--user-data-dir=" + cache_dir);
                //string dir = string.Format(@"user-data-dir={0}", ConfigManager.GetInstance().UserDataDir);
                //options.AddArguments(dir);

                //options.AddArgument("--no-sandbox");
                //options.AddArgument("--disable-dev-shm-usage");
                //options.AddArguments("--disable-extensions"); // to disable extension
                //options.AddArguments("--disable-notifications"); // to disable notification
                //options.AddArguments("--disable-application-cache"); // to disable cache
                try
                {
                    if (_timeout == 60)
                    {
                        theDriver = new QA.Chrome.ChromeDriver(driverService, options, new TimeSpan(0, 0, 40));
                    }
                    else
                    {
                        theDriver = new QA.Chrome.ChromeDriver(driverService, options, new TimeSpan(0, 0, _timeout));
                    }
                }
                catch (Exception ex)
                {
                }
                ProcessID = driverService.ProcessId;
            }; break;

            case Browsers.Firefox:
            {
                var driverService = FirefoxDriverService.CreateDefaultService(Application.StartupPath + "\\drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;

                FirefoxProfile profile = new FirefoxProfile();
                try
                {
                    if (_doproxy == "1")
                    {
                        string proxy = "";
                        try
                        {
                            if (_IsUseNewProxy == false)
                            {
                                proxy = GetProxyA();
                            }
                            else
                            {
                                //TO DO 获取芝麻代理
                                hi.URL = "http:......?你的代理地址";        // ConfigManager.GetInstance().ProxyUrl;
                                hr     = hh.GetContent(hi);
                                if (hr.StatusCode == System.Net.HttpStatusCode.OK)
                                {
                                    if (hr.Content.Contains("您的套餐余量为0"))
                                    {
                                        proxy = "";
                                    }
                                    if (hr.Content.Contains("success") == false)
                                    {
                                        proxy = "";
                                    }

                                    JObject j = JObject.Parse(hr.Content);
                                    foreach (var item in j)
                                    {
                                        foreach (var itemA in item.Value)
                                        {
                                            if (itemA.ToString().Contains("expire_time"))
                                            {
                                                if (DateTime.Now.AddHours(2) < DateTime.Parse(itemA["expire_time"].ToString()))
                                                {
                                                    proxy = itemA["ip"].ToString() + ":" + itemA["port"].ToString();
                                                    break;
                                                }
                                            }
                                        }
                                        if (proxy != "")
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }

                        if (proxy != "" && proxy.Contains(":"))
                        {
                            OpenQA.Selenium.Proxy proxyF = new OpenQA.Selenium.Proxy();
                            proxyF.HttpProxy = proxy;
                            proxyF.FtpProxy  = proxy;
                            proxyF.SslProxy  = proxy;
                            profile.SetProxyPreferences(proxyF);
                            // 使用代理
                            profile.SetPreference("network.proxy.type", 1);
                            //ProxyUser-通行证书 ProxyPass-通行密钥
                            profile.SetPreference("username", "你的账号");
                            profile.SetPreference("password", "你的密码");

                            // 所有协议公用一种代理配置,如果单独配置,这项设置为false
                            profile.SetPreference("network.proxy.share_proxy_settings", true);

                            // 对于localhost的不用代理,这里必须要配置,否则无法和webdriver通讯
                            profile.SetPreference("network.proxy.no_proxies_on", "localhost");
                        }
                    }
                }
                catch (Exception ex)
                {
                }

                //profile.SetPreference("permissions.default.image", 2);
                // 关掉flash
                profile.SetPreference("dom.ipc.plugins.enabled.libflashplayer.so", false);
                FirefoxOptions options = new FirefoxOptions();
                options.Profile = profile;
                theDriver       = new QA.Firefox.FirefoxDriver(driverService, options, TimeSpan.FromMinutes(1));
                ProcessID       = driverService.ProcessId;
            }; break;

            case Browsers.Safari:
            {
                SafariDriverService driverService = SafariDriverService.CreateDefaultService(Application.StartupPath + "\\Drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds        = driverService;
                theDriver = new QA.Safari.SafariDriver(driverService);
                ProcessID = driverService.ProcessId;
            }; break;

            default:
            {
                QA.IE.InternetExplorerOptions _ieOptions = new QA.IE.InternetExplorerOptions();
                _ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                theDriver = new QA.IE.InternetExplorerDriver(_ieOptions);
            }; break;
            }
            return(theDriver);
        }
Exemplo n.º 38
0
 /// <summary>
 /// Initializes a new instance of the InternetExplorerOptions class.
 /// </summary>
 /// <param name="driver">Instance of the driver currently in use.</param>
 public InternetExplorerOptions(InternetExplorerDriver driver)
 {
     this.driver = driver;
 }
Exemplo n.º 39
0
        private QA.IWebDriver InitWebDriver(string cache_dir, bool loadImage = true, string useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36")
        {
            if (!Directory.Exists(cache_dir))
            {
                Directory.CreateDirectory(cache_dir);
            }
            QA.IWebDriver theDriver = null;
            switch (this.browser)
            {
            case Browsers.IE:
            {
                InternetExplorerDriverService driverService = InternetExplorerDriverService.CreateDefaultService(Application.StartupPath + "\\Drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;
                QA.IE.InternetExplorerOptions _ieOptions = new QA.IE.InternetExplorerOptions();
                _ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                theDriver  = new QA.IE.InternetExplorerDriver(driverService, _ieOptions);
                _ProcessID = driverService.ProcessId;
            }; break;

            case Browsers.Chrome:
            {
                ChromeDriverService driverService = ChromeDriverService.CreateDefaultService(Application.StartupPath + "\\Drivers\\");
                driverService.Port = new Random().Next(1000, 2000);
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;
                ChromeOptions options = new QA.Chrome.ChromeOptions();
                options.AddArgument("--window-size=" + Screen.PrimaryScreen.WorkingArea.Width + "x" + Screen.PrimaryScreen.WorkingArea.Height);
                options.AddArgument("--disable-gpu");
                options.AddArgument("--disable-extensions");
                options.AddArgument("--no-sandbox");
                options.AddArgument("--disable-dev-shm-usage");
                options.AddArgument("--disable-java");
                options.AddArgument("--user-agent=" + useragent);
                options.AddArgument(@"--user-data-dir=" + cache_dir);
                if (loadImage == false)
                {
                    options.AddUserProfilePreference("profile.managed_default_content_settings.images", 2);        //不加载图片
                }
                theDriver  = new QA.Chrome.ChromeDriver(driverService, options, TimeSpan.FromSeconds(240));
                _ProcessID = driverService.ProcessId;
            };
                break;

            case Browsers.Firefox:
            {
                var driverService = FirefoxDriverService.CreateDefaultService(Application.StartupPath + "\\Drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;
                FirefoxProfile profile = new FirefoxProfile();
                if (loadImage == false)
                {
                    profile.SetPreference("permissions.default.image", 2);
                    // 关掉flash
                    profile.SetPreference("dom.ipc.plugins.enabled.libflashplayer.so", false);
                }
                FirefoxOptions options = new FirefoxOptions();
                options.Profile = profile;
                theDriver       = new QA.Firefox.FirefoxDriver(driverService, options, TimeSpan.FromMinutes(240));
                _ProcessID      = driverService.ProcessId;
            };
                break;

            case Browsers.Safari:
            {
                SafariDriverService driverService = SafariDriverService.CreateDefaultService(Application.StartupPath + "\\Drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds         = driverService;
                theDriver  = new QA.Safari.SafariDriver(driverService);
                _ProcessID = driverService.ProcessId;
            };
                break;

            default:
            {
                QA.IE.InternetExplorerOptions _ieOptions = new QA.IE.InternetExplorerOptions();
                _ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                theDriver = new QA.IE.InternetExplorerDriver(_ieOptions);
            };
                break;
            }
            //theDriver.Manage().Window.Maximize();
            return(theDriver);
        }
Exemplo n.º 40
0
        private static IWebDriver CreateNewWebDriver(string webBrowserName, BrowserType type, out IntPtr mainWindowHandle, string driversDirectory)
        {
            webBrowserName = webBrowserName.ToLower();
            IWebDriver     iWebDriver            = null;
            List <Process> processesBeforeLaunch = GetProcesses();
            string         newProcessFilter      = string.Empty;

            switch (type)
            {
            case BrowserType.Chrome:
                var chromeService = Chrome.ChromeDriverService.CreateDefaultService(driversDirectory);
                chromeService.HideCommandPromptWindow = true;
                var chromeOptions = new Chrome.ChromeOptions();
                chromeOptions.PageLoadStrategy = PageLoadStrategy.None;
                chromeOptions.AddArgument("disable-infobars");
                chromeOptions.AddArgument("--disable-bundled-ppapi-flash");
                chromeOptions.AddArgument("--log-level=3");
                chromeOptions.AddArgument("--silent");
                chromeOptions.AddUserProfilePreference("credentials_enable_service", false);
                chromeOptions.AddUserProfilePreference("profile.password_manager_enabled", false);
                chromeOptions.AddUserProfilePreference("auto-open-devtools-for-tabs", false);
                //chromeOptions.AddAdditionalCapability("pageLoadStrategy", "none", true);
                iWebDriver       = new Chrome.ChromeDriver(chromeService, chromeOptions);
                newProcessFilter = "chrome";
                break;

            case BrowserType.Firefox:
                var firefoxService = Firefox.FirefoxDriverService.CreateDefaultService(driversDirectory);
                firefoxService.HideCommandPromptWindow = true;
                iWebDriver       = new Firefox.FirefoxDriver(firefoxService);
                newProcessFilter = "firefox";
                break;

            case BrowserType.InternetExplorer:
                IE.InternetExplorerDriverService ieService = IE.InternetExplorerDriverService.CreateDefaultService(driversDirectory);
                ieService.HideCommandPromptWindow = true;
                IE.InternetExplorerOptions options = new IE.InternetExplorerOptions()
                {
                    IgnoreZoomLevel = true
                };
                iWebDriver       = new IE.InternetExplorerDriver(ieService, options);
                newProcessFilter = "iexplore";
                break;

            case BrowserType.Edge:
                var edgeService = Edge.EdgeDriverService.CreateDefaultService(driversDirectory);
                edgeService.HideCommandPromptWindow = true;
                var edgeOptions = new Edge.EdgeOptions();
                edgeOptions.PageLoadStrategy = PageLoadStrategy.Eager;
                iWebDriver       = new Edge.EdgeDriver(edgeService, edgeOptions);
                newProcessFilter = "edge";
                break;

            default:
                throw new ArgumentException($"Could not launch specified browser '{webBrowserName}'");
            }
            var newProcess = GetNewlyCreatedProcesses(newProcessFilter, processesBeforeLaunch);

            mainWindowHandle = (newProcess != null) ? newProcess.MainWindowHandle : IntPtr.Zero;
            return(iWebDriver);
        }
Exemplo n.º 41
0
 /// <summary>
 /// Initializes a new instance of the InternetExplorerTargetLocator class.
 /// </summary>
 /// <param name="driver">The driver that is currently in use.</param>
 public InternetExplorerTargetLocator(InternetExplorerDriver driver)
 {
     this.driver = driver;
 }
Exemplo n.º 42
0
 /// <summary>
 /// Initializes a new instance of the InternetExplorerWebElement class.
 /// </summary>
 /// <param name="driver">Drive in use.</param>
 /// <param name="wrapper">Wrapper of the handle to get.</param>
 internal InternetExplorerWebElement(InternetExplorerDriver driver, SafeInternetExplorerWebElementHandle wrapper)
 {
     this.driver        = driver;
     this.elementHandle = wrapper;
 }
 /// <summary>
 /// Initializes a new instance of the InternetExplorerWebElementCollection class
 /// </summary>
 /// <param name="driver">driver in use</param>
 /// <param name="elements">Elements on the page</param>
 public InternetExplorerWebElementCollection(InternetExplorerDriver driver, SafeWebElementCollectionHandle elements)
 {
     this.driver      = driver;
     collectionHandle = elements;
 }
Exemplo n.º 44
0
        static void Main(string[] args)
        {
            try
            {
                ConsoleCmdLine   ccl            = new ConsoleCmdLine();
                CmdLineString    outputFileName = new CmdLineString("output-file", false, "Output File Name - defaults to SeleniumJasmineResults.xml");
                CmdLineString    chromeBaseDir  = new CmdLineString("chrome-path", false, @"Path to ChromeDriver.exe - defaults to c:\selenium\chromedriver_win32_2.2");
                CmdLineString    ieBaseDir      = new CmdLineString("ie-path", false, @"Path to IEDriverServer.exe - defaults to c:\selenium\IEDriverServer_x86_2.34.0");
                CmdLineString    inputUrlList   = new CmdLineString("input-url-file", false, "Input file containing urls to test - defaults to SpecRunnerList.txt");
                CmdLineParameter runChrome      = new CmdLineParameter("chrome", false, "Run Selenium with the chrome driver");
                CmdLineParameter runIE          = new CmdLineParameter("ie", false, "Run Selenium with the ie driver");
                CmdLineParameter runFireFox     = new CmdLineParameter("firefox", false, "Run Selenium with the FireFox driver");

                CmdLineParameter timeout     = new CmdLineParameter("timeout", false, "Timeout value (seconds) to wait for the tests to finish. defaults to 90.");
                CmdLineParameter reporter    = new CmdLineParameter("reporter", false, "Reporter type : jenkins | teamcity.  Defaults to teamcity reporter ");
                CmdLineParameter resultInput = new CmdLineParameter("reporter-input", false, "Reporter type : trivialreporter | logreporter.  Use trivial reporter for jasmine < 2.0 , use logreporter otherwise. ");


                ccl.RegisterParameter(outputFileName);
                ccl.RegisterParameter(chromeBaseDir);
                ccl.RegisterParameter(ieBaseDir);
                ccl.RegisterParameter(inputUrlList);
                ccl.RegisterParameter(runChrome);
                ccl.RegisterParameter(runIE);
                ccl.RegisterParameter(runFireFox);
                ccl.RegisterParameter(timeout);
                ccl.RegisterParameter(reporter);
                ccl.RegisterParameter(resultInput);
                ccl.Parse(args);


                string strOutputFileName     = !string.IsNullOrEmpty(outputFileName.Value) ? outputFileName.Value : "SeleniumTestRunner.xml";
                string strChromeBaseDir      = !string.IsNullOrEmpty(chromeBaseDir.Value) ? chromeBaseDir.Value : @"E:\source\github\selenium-jasmine-runner\chromedriver_win32_2.2";
                string strIEBaseDir          = !string.IsNullOrEmpty(ieBaseDir.Value) ? ieBaseDir.Value : @"E:\source\github\selenium-jasmine-runner\IEDriverServer_x64_2.34.0";
                string strSpecRunnerListFile = !string.IsNullOrEmpty(inputUrlList.Value) ? inputUrlList.Value : "SpecRunnerList.txt";
                string strReporter           = !string.IsNullOrEmpty(reporter.Value) ? reporter.Value : "teamcity";

                string strInput = !string.IsNullOrEmpty(resultInput.Value) ? resultInput.Value : "logreporter";

                short timeoutValue = 90;
                if (!string.IsNullOrEmpty(timeout.Value))
                {
                    Int16.TryParse(timeout.Value, out timeoutValue);
                }

                TestSuites testSuites = new TestSuites(TestReporterFactory.GetTestReporter(strReporter));

                List <string> strFileList = new List <string> ();
                using (FileStream fs = new FileStream(strSpecRunnerListFile, FileMode.Open, FileAccess.Read))
                {
                    StreamReader streamReader = new StreamReader(fs);

                    string strLine = streamReader.ReadLine();

                    while (!string.IsNullOrEmpty(strLine))
                    {
                        strFileList.Add(strLine);
                        strLine = streamReader.ReadLine();
                    }
                }

                if (runFireFox.Exists)
                {
                    using (var firefoxDriver = new OpenQA.Selenium.Firefox.FirefoxDriver())
                    {
                        foreach (string strSpecRunner in strFileList)
                        {
                            string strPageName = strSpecRunner.Substring(strSpecRunner.LastIndexOf('/') + 1);
                            if (strPageName.IndexOf('.') > 0)
                            {
                                strPageName = strPageName.Substring(0, strPageName.IndexOf('.'));
                            }

                            if (strInput == "logreporter")
                            {
                                RunAllJasmineTestsAndReport_LogReporter(firefoxDriver, timeoutValue, strSpecRunner,
                                                                        strPageName,
                                                                        "Chrome", ref testSuites);
                            }
                            else
                            {
                                RunAllJasmineTestsAndReportTrivialReporter(firefoxDriver, timeoutValue, strSpecRunner,
                                                                           strPageName, "FireFox", ref testSuites);
                            }
                        }
                    }
                }

                if (runChrome.Exists)
                {
                    using (var driver = new OpenQA.Selenium.Chrome.ChromeDriver(strChromeBaseDir))
                    {
                        foreach (string strSpecRunner in strFileList)
                        {
                            string strPageName = strSpecRunner.Substring(strSpecRunner.LastIndexOf('/') + 1);
                            if (strPageName.IndexOf('.') > 0)
                            {
                                strPageName = strPageName.Substring(0, strPageName.IndexOf('.'));
                            }

                            if (strInput == "logreporter")
                            {
                                RunAllJasmineTestsAndReport_LogReporter(driver, timeoutValue, strSpecRunner, strPageName,
                                                                        "Chrome", ref testSuites);
                            }
                            else
                            {
                                RunAllJasmineTestsAndReportTrivialReporter(driver, timeoutValue, strSpecRunner,
                                                                           strPageName, "Chrome", ref testSuites);
                            }
                        }
                    }
                }

                if (runIE.Exists)
                {
                    InternetExplorerOptions options = new InternetExplorerOptions();
                    options.EnableNativeEvents = false;
                    options.EnsureCleanSession = true;

                    using (var driver = new OpenQA.Selenium.IE.InternetExplorerDriver(strIEBaseDir))

                    {
                        foreach (string strSpecRunner in strFileList)
                        {
                            string strPageName = strSpecRunner.Substring(strSpecRunner.LastIndexOf('/') + 1);
                            if (strPageName.IndexOf('.') > 0)
                            {
                                strPageName = strPageName.Substring(0, strPageName.IndexOf('.'));
                            }

                            if (strInput == "logreporter")
                            {
                                RunAllJasmineTestsAndReport_LogReporter(driver, timeoutValue, strSpecRunner, strPageName, "IE", ref testSuites);
                            }
                            else
                            {
                                RunAllJasmineTestsAndReportTrivialReporter(driver, timeoutValue, strSpecRunner, strPageName, "IE", ref testSuites);
                            }
                        }
                    }
                }



                Console.WriteLine("-----------");

                if (strInput != "logreporter")
                {
                    testSuites.WriteToConsole();

                    using (FileStream fs = new FileStream(strOutputFileName, FileMode.Create, FileAccess.Write))
                    {
                        StreamWriter streamWriter = new StreamWriter(fs);

                        testSuites.WriteToStream(streamWriter);

                        streamWriter.Flush();
                    }

                    using (StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()))
                    {
                        sw.AutoFlush = true;
                        testSuites.WriteToStream(sw);
                        sw.Flush();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("");
                Console.WriteLine("Unhandled Exception " + ex.ToString());
                Console.WriteLine("");
                Console.WriteLine(ex.ToString());
                throw ex;
            }
        }
Exemplo n.º 45
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InternetExplorerWebElement"/> class.
 /// </summary>
 /// <param name="parent">Driver in use.</param>
 /// <param name="id">ID of the element.</param>
 public InternetExplorerWebElement(InternetExplorerDriver parent, string id)
     : base(parent, id)
 {
 }
        private IWebDriver GetDriver(DriverTypes type)
        {
            IWebDriver driver = null;
            switch (type)
            {
                case DriverTypes.IE:
                    driver = new InternetExplorerDriver(
                        new InternetExplorerOptions
                        {
                            UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Default,
                            EnableNativeEvents = true,
                            //ForceCreateProcessApi = true,
                            //BrowserCommandLineArguments = "-private",
                            EnsureCleanSession = true
                        });
                    driver = new NgWebDriver(driver);
                    break;

                case DriverTypes.Chrome:
                    ChromeOptions options = new ChromeOptions();
                    options.AddArgument("--disable-plugins");
                    driver = new ChromeDriver(options);
                    driver = new NgWebDriver(driver);
                    break;
            }
            ((NgWebDriver)driver).IgnoreSynchronization = true;
            return driver;
        }