Ejemplo n.º 1
0
        public void TestTeardownWithErrorAttemptsScreenshotButListenerIsUnavailable()
        {
            var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict);

            scenarioContext.Setup(s => s.GetError()).Returns(new InvalidOperationException());
            scenarioContext.Setup(s => s.GetStepFileName()).Returns("TestFileName");

            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(b => b.Close());
            browser.Setup(b => b.TakeScreenshot(It.IsAny <string>(), "TestFileName")).Returns((string)null);
            browser.Setup(b => b.SaveHtml(It.IsAny <string>(), "TestFileName")).Returns((string)null);

            var container = new Mock <IObjectContainer>(MockBehavior.Strict);

            container.Setup(c => c.Resolve <IBrowser>()).Returns(browser.Object);
            container.Setup(c => c.Resolve <IScenarioContextHelper>()).Returns(scenarioContext.Object);
            container.Setup(c => c.Resolve <ITraceListener>()).Returns((ITraceListener)null);

            var driverSupport = new WebDriverSupport(container.Object);

            driverSupport.TearDownWebDriverAfterScenario();

            container.VerifyAll();
            browser.VerifyAll();
            scenarioContext.VerifyAll();
        }
Ejemplo n.º 2
0
        public void TestTeardownWithErrorTakesSueccessfulScreenshot()
        {
            var listener = new Mock <ITraceListener>(MockBehavior.Strict);

            listener.Setup(l => l.WriteTestOutput(It.Is <string>(s => s.Contains("TestFileName.jpg"))));

            var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict);

            scenarioContext.Setup(s => s.GetError()).Returns(new InvalidOperationException());
            scenarioContext.Setup(s => s.GetStepFileName()).Returns("TestFileName");

            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(b => b.Close());
            browser.Setup(b => b.TakeScreenshot(It.IsAny <string>(), "TestFileName")).Returns("TestFileName.jpg");
            browser.Setup(b => b.SaveHtml(It.IsAny <string>(), "TestFileName")).Returns((string)null);

            var container = new Mock <IObjectContainer>(MockBehavior.Strict);

            container.Setup(c => c.Resolve <IBrowser>()).Returns(browser.Object);
            container.Setup(c => c.Resolve <IScenarioContextHelper>()).Returns(scenarioContext.Object);
            container.Setup(c => c.Resolve <ITraceListener>()).Returns(listener.Object);

            var driverSupport = new WebDriverSupport(container.Object);

            driverSupport.TearDownWebDriverAfterScenario();

            container.VerifyAll();
            browser.VerifyAll();
            scenarioContext.VerifyAll();
            listener.VerifyAll();
        }
Ejemplo n.º 3
0
        public void TestInitializeTests()
        {
            var logger = new Mock <ILogger>();

            var container = new Mock <IObjectContainer>(MockBehavior.Strict);

            container.Setup(c => c.RegisterInstanceAs(It.IsAny <IBrowser>(), null));
            container.Setup(c => c.RegisterInstanceAs <ISettingHelper>(It.IsAny <WrappedSettingHelper>(), null));
            container.Setup(c => c.RegisterInstanceAs(It.IsAny <IPageMapper>(), null));
            container.Setup(c => c.RegisterInstanceAs <IScenarioContextHelper>(It.IsAny <ScenarioContextHelper>(), null));
            container.Setup(c => c.RegisterInstanceAs <ITokenManager>(It.IsAny <TokenManager>(), null));
            container.Setup(c => c.RegisterInstanceAs(It.IsAny <IActionRepository>(), null));
            container.Setup(c => c.RegisterTypeAs <ActionPipelineService, IActionPipelineService>(null));
            container.Setup(c => c.RegisterTypeAs <ProxyLogger, ILogger>(null));
            container.Setup(c => c.Resolve <ILogger>()).Returns(logger.Object);

            container.Setup(c => c.Resolve(It.Is <Type>(t => typeof(ILocatorAction).IsAssignableFrom(t)), null)).Returns(new Mock <ILocatorAction>().Object);
            container.Setup(c => c.Resolve(It.Is <Type>(t => typeof(IPreAction).IsAssignableFrom(t)), null)).Returns(new Mock <IPreAction>().Object);
            container.Setup(c => c.Resolve(It.Is <Type>(t => typeof(IValidationComparer).IsAssignableFrom(t)), null)).Returns(new Mock <IValidationComparer>().Object);

            var driverSupport = new WebDriverSupport(container.Object);

            driverSupport.InitializeDriver();

            container.VerifyAll();
        }
