public void TestGetPageBaseTypeReturnsNull()
        {
            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object));

            var result = browser.BasePageType;

            Assert.IsNull(result);
            driver.VerifyAll();
        }
示例#2
0
        public void TestGetUrlReturnsBrowserUrl()
        {
            const string BrowserUrl = "http://www.mysite.com/home";
            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            driver.SetupGet(d => d.Url).Returns(BrowserUrl);

            var logger = new Mock<ILogger>(MockBehavior.Loose);

            var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object), logger.Object);

            var result = browser.Url;

            Assert.AreEqual(BrowserUrl, result);
            driver.VerifyAll();
        }
        public void TestGotoPageCallsDriverMethod()
        {
            var url = new Uri("http://www.bing.com");

            var navigation = new Mock<INavigation>(MockBehavior.Strict);
            navigation.Setup(n => n.GoToUrl(url));

            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            driver.Setup(d => d.Navigate()).Returns(navigation.Object);

            var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object));

            browser.GoTo(url);

            driver.VerifyAll();
            navigation.VerifyAll();
        }
示例#4
0
        public void TestDisposeWhenCalledTwiceOnlyDisposesOnce()
        {
            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            driver.Setup(d => d.Quit());
            driver.Setup(d => d.Dispose());

            var lazyDriver = new Lazy<IWebDriver>(() => driver.Object);

            Assert.IsNotNull(lazyDriver.Value);

            var logger = new Mock<ILogger>(MockBehavior.Loose);

            var browser = new SeleniumBrowser(lazyDriver, logger.Object);

            browser.Dispose();
            browser.Dispose();

            driver.Verify(d => d.Quit(), Times.Exactly(1));
            driver.Verify(d => d.Dispose(), Times.Exactly(1));
            driver.VerifyAll();
        }
示例#5
0
        public void TestDisposeClosesBrowserWhenDriverIsInitialized()
        {
            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            driver.Setup(d => d.Quit());
            driver.Setup(d => d.Dispose());

            var lazyDriver = new Lazy<IWebDriver>(() => driver.Object);

            Assert.IsNotNull(lazyDriver.Value);

            var logger = new Mock<ILogger>(MockBehavior.Loose);

            var browser = new SeleniumBrowser(lazyDriver, logger.Object);

            browser.Dispose();

            driver.VerifyAll();
        }
示例#6
0
        public void TestAddCookieWhenCookieDoesntExistCallsDriverMethod()
        {
            var expireDate = DateTime.Now;

            var cookies = new Mock<ICookieJar>(MockBehavior.Strict);
            cookies.Setup(c => c.GetCookieNamed("TestCookie")).Returns((Cookie)null);
            cookies.Setup(c => c.AddCookie(It.Is<Cookie>(ck => ck.Name == "TestCookie" && ck.Value == "TestValue" && ck.Path == "/" && ck.Expiry == expireDate)));

            var options = new Mock<IOptions>(MockBehavior.Strict);
            options.Setup(o => o.Cookies).Returns(cookies.Object);

            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            driver.Setup(d => d.Manage()).Returns(options.Object);

            var logger = new Mock<ILogger>(MockBehavior.Loose);

            var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object), logger.Object);

            browser.AddCookie("TestCookie", "TestValue", "/", expireDate, null, false);

            driver.VerifyAll();
            options.VerifyAll();
            cookies.VerifyAll();
        }
示例#7
0
        public void TestTakeScreenshotWhenCalledWithoutErrorTakesScreenshot()
        {
            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            driver.As<ITakesScreenshot>().Setup(s => s.GetScreenshot()).Throws<InvalidOperationException>();

            var basePath = Path.GetTempPath();
            var fileName = Guid.NewGuid().ToString();
            
            Screenshot screenshot;
            using (var ms = new MemoryStream())
            {
                var image = TestResource.TestImage;
                image.Save(ms, ImageFormat.Jpeg);
                
                screenshot = new Screenshot(Convert.ToBase64String(ms.ToArray()));
            }

            var screenShot = driver.As<ITakesScreenshot>();
            screenShot.Setup(s => s.GetScreenshot()).Returns(screenshot);

            var logger = new Mock<ILogger>(MockBehavior.Loose);

            var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object), logger.Object);

            string fullPath = null;
            try
            {
                fullPath = browser.TakeScreenshot(basePath, fileName);
            }
            finally
            {
                if (fullPath != null && File.Exists(fullPath))
                {
                    File.Delete(fullPath);
                }
            }

            Assert.IsNotNull(fullPath);
            driver.VerifyAll();
        }
