Exemplo n.º 1
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();
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
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();
        }