A wrapper around an arbitrary WebDriver instance which supports registering for events, e.g. for logging purposes.
Inheritance: IWebDriver, IJavaScriptExecutor, ITakesScreenshot, IWrapsDriver
        public void ShouldFireNavigationEvents()
        {
            Expect.Once.On(mockDriver).SetProperty("Url").To("http://www.get.com");
            Expect.Exactly(3).On(mockDriver).Method("Navigate").Will(Return.Value(mockNavigation));
            Expect.Once.On(mockNavigation).Method("GoToUrl").With("http://www.navigate-to.com");
            Expect.Once.On(mockNavigation).Method("Back");
            Expect.Once.On(mockNavigation).Method("Forward");

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver);
            firingDriver.Navigating += new EventHandler<WebDriverNavigationEventArgs>(firingDriver_Navigating);
            firingDriver.Navigated += new EventHandler<WebDriverNavigationEventArgs>(firingDriver_Navigated);
            firingDriver.NavigatingBack += new EventHandler<WebDriverNavigationEventArgs>(firingDriver_NavigatingBack);
            firingDriver.NavigatedBack += new EventHandler<WebDriverNavigationEventArgs>(firingDriver_NavigatedBack);
            firingDriver.NavigatingForward += new EventHandler<WebDriverNavigationEventArgs>(firingDriver_NavigatingForward);
            firingDriver.NavigatedForward += new EventHandler<WebDriverNavigationEventArgs>(firingDriver_NavigatedForward);

            firingDriver.Url = "http://www.get.com";
            firingDriver.Navigate().GoToUrl("http://www.navigate-to.com");
            firingDriver.Navigate().Back();
            firingDriver.Navigate().Forward();

            string expectedLog = @"Navigating http://www.get.com
Navigated http://www.get.com
Navigating http://www.navigate-to.com
Navigated http://www.navigate-to.com
Navigating back
Navigated back
Navigating forward
Navigated forward
";
            Assert.AreEqual(expectedLog, log.ToString());
        }
        public object ExecuteScript(string script, params object[] args)
        {
            IJavaScriptExecutor javaScriptExecutor = this.driver as IJavaScriptExecutor;

            if (javaScriptExecutor == null)
            {
                throw new NotSupportedException("Underlying driver instance does not support executing JavaScript");
            }
            object result = null;

            try
            {
                object[] args2             = EventFiringWebDriver.UnwrapElementArguments(args);
                WebDriverScriptEventArgs e = new WebDriverScriptEventArgs(this.driver, script);
                this.OnScriptExecuting(e);
                result = javaScriptExecutor.ExecuteScript(script, args2);
                this.OnScriptExecuted(e);
            }
            catch (Exception thrownException)
            {
                this.OnException(new WebDriverExceptionEventArgs(this.driver, thrownException));
                throw;
            }
            return(result);
        }
        public void ShouldBeAbleToAccessWrappedInstanceFromEventCalls()
        {
            mockDriver = new StubDriver();
            EventFiringWebDriver testDriver = new EventFiringWebDriver(mockDriver);
            StubDriver wrapped = ((IWrapsDriver)testDriver).WrappedDriver as StubDriver;
            Assert.AreEqual(mockDriver, wrapped);
            testDriver.Navigating += new EventHandler<WebDriverNavigationEventArgs>(testDriver_Navigating);

            testDriver.Url = "http://example.org";
        }
