public BrowserWrapper(IWebDriver browser, ITestBase testClass, ScopeOptions scope)
 {
     this.browser   = browser;
     this.testClass = testClass;
     ScopeOptions   = scope;
     SetCssSelector();
 }
        public BrowserWrapper GetFrameScope(string selector)
        {
            var options = new ScopeOptions {
                FrameSelector = selector, Parent = this, CurrentWindowHandle = browser.CurrentWindowHandle
            };

            var iframe = First(selector);

            iframe.CheckIfTagName(new[] { "iframe", "frame" }, $"The selected element '{iframe.FullSelector}' is not a iframe element.");
            var frame = browser.SwitchTo().Frame(iframe.WebElement);

            testClass.ActiveScope = options.ScopeId;
            return(new BrowserWrapper(frame, testClass, options));
        }
 /// <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);
     }
 }
        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);
        }