Ejemplo n.º 4
0
 public static void ClickElement(this IWebElement e)
 {
     try
     {
         WaitUntilDisplayed(e);
         e.Click();
     }
     catch (TargetInvocationException)
     {
         //TODO make this more realistic for chrome.
         IJavaScriptExecutor executor = (IJavaScriptExecutor)WebDriverSupport.SupportDriver();
         executor.ExecuteScript("arguments[0].click();", e);
     }
     catch (ElementClickInterceptedException)
     {
         //TODO make this more realistic for chrome.
         IJavaScriptExecutor executor = (IJavaScriptExecutor)WebDriverSupport.SupportDriver();
         executor.ExecuteScript("arguments[0].click();", e);
     }
     catch (ElementNotInteractableException)
     {
         IJavaScriptExecutor executor = (IJavaScriptExecutor)WebDriverSupport.SupportDriver();
         executor.ExecuteScript("arguments[0].click();", e);
     }
 }
Ejemplo n.º 5
0
        public void TestCheckForScreenshotWithErrorAttemptsScreenshotButFails()
        {
            var listener = new Mock <ITraceListener>(MockBehavior.Strict);

            var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict);

            scenarioContext.Setup(s => s.GetError()).Returns(new InvalidOperationException());
            scenarioContext.Setup(s => s.GetStepFileName(true)).Returns("TestFileName");

            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(b => b.TakeScreenshot(It.IsAny <string>(), "TestFileName")).Returns((string)null);
            browser.Setup(b => b.SaveHtml(It.IsAny <string>(), "TestFileName")).Returns((string)null);
            browser.Setup(b => b.Close(true));
            browser.Setup(b => b.IsCreated).Returns(true);

            var container = new Mock <IObjectContainer>(MockBehavior.Strict);

            container.Setup(c => c.Resolve <IScenarioContextHelper>()).Returns(scenarioContext.Object);
            container.Setup(c => c.Resolve <ITraceListener>()).Returns(listener.Object);

            WebDriverSupport.Browser = browser.Object;
            var driverSupport = new WebDriverSupport(container.Object);

            driverSupport.CheckForScreenshot();

            container.VerifyAll();
            browser.VerifyAll();
            scenarioContext.VerifyAll();
            listener.VerifyAll();
        }
Ejemplo n.º 6
0
        public void SetupWebDriver()
        {
            var settingsLibrary = this.Context.GetSettingsLibrary <AppSettings>();
            var webDriver       = new WebDriverSupport <AppSettings>(settingsLibrary).Create();

            webDriver.Manage().Window.Maximize();
            webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(settingsLibrary.TestExecutionSettings.TimeoutSettings.PageNavigation);
            this.Context.SetWebDriver(webDriver);
        }
Ejemplo n.º 7
0
        public static void WaitUntilClickable(this IWebElement e)
        {
            var driver          = WebDriverSupport.SupportDriver();
            var isClickableWait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));

            isClickableWait.Until(ExpectedConditions.ElementToBeClickable(e));

            e.Click();
        }
Ejemplo n.º 8
0
        public void TestTearDownAfterTestRun()
        {
            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(b => b.Close(true));
            WebDriverSupport.Browser = browser.Object;

            WebDriverSupport.TearDownAfterTestRun();

            browser.VerifyAll();
        }
Ejemplo n.º 9
0
        public void WaitForjQuery_WhenCanGetUrlReturnsFalse_DoesNotTryToGetUrl()
        {
            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(s => s.IsClosed).Returns(false);
            browser.Setup(s => s.IsDisposed).Returns(false);
            browser.Setup(s => s.CanGetUrl()).Returns(false);
            WebDriverSupport.Browser = browser.Object;

            WebDriverSupport.WaitForjQuery();

            browser.VerifyAll();
        }
Ejemplo n.º 10
0
        public void TestWaitForjQueryWithNothingPending()
        {
            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(s => s.IsClosed).Returns(false);
            browser.Setup(s => s.IsDisposed).Returns(false);
            browser.Setup(s => s.Url).Returns("http://www.specbind.org");
            browser.Setup(s => s.ExecuteScript(It.IsAny <string>())).Returns("0");
            WebDriverSupport.Browser = browser.Object;

            WebDriverSupport.WaitForjQuery();

            browser.VerifyAll();
        }
