public void CleanupActionsAddedInInitializeAreCalledAlsoFromRegularCleanup() { bool cleanupWasCalled = false; var context = new TestExecutionScopesManager("dummy", ctx => ctx.AddCleanupAction(() => cleanupWasCalled = true)); context.EndIsolationScope(); Assert.IsTrue(cleanupWasCalled); }
protected Browser OpenBrowserWithPage(string pageSource, TestExecutionScopesManager executionScopesManager) { var uri = CreatePage(pageSource); var driver = CreateDriver(); var browser = new Browser("test browser", driver, executionScopesManager); browser.NavigateToUrl(uri.ToString()); return(browser); }
public void StackTraceOfCleanupActionContainsTheOriginalLineItWasThrown() { var manager = new TestExecutionScopesManager("dummy", Functions.EmptyAction <IIsolationScope>()); manager.AddCleanupAction(MethodThatThrowsException); var ex = TestUtils.ExpectException <Exception>(manager.EndIsolationScope); StringAssert.Contains(ex.StackTrace, "MethodThatThrowsException"); }
public void CleaupActionIsCalledAfterInitialize() { bool cleanupWasCalled = false; var context = new TestExecutionScopesManager("dummy", ctx => { }); context.AddCleanupAction(() => cleanupWasCalled = true); context.EndIsolationScope(); Assert.IsTrue(cleanupWasCalled); }
public void NoExceptionIsThrownOnCleanupIfBrowserIsDisposedWhenTheresAnOpenWindow() { using (TestExecutionScopesManager.BeginIsolationScope("Window scope")) { using (var browser = OpenBrowserWithLinkToNewWindow()) { var link = browser.WaitForElement(By.Id("myLink"), "Link to other window"); browser.OpenWindow(() => link.Click(), "Other window"); } } }
public void CanAddCleanupActionAfterOneLevelWasPoppoed() { var context = new TestExecutionScopesManager("dummy", Functions.EmptyAction <IIsolationScope>()); context.BeginIsolationScope("Level1", Functions.EmptyAction <IIsolationScope>()); context.EndIsolationScope(); var cleanupCalled = false; context.AddCleanupAction(() => cleanupCalled = true); context.EndIsolationScope(); Assert.IsTrue(cleanupCalled, "Cleanup action hasn't been called"); }
public void CleanupActionInNestedIsolationLevelIsCalledOnlyOnPop() { bool cleaupWasCalled = false; var context = new TestExecutionScopesManager("dummy", ctx => { }); context.BeginIsolationScope("dummyIsolationLevel", ctx => { }); context.AddCleanupAction(() => cleaupWasCalled = true); context.EndIsolationScope(); Assert.IsTrue(cleaupWasCalled); cleaupWasCalled = false; context.EndIsolationScope(); Assert.IsFalse(cleaupWasCalled); }
public void ExceptionIsThrownIfCallingAddCleanupActionFromWithinACleaupAction() { var context = new TestExecutionScopesManager("dummy", ctx => { }); context.AddCleanupAction(() => { context.AddCleanupAction(() => { Assert.Fail("This code should never be called!"); }); }); TestUtils.ExpectException <InvalidOperationException>(() => { context.EndIsolationScope(); }); }
public void WindowIsClosedOnCleanup() { var scopesManager = new TestExecutionScopesManager("Dummy test scope", Functions.EmptyAction <IIsolationScope>()); using (var browser = OpenBrowserWithLinkToNewWindow(scopesManager)) { var driver = browser.GetWebDriver(); using (scopesManager.BeginIsolationScope("Window scope")) { var link = browser.WaitForElement(By.Id("myLink"), "Link to other window"); browser.OpenWindow(() => link.Click(), "Other window"); Assert.AreEqual(2, driver.WindowHandles.Count, "2 Windows should be open after OpenWindow was called"); } Assert.AreEqual(1, driver.WindowHandles.Count, "1 Window should be open after disposing the IsolationScope"); } }
private Browser OpenBrowserWithLinkToNewWindow(TestExecutionScopesManager scopeManager) { var otherPageUrl = CreatePageWithTitle(NewWindowTitle); var pageSource = @" <html> <head><title>" + FirstWindowTitle + @"</title></head> <body> <a id='myLink' target='_blank' href='" + otherPageUrl + @"'>Click here to open new window</a> </body> </html> "; var browser = OpenBrowserWithPage(pageSource, scopeManager); return(browser); }
public void DoesNothingIfInitializeIsNull() { bool outerCleanupIsCalled = false, innerCleanupIsCalled = false; Action <IIsolationScope> nullInitialize = null; var context = new TestExecutionScopesManager("OuterScope", nullInitialize); context.AddCleanupAction(() => outerCleanupIsCalled = true); context.BeginIsolationScope("InnerScope", nullInitialize); context.AddCleanupAction(() => innerCleanupIsCalled = true); context.EndIsolationScope(); Assert.IsTrue(innerCleanupIsCalled); context.EndIsolationScope(); Assert.IsTrue(outerCleanupIsCalled); }
/// <summary> /// Initializes the instance of the object using the specified description and <see cref="IWebDriver"/> /// </summary> /// <param name="description">The description of the browser. This is used for logging</param> /// <param name="webDriver">The WebDriver instance that is used to communicate with the browser</param> /// <param name="testExecutionScopesManager">The test execution scope manager of your tests (See remarks)</param> /// <exception cref="ArgumentNullException">one of the arguments are null</exception> /// <remarks> /// The <paramref name="testExecutionScopesManager"/> is used to automatically close any windows that /// are opened using <see cref="OpenWindow(System.Action,string)"/>, at the end of the current test or active scope. /// <br/> /// If you're using TestAutomationEssentials.MSTest or TestAutomationEssentials.MSTestV2, simply pass /// <see cref="TestExecutionScopesManager"/>. Otherwise, create an instance of <see cref="TestExecutionScopesManager"/> /// and pass it. /// </remarks> public Browser(string description, IWebDriver webDriver, TestExecutionScopesManager testExecutionScopesManager) : base(description) { if (webDriver == null) { throw new ArgumentNullException("webDriver"); } if (testExecutionScopesManager == null) { throw new ArgumentNullException("testExecutionScopesManager"); } WebDriver = webDriver; var mainWindowHandle = WebDriver.CurrentWindowHandle; _mainWindow = new BrowserWindow(this, mainWindowHandle, "Main window"); ActiveDOM = MainWindow; _testExecutionScopesManager = testExecutionScopesManager; }
public void ExceptionInNestedLevelInitialization() { var calledActions = new List <string>(); var context = new TestExecutionScopesManager("dummy", ctx => { }); context.AddCleanupAction(() => calledActions.Add("action1")); var ex = TestUtils.ExpectException <Exception>(() => context.BeginIsolationScope("nested", ctx => { context.AddCleanupAction(() => calledActions.Add("action2")); throw new Exception("DummyExceptionMessage"); })); Assert.AreEqual("DummyExceptionMessage", ex.Message); Assert.AreEqual("action2", calledActions.Content()); calledActions.Clear(); context.EndIsolationScope(); Assert.AreEqual("action1", calledActions.Content()); }
public void WhenMultipleCleanupActionsThrowExceptionsAnAggregatedExceptionIsThrown() { var context = new TestExecutionScopesManager("dummy", Functions.EmptyAction <IIsolationScope>()); var ex1 = new Exception("1st Exception"); var ex2 = new Exception("2nd Exception"); context.AddCleanupAction(() => { throw ex1; }); context.AddCleanupAction(() => { throw ex2; }); var aggregatedEx = TestUtils.ExpectException <AggregateException>(() => context.EndIsolationScope()); Assert.AreEqual(2, aggregatedEx.InnerExceptions.Count, "Invalid number of inner exceptions"); Assert.IsTrue(aggregatedEx.InnerExceptions.Contains(ex1), "1st exception is not found in the aggergate exception"); Assert.IsTrue(aggregatedEx.InnerExceptions.Contains(ex2), "2nd exception is not found in the aggergate exception"); }
public void NoCleanupActions() { var context = new TestExecutionScopesManager("dummy", ctx => { }); context.EndIsolationScope(); }