Beispiel #4
0
 public Debugger(IWebDriver driver)
 {
     _firingDriver = new EventFiringWebDriver(driver);
     _firingDriver.ExceptionThrown += ExceptionThrown;
     _firingDriver.ElementClicked += ElementClicked;
     _firingDriver.ElementClicking += ElementClicking;
     _firingDriver.FindElementCompleted += FindElementCompleted;
     _firingDriver.FindingElement += FindingElement;
     _firingDriver.Navigated += Navigated;
     _firingDriver.Navigating += Navigating;
     _firingDriver.ScriptExecuted += ScriptExecuted;
     _firingDriver.ScriptExecuting += ScriptExecuting;
     _firingDriver.ElementValueChanged += ElementValueChanged;
     _firingDriver.ElementValueChanging += ElementValueChanging;
 }
        public void ShouldFireClickEvent()
        {
            Expect.Once.On(mockDriver).Method("FindElement").With(By.Name("foo")).Will(Return.Value(mockElement));
            Expect.Once.On(mockElement).Method("Click");

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver);
            firingDriver.ElementClicking += new EventHandler<WebElementEventArgs>(firingDriver_ElementClicking);
            firingDriver.ElementClicked += new EventHandler<WebElementEventArgs>(firingDriver_ElementClicked);

            firingDriver.FindElement(By.Name("foo")).Click();

            string expectedLog = @"Clicking
Clicked
";
            Assert.AreEqual(expectedLog, log.ToString());
        }
        public void ShouldCallListenerOnException()
        {
            NoSuchElementException exception = new NoSuchElementException("argh");
            Expect.Once.On(mockDriver).Method("FindElement").With(By.Id("foo")).Will(Throw.Exception(exception));

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver);
            firingDriver.ExceptionThrown += new EventHandler<WebDriverExceptionEventArgs>(firingDriver_ExceptionThrown);

            try
            {
                firingDriver.FindElement(By.Id("foo"));
                Assert.Fail("Expected exception to be propogated");
            }
            catch (NoSuchElementException)
            {
                // Fine
            }

            Assert.AreEqual(exception.Message, log.ToString());
        }
Beispiel #7
0
        public void ShouldCallListenerOnException()
        {
            NoSuchElementException exception = new NoSuchElementException("argh");

            Expect.Once.On(mockDriver).Method("FindElement").With(By.Id("foo")).Will(Throw.Exception(exception));

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver);

            firingDriver.ExceptionThrown += new EventHandler <WebDriverExceptionEventArgs>(firingDriver_ExceptionThrown);

            try
            {
                firingDriver.FindElement(By.Id("foo"));
                Assert.Fail("Expected exception to be propogated");
            }
            catch (NoSuchElementException)
            {
                // Fine
            }

            Assert.AreEqual(exception.Message, log.ToString());
        }
 /// <summary>
 /// Initializes a new instance of the EventFiringOptions class
 /// </summary>
 /// <param name="driver">Instance of the driver currently in use</param>
 public EventFiringOptions(EventFiringWebDriver driver)
 {
     this.wrappedOptions = driver.WrappedDriver.Manage();
 }
 /// <summary>
 /// Initializes a new instance of the EventFiringNavigation class
 /// </summary>
 /// <param name="driver">Driver in use</param>
 public EventFiringNavigation(EventFiringWebDriver driver)
 {
     this.parentDriver = driver;
     this.wrappedNavigation = this.parentDriver.WrappedDriver.Navigate();
 }
        public void ShouldFireFindByEvent()
        {
            IList<IWebElement> driverElements = new List<IWebElement>();
            IList<IWebElement> subElements = new List<IWebElement>();
            Expect.Once.On(mockDriver).Method("FindElement").With(By.Id("foo")).Will(Return.Value(mockElement));
            Expect.Once.On(mockElement).Method("FindElement").With(By.LinkText("bar"));
            Expect.Once.On(mockElement).Method("FindElements").With(By.Name("xyz")).Will(Return.Value(new ReadOnlyCollection<IWebElement>(driverElements)));
            Expect.Once.On(mockDriver).Method("FindElements").With(By.XPath("//link[@type = 'text/css']")).Will(Return.Value(new ReadOnlyCollection<IWebElement>(subElements)));

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver);
            firingDriver.FindingElement += new EventHandler<FindElementEventArgs>(firingDriver_FindingElement);
            firingDriver.FindElementCompleted += new EventHandler<FindElementEventArgs>(firingDriver_FindElementCompleted);

            IWebElement element = firingDriver.FindElement(By.Id("foo"));
            element.FindElement(By.LinkText("bar"));
            element.FindElements(By.Name("xyz"));
            firingDriver.FindElements(By.XPath("//link[@type = 'text/css']"));

            string expectedLog = @"FindingElement from IWebDriver By.Id: foo