Ejemplo n.º 11
0
        public void WaitForjQuery_WhenCanGetUrlReturnsTrue_GetsUrl()
        {
            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(s => s.IsClosed).Returns(false);
            browser.Setup(s => s.IsDisposed).Returns(false);
            browser.Setup(s => s.CanGetUrl()).Returns(true);
            browser.Setup(s => s.Url).Returns("http://www.specbind.org");
            browser.Setup(s => s.ExecuteScript(It.IsAny <string>())).Returns("0");
            WebDriverSupport.Browser = browser.Object;

            WebDriverSupport.WaitForjQuery();

            browser.VerifyAll();
        }
Ejemplo n.º 12
0
        public void TestCheckForScreenshotWithNoErrorButSettingEnabledTakesSuccessfulScreenshot()
        {
            var listener = new Mock <ITraceListener>(MockBehavior.Strict);

            listener.Setup(l => l.WriteTestOutput(It.Is <string>(s => s.Contains("TestFileName.jpg"))));

            var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict);

            scenarioContext.Setup(s => s.GetError()).Returns((Exception)null);
            scenarioContext.Setup(s => s.GetStepFileName(false)).Returns("TestFileName");

            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(b => b.TakeScreenshot(It.IsAny <string>(), "TestFileName")).Returns("TestFileName.jpg");
            browser.Setup(b => b.SaveHtml(It.IsAny <string>(), "TestFileName")).Returns((string)null);
            browser.Setup(b => b.Close(true));
            browser.Setup(b => b.IsCreated).Returns(true);

            var container = new Mock <IObjectContainer>(MockBehavior.Strict);

            container.Setup(c => c.Resolve <IScenarioContextHelper>()).Returns(scenarioContext.Object);
            container.Setup(c => c.Resolve <ITraceListener>()).Returns(listener.Object);

            WebDriverSupport.Browser = browser.Object;
            var driverSupport = new WebDriverSupport(container.Object);

            // Setup Configuration
            var config = new ConfigurationSectionHandler
            {
                BrowserFactory =
                    new BrowserFactoryConfigurationElement
                {
                    CreateScreenshotOnExit = true
                }
            };

            WebDriverSupport.ConfigurationMethod = new Lazy <ConfigurationSectionHandler>(() => config);

            driverSupport.CheckForScreenshot();

            config.BrowserFactory.CreateScreenshotOnExit = false;
            WebDriverSupport.ConfigurationMethod         = new Lazy <ConfigurationSectionHandler>(() => config);

            container.VerifyAll();
            browser.VerifyAll();
            scenarioContext.VerifyAll();
            listener.VerifyAll();
        }
Ejemplo n.º 13
0
        public void TestWaitForAngularWithSomethingPending()
        {
            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(s => s.IsClosed).Returns(false);
            browser.Setup(s => s.IsDisposed).Returns(false);
            browser.Setup(s => s.CanGetUrl()).Returns(true);
            browser.Setup(s => s.Url).Returns("http://www.specbind.org");
            browser.SetupSequence(s => s.ExecuteScript(It.IsAny <string>()))
            .Returns("1")
            .Returns("0");
            WebDriverSupport.Browser = browser.Object;

            WebDriverSupport.WaitForAngular();

            browser.VerifyAll();
        }
Ejemplo n.º 14
0
        public void IWaitForjQueryAjaxCallsToCompleteStep_WhenCanGetUrlReturnsFalse_DoesNotTryToGetUrl()
        {
            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(s => s.IsClosed).Returns(false);
            browser.Setup(s => s.IsDisposed).Returns(false);
            browser.Setup(s => s.CanGetUrl()).Returns(false);
            WebDriverSupport.SetCurrentBrowser(browser.Object);

            var pipelineService = new Mock <IActionPipelineService>(MockBehavior.Strict);
            var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict);
            var steps           = new WaitingSteps(pipelineService.Object, scenarioContext.Object);

            steps.WaitForjQuery();

            browser.VerifyAll();
        }
Ejemplo n.º 15
0
        public void TestCheckForScreenShotNoError()
        {
            var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict);

            scenarioContext.Setup(s => s.GetError()).Returns((Exception)null);

            var container = new Mock <IObjectContainer>(MockBehavior.Strict);

            container.Setup(c => c.Resolve <IScenarioContextHelper>()).Returns(scenarioContext.Object);

            var driverSupport = new WebDriverSupport(container.Object);

            driverSupport.CheckForScreenshot();

            container.VerifyAll();
            scenarioContext.VerifyAll();
        }
