当前位置: 首页>>代码示例>>C#>>正文


C# IWebDriver.GetType方法代码示例

本文整理汇总了C#中IWebDriver.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IWebDriver.GetType方法的具体用法?C# IWebDriver.GetType怎么用?C# IWebDriver.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IWebDriver的用法示例。


在下文中一共展示了IWebDriver.GetType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TakeScreenShot

    public static void TakeScreenShot(IWebDriver webDriver, string screenShotFileNameWithoutExtension, ImageFormat imageFormat, string screenShotDirectoryPath) {
        Screenshot screenShot = null;
        var browserName = string.Empty;

        if (webDriver.GetType() == typeof(InternetExplorerDriver)) {
            screenShot = ((InternetExplorerDriver)webDriver).GetScreenshot();
            browserName = "IE";
        }

        if (webDriver.GetType() == typeof(FirefoxDriver)) {
            screenShot = ((FirefoxDriver)webDriver).GetScreenshot();
            browserName = "Firefox";
        }

        if (webDriver.GetType() == typeof(ChromeDriver)) {
            screenShot = ((ChromeDriver)webDriver).GetScreenshot();
            browserName = "Chrome";
        }

        var screenShotFileName = screenShotFileNameWithoutExtension + "." + imageFormat.ToString().ToLower();

        if (screenShot != null) {
            if (!string.IsNullOrEmpty(screenShotDirectoryPath)) {
                Directory.CreateDirectory(screenShotDirectoryPath).CreateSubdirectory(browserName);
                var browserScreenShotDirectoryPath = Path.Combine(screenShotDirectoryPath, browserName);
                Directory.CreateDirectory(browserScreenShotDirectoryPath);
                var screenShotFileFullPath = Path.Combine(browserScreenShotDirectoryPath, screenShotFileName);
                screenShot.SaveAsFile(screenShotFileFullPath, imageFormat);
            }
        }
    }
开发者ID:tablesmit,项目名称:browserscreenshots,代码行数:31,代码来源:Screenshots.cs

示例2: GetFirefoxBrowser64

        public void GetFirefoxBrowser64()
        {

            Assume.That(_driver.DownloadGeckoDriver());
            _driver = WebDriverFactory.GetBrowser<FirefoxDriver>("http://rickcasady.blogspot.com/");
            Assert.AreEqual(typeof(FirefoxDriver), _driver.GetType());
        }
开发者ID:rcasady616,项目名称:SeleniumExtensions,代码行数:7,代码来源:IWebDriverFactoryTests.cs

示例3: SetUpSelenium

        public void SetUpSelenium()
        {
            _driver = new FirefoxDriver();

            if (_driver.GetType() == typeof (FirefoxDriver))
            {
                _driver.Manage().Window.Maximize();
            }
            if (_driver.GetType() == typeof (ChromeDriver))
            {
                var options = new ChromeOptions();
                options.AddArgument("--start-maximized");
                _driver = new ChromeDriver(options);
            }

            _driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 0, 5));
            _actions = new Actions(_driver);
        }
开发者ID:krasnovandr,项目名称:Personal,代码行数:18,代码来源:SeleniumBasedHelper.cs

示例4: TakeScreenshot

        public static string TakeScreenshot(IWebDriver driver, string screenshotPath, string fileName = "")
        {
            ITakesScreenshot ss = driver as ITakesScreenshot;
            if (ss == null)
            {
                throw new Exception(string.Format(
                    "Can't take screenshot - driver {0} is null or doesn't implement ITakesScreenshot",
                    (driver == null) ? "null" : driver.GetType().Name));
            }

            DirectoryInfo outputPath = new DirectoryInfo(Path.Combine(
                screenshotPath,
                DateTime.Now.ToString("yyyy-MM-dd")));

            if (!outputPath.Exists)
            {
                outputPath.Create();
            }

            var driverName = driver.GetType().Name.Replace("Driver", string.Empty);
            if (String.IsNullOrEmpty(fileName))
            {
                var now = DateTime.Now.ToString("HHmmss");
                fileName = now;
            }

            foreach (var handle in driver.WindowHandles)
            {
                driver.SwitchTo().Window(handle);
                Uri u = new Uri(driver.Url);

                ss
                    .GetScreenshot()
                    .SaveAsFile(Path.Combine(outputPath.FullName, string.Format("{0}.jpeg", fileName)), System.Drawing.Imaging.ImageFormat.Jpeg);

            }
            return Path.Combine(outputPath.FullName, fileName);
        }
