public ElementWrapper(IWebElement webElement, BrowserWrapper browserWrapper) { element = webElement; browser = browserWrapper; SelectMethod = browser.SelectMethod; BaseUrl = browser.BaseUrl; }
public ElementWrapperCollection(IEnumerable <ElementWrapper> collection, string selector, BrowserWrapper browserWrapper) { this.collection = new List <ElementWrapper>(collection); Selector = selector; SetReferences(selector); BrowserWrapper = browserWrapper; }
protected virtual void TakeScreenshot(int attemptNumber, BrowserWrapper browserWrapper) { // make screenshot try { LogCurrentlyPerformedAction("Taking screenshot"); var filename = Path.Combine(ScreenshotsFolderPath, $"{TestContext.FullyQualifiedTestClassName}_{TestContext.TestName}" + attemptNumber + ".png"); browserWrapper.TakeScreenshot(filename); LogCurrentlyPerformedAction($"Screenshot saved to: {filename}"); TestContext.AddResultFile(filename); } catch { //ignore } }
/// <summary> /// Executes test withnout caching exceptions /// </summary> /// <param name="testBody">Test to execute</param> /// <param name="browserFactory"></param> /// <param name="browserName"></param> /// <remarks>The ExpectException is ignored.</remarks> protected virtual void ExecuteTest(Action <BrowserWrapper> testBody, IWebDriverFactory browserFactory, out string browserName) { try { var browser = LatestLiveWebDriver = browserFactory.CreateNewInstance(); var scope = new ScopeOptions() { CurrentWindowHandle = browser.CurrentWindowHandle }; wrapper = new BrowserWrapper(browser, this, scope); browserName = browser.GetType().Name; testBody(wrapper); } finally { DisposeBrowsers(browserFactory); } }
public virtual void AfterSpecificBrowserTestEnds(BrowserWrapper browser) { }
public virtual void BeforeSpecificBrowserTestStarts(BrowserWrapper browser) { }
protected virtual void TryExecuteTest(Action <BrowserWrapper> testBody, IWebDriverFactory browserFactory, out string browserName, out Exception exception) { var attemptNumber = 0; var attampsMaximum = SeleniumTestsConfiguration.TestAttempts + (SeleniumTestsConfiguration.FastMode ? 1 : 0); do { attemptNumber++; WriteLine($"Attamp #{attemptNumber} starts...."); exception = null; var browser = LatestLiveWebDriver = browserFactory.CreateNewInstance(); LogDriverId(browser, "Driver creation - TryExecuteTest"); var scope = new ScopeOptions() { CurrentWindowHandle = browser.CurrentWindowHandle }; wrapper = new BrowserWrapper(browser, this, scope); browserName = browser.GetType().Name; WriteLine($"Testing browser '{browserName}' attempt no. {attemptNumber}"); bool exceptionWasThrow = false; try { BeforeSpecificBrowserTestStarts(wrapper); Log("Execution of user test starting.", 10); testBody(wrapper); Log("Execution of user test ended.", 10); AfterSpecificBrowserTestEnds(wrapper); } catch (Exception ex) { exceptionWasThrow = true; bool isExpected = false; if (ExpectedExceptionType != null) { isExpected = ex.GetType() == ExpectedExceptionType || (AllowDerivedExceptionTypes && ExpectedExceptionType.IsInstanceOfType(ex)); } Log("Test is expected to drop: " + isExpected, 10); if (!isExpected) { TakeScreenshot(attemptNumber, wrapper); // fail the test CurrentTestExceptions.Add(exception = ex); Log("Test attemp was not successfull! - TEST ATTAMP FAILED", 10); } if (attemptNumber < attampsMaximum) { RecreateBrowsers(browserFactory); } else { DisposeBrowsers(browserFactory); } } finally { if (!exceptionWasThrow) { CleanBrowsers(browserFactory); } } if (ExpectedExceptionType != null && !exceptionWasThrow) { CurrentTestExceptions.Add(exception = new SeleniumTestFailedException("Test was supposted to fail and it did not.")); } }while (exception != null && attemptNumber < attampsMaximum); }
public static ElementWrapperCollection ToElementsList(this IEnumerable <IWebElement> elements, BrowserWrapper browserWrapper, string selector) { return(new ElementWrapperCollection(elements.Select(s => new ElementWrapper(s, browserWrapper)), selector, browserWrapper)); }