Ejemplo n.º 16
0
        public void IWaitForjQueryAjaxCallsToCompleteStep_WhenCanGetUrlReturnsTrue_GetsUrl()
        {
            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(s => s.IsClosed).Returns(false);
            browser.Setup(s => s.IsDisposed).Returns(false);
            browser.Setup(s => s.CanGetUrl()).Returns(true);
            browser.Setup(s => s.Url).Returns("http://www.specbind.org");
            browser.Setup(s => s.ExecuteScript(It.IsAny <string>())).Returns("0");
            WebDriverSupport.SetCurrentBrowser(browser.Object);

            var pipelineService = new Mock <IActionPipelineService>(MockBehavior.Strict);
            var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict);
            var steps           = new WaitingSteps(pipelineService.Object, scenarioContext.Object);

            steps.WaitForjQuery();

            browser.VerifyAll();
        }
Ejemplo n.º 17
0
        public void TestTearDownAfterScenarioWhenReuseBrowserIsTrue()
        {
            // arrange
            BrowserFactoryConfiguration config = new BrowserFactoryConfiguration
            {
                ReuseBrowser = true
            };

            var browserFactory = new Mock <BrowserFactory>(config);

            WebDriverSupport.SetBrowserFactory(browserFactory.Object);

            var browser = new Mock <IBrowser>(MockBehavior.Loose);

            WebDriverSupport.SetCurrentBrowser(browser.Object);

            // act
            WebDriverSupport.TearDownAfterScenario();

            // assert
            browser.Verify(b => b.Close(true), Times.Never());
        }
Ejemplo n.º 18
0
        public void TestInitializeTests()
        {
            var logger    = new Mock <ILogger>();
            var container = new Mock <IObjectContainer>(MockBehavior.Strict);

            container.Setup(c => c.RegisterInstanceAs(It.IsAny <BrowserFactory>(), null, true));
            container.Setup(c => c.RegisterFactoryAs(It.IsAny <Func <IObjectContainer, IBrowser> >(), null));
            container.Setup(c => c.RegisterInstanceAs <ISettingHelper>(It.IsAny <WrappedSettingHelper>(), null, false));
            container.Setup(c => c.RegisterInstanceAs(It.IsAny <IPageMapper>(), null, false));
            container.Setup(c => c.RegisterTypeAs <ScenarioContextHelper, IScenarioContextHelper>(null));
            container.Setup(c => c.RegisterTypeAs <TokenManager, ITokenManager>(null));
            container.Setup(c => c.RegisterInstanceAs(It.IsAny <IActionRepository>(), null, false));
            container.Setup(c => c.RegisterInstanceAs(It.IsAny <IActionPipelineService>(), null, false));
            container.Setup(c => c.RegisterTypeAs <ProxyLogger, ILogger>(null));
            container.Setup(c => c.Resolve <ILogger>()).Returns(logger.Object);

            var driverSupport = new WebDriverSupport(container.Object);

            driverSupport.InitializeDriver();

            container.VerifyAll();
        }
Ejemplo n.º 19
0
        public void TestTeardownNoError()
        {
            var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict);

            scenarioContext.Setup(s => s.GetError()).Returns((Exception)null);

            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(b => b.Close());

            var container = new Mock <IObjectContainer>(MockBehavior.Strict);

            container.Setup(c => c.Resolve <IBrowser>()).Returns(browser.Object);
            container.Setup(c => c.Resolve <IScenarioContextHelper>()).Returns(scenarioContext.Object);

            var driverSupport = new WebDriverSupport(container.Object);

            driverSupport.TearDownWebDriverAfterScenario();

            container.VerifyAll();
            browser.VerifyAll();
            scenarioContext.VerifyAll();
        }
Ejemplo n.º 20
0
        public void TestTearDownAfterScenarioWhenReuseBrowserIsTrue()
        {
            // arrange
            var config = new ConfigurationSectionHandler
            {
                BrowserFactory =
                    new BrowserFactoryConfigurationElement
                {
                    ReuseBrowser = true
                }
            };

            var browser = new Mock <IBrowser>(MockBehavior.Loose);

            WebDriverSupport.Browser             = browser.Object;
            WebDriverSupport.ConfigurationMethod = new Lazy <ConfigurationSectionHandler>(() => config);

            // act
            WebDriverSupport.TearDownAfterScenario();

            // assert
            browser.Verify(b => b.Close(true), Times.Never());
        }