开发者ID:chriscore,项目名称:SpecDriver,代码行数:38,代码来源:ScreenshotHelper.cs

示例5: CheckMenuFontCN

 public void CheckMenuFontCN(IWebDriver driver)
 {
     driver.Url = "http://cn.kantar.stage.guardianprofessional.co.uk/";
     IWebElement home;
     home = driver.FindElement(By.CssSelector("html body.cn form#Form1 div#whiteBackground div#mainContainer div#mainNavigationContainer ul.firstLevelMenu li.first a"));
     //html body.cn form#Form1 div#whiteBackground div#mainContainer div#mainNavigationContainer ul.firstLevelMenu li.first a.selected CSS path for actual homepage above is the login page
     string actualfont = home.GetCssValue("font-family");
     Assert.IsTrue(actualfont.Contains("Microsoft Yahei"));
     String expectedfontsize;
     if ((driver.GetType().Name == "FirefoxDriver"))
     {
         expectedfontsize = "15.95px";
     }
     else if ((driver.GetType().Name == "ChromeDriver"))
     {
         expectedfontsize = "16px";
     }
     else
     {
         expectedfontsize = "10pt";
     }
     string actfontsize = home.GetCssValue("font-size");
     Assert.AreEqual(expectedfontsize, actfontsize);
 }
开发者ID:GCollins1974,项目名称:Kantar-Tests,代码行数:24,代码来源:UnitTest1.cs

示例6: ForceClick

 /// <summary>
 /// Click on a desired element within a document (with reference to Internet Explorer).
 /// </summary>
 /// <param name="element"></param>
 /// <param name="browser">Current webdriver instance.</param>
 public static void ForceClick(this IWebElement element, IWebDriver browser)
 {
     if (typeof(InternetExplorerDriver) == browser.GetType())
     {
         element.SendKeys(Keys.Enter);
     }
     else
     {
         element.Click();
     }
 }
开发者ID:rburkitt,项目名称:ServiceNowWebDriverExtensions,代码行数:16,代码来源:WebDriverExtensions.cs

示例7: RecordError

        /// <summary>
        /// Record details of an error that was detected during testing
        /// </summary>
        protected void RecordError(IWebDriver driver, string failingTest, Exception ex)
        {
            if (!NareshScalerSettings.Default.LoggingEnabled)
                return;

            if (!Directory.Exists(LogFileDirectory))
                Directory.CreateDirectory(LogFileDirectory);

            var screenshotsDir = LogFileDirectory + @"\screenshots";

            if (!Directory.Exists(screenshotsDir))
                Directory.CreateDirectory(screenshotsDir);

            var screenshotFilename = string.Format(screenshotsDir + @"\{0}-{1}.png", failingTest, DateTime.Now.ToString("MMdd-HHmm"));

            dynamic error = new ExpandoObject();
            error.Browser = driver.GetType().Name;
            error.TestName = failingTest;
            error.Description = ex.Message;
            error.Screenshot = screenshotFilename;
            TakeScreenshot(driver, screenshotFilename);
            ErrorList.Add(driver.GetType().Name + "_" + failingTest, error);

            // once we've logged the error, throw it on to allow nunit etc to handle it
            throw ex;
        }
开发者ID:hunt3ri,项目名称:NareshScaler,代码行数:29,代码来源:NareshScalerTest.cs

示例8: GetSauceTest

 public void GetSauceTest()
 {
     _driver = WebDriverFactory.GetSauceDriver(TestContext.CurrentContext.Test.Name, url: "http://rickcasady.blogspot.com/");
     Assert.AreEqual(typeof(RemoteWebDriver), _driver.GetType());
 }
开发者ID:rcasady616,项目名称:SeleniumExtensions,代码行数:5,代码来源:IWebDriverFactoryRemoteTests.cs