示例#8
0
        public void TestTakeScreenshotWhenNotSupportedDoesNothing()
        {
            var driver = new Mock<IWebDriver>(MockBehavior.Strict);

            var logger = new Mock<ILogger>(MockBehavior.Loose);

            var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object), logger.Object);

            var fullPath = browser.TakeScreenshot(@"C:\somepath", "fileBase");

            Assert.IsNull(fullPath);
            driver.VerifyAll();
        }
示例#9
0
        public void TestExecuteScriptWhenDriverDoesNotSupportScriptReturnsNull()
        {
            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            
            var lazyDriver = new Lazy<IWebDriver>(() => driver.Object);

            Assert.IsNotNull(lazyDriver.Value);

            var logger = new Mock<ILogger>(MockBehavior.Loose);

            var browser = new SeleniumBrowser(lazyDriver, logger.Object);

            var resultObject = browser.ExecuteScript("some script", "Hello");

            Assert.IsNull(resultObject);

            driver.VerifyAll();
        }
示例#10
0
 public static string ClearBrowserData(this SeleniumBrowser browser)
 {
     return(((IJavaScriptExecutor)browser.Driver).ExecuteAsyncScript(ScriptClear).ToString());
 }
示例#11
0
 public static string GetConsoleLogs(this SeleniumBrowser browser)
 {
     return(((IJavaScriptExecutor)browser.Driver).ExecuteAsyncScript(ScriptGetLog).ToString());
 }
示例#12
0
 public RenderController(SeleniumBrowser browser, HttpClient httpClient, ApiClient apiClient)
 {
     Browser    = browser;
     HttpClient = httpClient;
     ApiClient  = apiClient;
 }
示例#13
0
 protected BaseWebFixture()
 {
     Browser = new SeleniumBrowser();
 }
示例#14
0
 public void Setup()
 {
     browser = new SeleniumBrowser();
     browser.GoToURL("https://www.expedia.com/");
 }
示例#15
0
        public void TestExecuteScriptWhenDriverSupportItRunsScript()
        {
            var result = new object();
            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            driver.As<IJavaScriptExecutor>().Setup(e => e.ExecuteScript("some script", It.IsAny<object[]>()))
                                            .Returns(result);

            var lazyDriver = new Lazy<IWebDriver>(() => driver.Object);

            Assert.IsNotNull(lazyDriver.Value);

            var logger = new Mock<ILogger>(MockBehavior.Loose);

            var browser = new SeleniumBrowser(lazyDriver, logger.Object);

            var resultObject = browser.ExecuteScript("some script", "Hello");

            Assert.AreSame(result, resultObject);

            driver.VerifyAll();
        }
示例#16
0
        public void TestExecuteScriptWhenResultIsNativeElementReturnsProxyClass()
        {
            var result = new Mock<IWebElement>(MockBehavior.Strict);
            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            driver.As<IJavaScriptExecutor>().Setup(e => e.ExecuteScript("some script", It.IsAny<object[]>()))
                                            .Returns(result.Object);

            var lazyDriver = new Lazy<IWebDriver>(() => driver.Object);

            Assert.IsNotNull(lazyDriver.Value);

            var logger = new Mock<ILogger>(MockBehavior.Loose);

            var browser = new SeleniumBrowser(lazyDriver, logger.Object);

            var resultObject = browser.ExecuteScript("some script", "Hello");

            Assert.IsNotNull(resultObject);
            Assert.IsInstanceOfType(resultObject, typeof(WebElement));
           
            driver.VerifyAll();
            result.VerifyAll();
        }
示例#17
0
		private void TestBrowserWith(Mock<IWebDriver> driver, bool initializeDriver, Action<SeleniumBrowser> test)
		{
			var lazyDriver = new Lazy<IWebDriver>(() => driver.Object);
			if (initializeDriver)
			{
				Assert.IsNotNull(lazyDriver.Value);
			}

			var logger = new Mock<ILogger>(MockBehavior.Loose);

			using (var browser = new SeleniumBrowser(lazyDriver, logger.Object))
			{
				test(browser);
			}

			driver.VerifyAll();
		}