FindElementCompleted from IWebDriver By.Id: foo
FindingElement from IWebElement By.LinkText: bar
FindElementCompleted from IWebElement By.LinkText: bar
FindingElement from IWebElement By.Name: xyz
FindElementCompleted from IWebElement By.Name: xyz
FindingElement from IWebDriver By.XPath: //link[@type = 'text/css']
FindElementCompleted from IWebDriver By.XPath: //link[@type = 'text/css']
";

            Assert.AreEqual(expectedLog, log.ToString());
        }
 public void ShouldBeAbleToWrapSubclassesOfSomethingImplementingTheWebDriverInterface()
 {
     // We should get this far
     EventFiringWebDriver testDriver = new EventFiringWebDriver(new ChildDriver());
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EventFiringRenderedWebElement"/> class.
 /// </summary>
 /// <param name="driver">The <see cref="EventFiringWebDriver"/> instance hosting this element.</param>
 /// <param name="element">The <see cref="IWebElement"/> to wrap for event firing.</param>
 public EventFiringRenderedWebElement(EventFiringWebDriver driver, IWebElement element)
     : base(driver, element)
 {
 }
 private static IWebDriver AttachDriverEvents(IWebDriver driver)
 {
     var firingDriver = new EventFiringWebDriver(driver);
     firingDriver.ExceptionThrown += ExceptionThrown;
     firingDriver.Navigated += Navigated;
     firingDriver.NavigatedBack += NavigatedBack;
     firingDriver.NavigatedForward += NavigatedForward;
     firingDriver.FindingElement += FindingElement;
     firingDriver.FindElementCompleted += FindElementCompleted;
     return firingDriver;
 }
 public IWebDriver GetWebDriver()
 {
     _webDriver = new EventFiringWebDriver(new ChromeDriver(@"C:\windev\SeleniumTesting\Webdrivers"));
     _webDriver.Navigated += Navigated;
     return _webDriver;
 }
Beispiel #15
0
 /// <summary>
 /// Initializes a new instance of the EventFiringNavigation class
 /// </summary>
 /// <param name="driver">Driver in use</param>
 public EventFiringNavigation(EventFiringWebDriver driver)
 {
     this.parentDriver      = driver;
     this.wrappedNavigation = this.parentDriver.WrappedDriver.Navigate();
 }
 /// <summary>
 /// Initializes a new instance of the EventFiringTargetLocator class
 /// </summary>
 /// <param name="driver">The driver that is currently in use</param>
 public EventFiringTargetLocator(EventFiringWebDriver driver)
 {
     this.wrappedLocator = driver.WrappedDriver.SwitchTo();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EventFiringWebElement"/> class.
 /// </summary>
 /// <param name="driver">The <see cref="EventFiringWebDriver"/> instance hosting this element.</param>
 /// <param name="element">The <see cref="IWebElement"/> to wrap for event firing.</param>
 public EventFiringWebElement(EventFiringWebDriver driver, IWebElement element)
 {
     this.underlyingElement = element;
     this.parentDriver = driver;
 }
        public void ShouldUnwrapElementArgsWhenCallingScripts()
        {
            IExecutingDriver executingDriver = mocks.NewMock<IExecutingDriver>();
            Expect.Once.On(executingDriver).Method("FindElement").With(By.Id("foo")).Will(Return.Value(mockElement));
            Expect.Once.On(executingDriver).Method("ExecuteScript").With("foo", new[] { mockElement }).Will(Return.Value("foo"));

            EventFiringWebDriver testedDriver = new EventFiringWebDriver(executingDriver);

            IWebElement element = testedDriver.FindElement(By.Id("foo"));
            try
            {
                testedDriver.ExecuteScript("foo", element);
            }
            catch (Exception e)
            {
                // This is the error we're trying to fix
                throw e;
            }
        }