示例9: TestMethod1

        public void TestMethod1()
        {
            //testTarget = targ;
            //testID = "UI-" + tclass + "-" + tsubclass + "-" + tID;
            //testClass = tclass;
            //testSubClass = tsubclass;
            testRegressionCandidate = false;
            testStatus = states[0];
            testClass = "TIT";
            testSubClass = "IE";
            testTarget = "visitor";
            testUrl = "http://10.141.10.20:8080/Account/Login?ReturnUrl=%2f";

            switch (this.testSubClass)
            {
                case "FF":
                    // Create a new instance of the Firefox driver.
                    //driver = new FirefoxDriver();
                    driver = new FirefoxDriver(new FirefoxProfile(""));
                    break;
                case "IE":
                    // Create a new instance of the Firefox driver.
                    driver = new InternetExplorerDriver();

                    break;
                case "AS":
                    // Create a new instance of the Firefox driver.
                    driver = new SafariDriver();
                    break;
                case "GC":
                    // Create a new instance of the Firefox driver.
                    driver = new ChromeDriver();
                    break;
                default:
                    System.Console.Error.WriteLine("ERROR: Invalid test subclass");
                    Environment.Exit(-1);
                    break;
            }

            switch (this.testClass)
            {
                case ("TIT"):

                    try
                    {

                        //driver.Navigate().GoToUrl("http://www.google.com/");
                        driver.Navigate().GoToUrl(testUrl);

                        // Find the text input element by its name
                        //IWebElement query = driver.FindElement(By.Name("q"));

                        IWebElement loginF = driver.FindElement(By.ClassName("form-hideLabels"));
                        IWebElement uName = driver.FindElement(By.Id("UserName"));
                        IWebElement uPass = driver.FindElement(By.Id("Password"));

                        System.Console.WriteLine(driver.GetType());
                        System.Console.WriteLine(driver.GetHashCode());

                        int wdr = driver.Manage().GetHashCode();

                        // Enter something to search for
                        uName.SendKeys("admin");
                        uPass.SendKeys("1234");

                        // Now submit the form. WebDriver will find the form for us from the element
                        loginF.Submit();
                    }
                    catch (OpenQA.Selenium.NoSuchElementException nsee)
                    {
                        driver.Quit();
                        System.Console.Error.WriteLine("ERROR: Exception trying to reach a page element");
                        System.Console.Error.WriteLine(nsee.Message);
                        Thread.Sleep(5000);

                        response = null;
                        Environment.Exit(-2);

                    }
                    catch (OpenQA.Selenium.NoSuchWindowException nswe) {
                        driver.Quit();
                        System.Console.Error.WriteLine("ERROR: Exception trying to reach a window");
                        System.Console.Error.WriteLine(nswe.Message);
                        Thread.Sleep(5000);

                        response = null;
                        Environment.Exit(-2);

                    }
                    catch
                    {
                        driver.Quit();
                        System.Console.Error.WriteLine("ERROR: Other error");
                        Thread.Sleep(5000);

                        response = null;
                        Environment.Exit(-2);

                    }

//.........这里部分代码省略.........
开发者ID:jorge-ERNI,项目名称:TestProject,代码行数:101,代码来源:UnitTest1.cs

示例10: GetChromeBrowser

 public void GetChromeBrowser()
 {
     Assume.That(_driver.GetNuGetChromeDriver());
     _driver = WebDriverFactory.GetBrowser<ChromeDriver>("http://rickcasady.blogspot.com/");
     Assert.AreEqual(typeof(ChromeDriver), _driver.GetType());
 }
开发者ID:rcasady616,项目名称:SeleniumExtensions,代码行数:6,代码来源:IWebDriverFactoryTests.cs

示例11: GetInternetExplorerBrowser

 public void GetInternetExplorerBrowser()
 {
     Assume.That(_driver.GetNuGetIEDriver());
     _driver = WebDriverFactory.GetBrowser<InternetExplorerDriver>("http://rickcasady.blogspot.com/");
     Assert.AreEqual(typeof(InternetExplorerDriver), _driver.GetType());
 }
开发者ID:rcasady616,项目名称:SeleniumExtensions,代码行数:6,代码来源:IWebDriverFactoryTests.cs

示例12: CheckMenuFontUK

        public void CheckMenuFontUK(IWebDriver driver)
        {
            //if((driver.GetType().Name == "FirefoxDriver"))
            //{
            //    driver.Url = "http://uk.kantar.stage.guardianprofessional.co.uk/";
            //    var ActualFont = ((FirefoxDriver)driver).ExecuteScript("var elem=document.querySelector('html body.uk form#Form1 div#whiteBackground div#mainContainer div#mainNavigationContainer ul.firstLevelMenu li.first a.selected'); return getComputedStyle(elem, null).getPropertyValue('font-family')");
            //    Assert.IsTrue(ActualFont.ToString().Contains("dinotregular"));
            //    var ActualFontsize = ((FirefoxDriver)driver).ExecuteScript("var elem=document.querySelector('html body.uk form#Form1 div#whiteBackground div#mainContainer div#mainNavigationContainer ul.firstLevelMenu li.first a.selected'); return getComputedStyle(elem, null).getPropertyValue('font-size')");
            //    String ExpectedFont = "15.95px";
            //    Assert.AreEqual(ActualFontsize.ToString(), ExpectedFont);

            //}
            driver.Url = "http://uk.kantar.stage.guardianprofessional.co.uk/";
            IWebElement home;
            home = driver.FindElement(By.CssSelector("html body.uk form#Form1 div#whiteBackground div#mainContainer div#mainNavigationContainer ul.firstLevelMenu li.first a.selected"));

            string actualfont = home.GetCssValue("font-family");
            Assert.IsTrue(actualfont.Contains("dinotregular"));
            String expectedfontsize;
            if ((driver.GetType().Name == "FirefoxDriver"))
            {
                expectedfontsize = "15.95px";
            }
            else if ((driver.GetType().Name == "ChromeDriver"))
            {
                expectedfontsize = "16px";
            }
            else
            {
                expectedfontsize = "10pt";
            }
            string actfontsize = home.GetCssValue("font-size");
            Assert.AreEqual(expectedfontsize, actfontsize);
        }
开发者ID:GCollins1974,项目名称:Kantar-Tests,代码行数:34,代码来源:UnitTest1.cs

示例13: CheckTitleUK

        public void CheckTitleUK(IWebDriver driver)
        {
            if ((driver.GetType().Name == "internetexplorerdriver"))
            {
                //driver.Navigate().GoToUrl("http://uk.kantar.stage.guardianprofessional.co.uk/");
                //System.Threading.Thread.Sleep(60000);
                //WebDriverWait wait = new WebDriverWait(ied, TimeSpan.FromSeconds(10));
                //String actualText = driver.FindElement(By.CssSelector("html body.uk form#Form1 div#whiteBackground div#mainContainer div#mainNavigationContainer ul.firstLevelMenu li.first a.selected")).Text;
                //wait.Until(a => actualText = "HOME");
                IWebElement we = FindElement(driver, By.CssSelector("html body.uk form#Form1 div#whiteBackground div#mainContainer div#mainNavigationContainer ul.firstLevelMenu li.first a.selected"), 10);

            }
            else
            { driver.Url = "http://uk.kantar.stage.guardianprofessional.co.uk/"; }

            String StrExpectedTitle = "Home - Kantar";
            String actualtitle = driver.Title;
            Assert.AreEqual(StrExpectedTitle, actualtitle);
        }
开发者ID:GCollins1974,项目名称:Kantar-Tests,代码行数:19,代码来源:UnitTest1.cs

示例14: CheckMenuFontUS

 public void CheckMenuFontUS(IWebDriver driver)
 {
     driver.Url = "http://us.kantar.stage.guardianprofessional.co.uk/";
     IWebElement home;
     home = driver.FindElement(By.CssSelector("html body.us form#Form1 div#whiteBackground div#mainContainer div#mainNavigationContainer ul.firstLevelMenu li.first a.selected"));
     string actualfont = home.GetCssValue("font-family");
     Assert.IsTrue(actualfont.Contains("dinotregular"));
     String expectedfontsize;
     if ((driver.GetType().Name == "FirefoxDriver"))
     {
         expectedfontsize = "15.95px";
     }
     else if ((driver.GetType().Name == "ChromeDriver"))
     {
         expectedfontsize = "16px";
     }
     else
     {
         expectedfontsize = "10pt";
     }
     string actfontsize = home.GetCssValue("font-size");
     Assert.AreEqual(expectedfontsize, actfontsize);
 }
开发者ID:GCollins1974,项目名称:Kantar-Tests,代码行数:23,代码来源:UnitTest1.cs


注:本文中的IWebDriver.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。