示例#1
0
        public void GridTest1(string browserName)
        {
            IWebDriver driver = null;

            try
            {
                ICapabilities capabilities = null;

                if (browserName == "chrome")
                {
                    ChromeOptions chromeOptions = new ChromeOptions();
                    capabilities = chromeOptions.ToCapabilities();
                }
                else if (browserName == "firefox")
                {
                    FirefoxOptions firefoxOptions = new FirefoxOptions();
                    capabilities = firefoxOptions.ToCapabilities();
                }

                driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capabilities);
                //driver.Manage().Window.Maximize();
                driver.Navigate().GoToUrl("http://127.0.0.1:5500/Test.html");
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

                var page = new TestPageObject(driver);

                Assert.That(page.InputElem.Enabled);
            }
            catch (Exception ex)
            {
                //var ss = ((ITakesScreenshot)driver).GetScreenshot();

                //ss.SaveAsFile("E:\\ss.png", ScreenshotImageFormat.Png);

                //System.Console.WriteLine(ex);
                //throw;
                //Console.WriteLine(ex);
            }
            finally
            {
                driver.Quit();
            }
        }
示例#2
0
        public void LocalTest1()
        {
            IWebDriver driver = null;

            try
            {
                var options = new ChromeOptions();
                //options.AddArgument("--headless");

                driver = new ChromeDriver(options);
                //driver.Manage().Window.Maximize();
                driver.Navigate().GoToUrl("http://127.0.0.1:5500/Test.html");
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

                var page = new TestPageObject(driver);

                //Assert.IsTrue(driver.Title.Contains("Test demo"));
                Console.WriteLine(page.InputElem.GetProperty("id"));

                var js    = (IJavaScriptExecutor)driver;
                var value = js.ExecuteScript("return $('#name').val()");
                Console.WriteLine(value);

                Assert.That(page.InputElem.Enabled);
            }
            catch (Exception ex)
            {
                var ss = ((ITakesScreenshot)driver).GetScreenshot();

                ss.SaveAsFile("E:\\ss.png", ScreenshotImageFormat.Png);


                System.Console.WriteLine(ex);
                throw;
            }
            finally
            {
                driver.Close();
            }
        }