示例#18
0
        public void TestClearCookies()
        {
            var cookies = new Mock<ICookieJar>(MockBehavior.Strict);
            cookies.Setup(c => c.DeleteAllCookies());

            var options = new Mock<IOptions>(MockBehavior.Strict);
            options.Setup(o => o.Cookies).Returns(cookies.Object);

            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            driver.Setup(d => d.Manage()).Returns(options.Object);

            var logger = new Mock<ILogger>(MockBehavior.Loose);

            var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object), logger.Object);

            browser.ClearCookies();

            driver.VerifyAll();
            options.VerifyAll();
            cookies.VerifyAll();
        }
示例#19
0
        public void TestDismissAlertEntersTextAndAcceptsWhenOkIsChoosen()
        {
            var alerter = new Mock<IAlert>(MockBehavior.Strict);
            alerter.Setup(a => a.SendKeys("My Text"));
            alerter.Setup(a => a.Accept());

            var locator = new Mock<ITargetLocator>(MockBehavior.Strict);
            locator.Setup(l => l.Alert()).Returns(alerter.Object);

            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            driver.Setup(d => d.SwitchTo()).Returns(locator.Object);

            var logger = new Mock<ILogger>(MockBehavior.Loose);

            var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object), logger.Object);

            browser.DismissAlert(AlertBoxAction.Ok, "My Text");

            alerter.VerifyAll();
            driver.VerifyAll();
            locator.VerifyAll();
        }
示例#20
0
        public void TestTakeScreenshotWhenScreenshotErrorsReturnsNothing()
        {
            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            driver.As<ITakesScreenshot>().Setup(s => s.GetScreenshot()).Throws<InvalidOperationException>();

            var logger = new Mock<ILogger>(MockBehavior.Loose);

            var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object), logger.Object);

            var fullPath = browser.TakeScreenshot(@"C:\somepath", "fileBase");

            Assert.IsNull(fullPath);
            driver.VerifyAll();
        }
示例#21
0
        public void TestGetNativePageLocationReturnsUrl()
        {
            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            driver.SetupGet(d => d.Url).Returns("http://localhost:2222/MyPage");

            var logger = new Mock<ILogger>(MockBehavior.Loose);

            var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object), logger.Object);

            browser.EnsureOnPage<MyPage>();

            driver.VerifyAll();
        }
示例#22
0
        /// <summary>
        /// Tests the alert scenario.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="acceptResult">if set to <c>true</c> the result should accept; otherwise it should dismiss.</param>
        private static void TestAlertScenario(AlertBoxAction action, bool acceptResult)
        {
            var alerter = new Mock<IAlert>(MockBehavior.Strict);

            if (acceptResult)
            {
                alerter.Setup(a => a.Accept());
            }
            else
            {
                alerter.Setup(a => a.Dismiss());
            }
            
            var locator = new Mock<ITargetLocator>(MockBehavior.Strict);
            locator.Setup(l => l.Alert()).Returns(alerter.Object);

            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            driver.Setup(d => d.SwitchTo()).Returns(locator.Object);

            var logger = new Mock<ILogger>(MockBehavior.Loose);

            var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object), logger.Object);

            browser.DismissAlert(action, null);

            alerter.VerifyAll();
            driver.VerifyAll();
            locator.VerifyAll();
        }
示例#23
0
        public void TestDisposeDoesNothingWhenDriverIsNotInitialized()
        {
            var driver = new Mock<IWebDriver>(MockBehavior.Strict);

            var logger = new Mock<ILogger>(MockBehavior.Loose);

            var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object), logger.Object);

            browser.Dispose();

            driver.VerifyAll();
        }
 public static void Initialize(TestContext ignore)
 {
     ServersHelper.StartServers();
     Browser = new SeleniumBrowser(ServersHelper.GetSelenium());
 }
        public void TestClosesDoenNothingWhenDriverIsNotInitialized()
        {
            var driver = new Mock<IWebDriver>(MockBehavior.Strict);
            
            var browser = new SeleniumBrowser(new Lazy<IWebDriver>(() => driver.Object));

            browser.Close();

            driver.VerifyAll();
        }