Ejemplo n.º 21
0
        public void TestCheckForScreenShotNoError()
        {
            var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict);

            scenarioContext.Setup(s => s.GetError()).Returns((Exception)null);

            var container = new Mock <IObjectContainer>(MockBehavior.Strict);

            container.Setup(c => c.Resolve <IScenarioContextHelper>()).Returns(scenarioContext.Object);


            WebDriverSupport.SetBrowserFactory(new MockBrowserFactory());

            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(b => b.IsCreated).Returns(true);
            WebDriverSupport.SetCurrentBrowser(browser.Object);
            var driverSupport = new WebDriverSupport(container.Object);

            driverSupport.CheckForScreenshot();

            container.VerifyAll();
            scenarioContext.VerifyAll();
        }
Ejemplo n.º 22
0
        public static string WaitForText(this IWebElement e, string expectedText, int timeout = 10)
        {
            var watch        = new Stopwatch();
            var driver       = WebDriverSupport.SupportDriver();
            var textContains = false;

            watch.Start();
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0);
            while (!textContains && watch.Elapsed.TotalMilliseconds <= timeout.ToMilliseconds())
            {
                try
                {
                    if (e.Text.Contains(expectedText))
                    {
                        return(e.Text);
                    }
                }
                catch
                {
                }
            }

            return(null);
        }
Ejemplo n.º 23
0
        private static bool WaitHandler(IWebElement e, int timeout, ElementOptions option, string text = "")
        {
            var watch  = new Stopwatch();
            var driver = WebDriverSupport.SupportDriver();
            var result = false;

            watch.Start();
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0);
            while (watch.Elapsed.TotalMilliseconds <= timeout.ToMilliseconds() && !result)
            {
                try
                {
                    switch (option)
                    {
                    case ElementOptions.Displayed:
                        if (e.Displayed)
                        {
                            result = true;
                        }

                        break;

                    case ElementOptions.NotDisplayed:
                        if (e == null || !e.Displayed)
                        {
                            result = true;
                        }

                        break;

                    case ElementOptions.Enabled:
                        if (e.Enabled)
                        {
                            result = true;
                        }

                        break;

                    case ElementOptions.SelectOptionDisplayed:
                        if (e.FindElements(By.TagName("option")).Count(x => x.Text.Contains(text)) > 0)
                        {
                            result = true;
                        }

                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(option), option, null);
                    }
                }
                catch (NoSuchElementException)
                {
                    if (option == ElementOptions.NotDisplayed)
                    {
                        result = true;
                    }
                }
                catch (StaleElementReferenceException)
                {
                    if (option == ElementOptions.NotDisplayed)
                    {
                        result = true;
                    }
                }
                catch
                {
                    //Ignored
                }
            }

            // if (watch.Elapsed.Seconds > 1) Log.Info($"Waited for {watch.Elapsed.Seconds} seconds for the element state {option}");

            return(result);
        }
Ejemplo n.º 24
0
 public static void NavigateUrl(string url)
 {
     WebDriverSupport.SupportDriver().Navigate().GoToUrl(AppConfigManager.GetBaseUrl());
 }
Ejemplo n.º 25
0
 public void ClickSliderAmount(int x, int y)
 {
     WebDriverSupport.SliderAmountClick(AmountSlider, x, y);
 }
Ejemplo n.º 26
0
 public BunningsWishListSteps(WebDriverSupport wdsupport)
 {
     _wdsupport = wdsupport;
 }
Ejemplo n.º 27
0
 public void BeforeScenario()
 {
     _currentDriver = WebDriverSupport.LaunchDriver($"{AppConfigManager.Browser()}");
     _objectContainer.RegisterInstanceAs <IWebDriver>(_currentDriver);
 }
Ejemplo n.º 28
0
 public void BeforeScenario()
 {
     _currentDriver = WebDriverSupport.LaunchDriver();
     _iObjectContainer.RegisterInstanceAs <IWebDriver>(_currentDriver);
 }
Ejemplo n.º 29
0
 public void WaitForAngular()
 {
     WebDriverSupport.WaitForAngular();
 }
Ejemplo n.º 30
0
 public void WaitForjQuery()
 {
     WebDriverSupport.WaitForjQuery();
 }