Exemplo n.º 1
0
        public void ShouldAllowUsersToHoverOverElements()
        {
            driver.Url = javascriptPage;

            IRenderedWebElement element = (IRenderedWebElement)driver.FindElement(By.Id("menu1"));

            if (!Platform.CurrentPlatform.IsPlatformType(PlatformType.Windows))
            {
                Assert.Ignore("Skipping test: Simulating hover needs native events");
            }

            IHasInputDevices inputDevicesDriver = driver as IHasInputDevices;

            if (inputDevicesDriver == null)
            {
                return;
            }

            IRenderedWebElement item = (IRenderedWebElement)driver.FindElement(By.Id("item1"));

            Assert.AreEqual("", item.Text);

            ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].style.background = 'green'", element);
            element.Hover();
            //inputDevicesDriver.ActionBuilder.MoveToElement(element).Build().Perform();

            item = (IRenderedWebElement)driver.FindElement(By.Id("item1"));
            Assert.AreEqual("Item 1", item.Text);
        }
Exemplo n.º 2
0
        public void ShouldAllowUsersToDragAndDropToElementsOffTheCurrentViewPort()
        {
            driver.Url = dragAndDropPage;

            IJavaScriptExecutor js   = (IJavaScriptExecutor)driver;
            int  height              = Convert.ToInt32(js.ExecuteScript("return window.outerHeight;"));
            int  width               = Convert.ToInt32(js.ExecuteScript("return window.outerWidth;"));
            bool mustUseOffsetHeight = width == 0 && height == 0;

            if (mustUseOffsetHeight)
            {
                width  = Convert.ToInt32(js.ExecuteScript("return document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;"));
                height = Convert.ToInt32(js.ExecuteScript("return document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;"));
            }

            js.ExecuteScript("window.resizeTo(300, 300);");
            if (mustUseOffsetHeight)
            {
                width  = width + 300 - Convert.ToInt32(js.ExecuteScript("return document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;"));
                height = height + 300 - Convert.ToInt32(js.ExecuteScript("return document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;"));
            }

            try
            {
                driver.Url = dragAndDropPage;
                IRenderedWebElement img = (IRenderedWebElement)driver.FindElement(By.Id("test3"));
                Point expectedLocation  = drag(img, img.Location, 100, 100);
                Assert.AreEqual(expectedLocation, img.Location);
            }
            finally
            {
                js.ExecuteScript("window.resizeTo(arguments[0], arguments[1]);", width, height);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Drag and Drop an element to another element.
        /// </summary>
        /// <param name="element">Element you wish to drop on.</param>
        public void DragAndDropOn(IRenderedWebElement element)
        {
            IntPtr          hwnd   = IntPtr.Zero;
            int             x      = 0;
            int             y      = 0;
            int             width  = 0;
            int             height = 0;
            WebDriverResult result = NativeDriverLibrary.Instance.GetElementDetailsOnceScrolledOnToScreen(elementHandle, ref hwnd, ref x, ref y, ref width, ref height);

            ResultHandler.VerifyResultCode(result, "Unable to determine location once scrolled on to screen");

            int startX = x + (width / 2);
            int startY = y + (height / 2);

            NativeDriverLibrary.Instance.MouseDownAt(hwnd, startX, startY);

            SafeInternetExplorerWebElementHandle other = ((InternetExplorerWebElement)element).Wrapper;

            result = NativeDriverLibrary.Instance.GetElementDetailsOnceScrolledOnToScreen(other, ref hwnd, ref x, ref y, ref width, ref height);
            ResultHandler.VerifyResultCode(result, "Unable to determine location of target once scrolled on to screen");

            int endX = x + (width / 2);
            int endY = y + (height / 2);

            int duration = driver.Manage().Speed.Timeout;

            NativeDriverLibrary.Instance.MouseMoveTo(hwnd, duration, startX, startY, endX, endY);
            NativeDriverLibrary.Instance.MouseUpAt(hwnd, endX, endY);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Drag and Drop an element to another element
        /// </summary>
        /// <param name="element">Element you wish to drop on</param>
        public virtual void DragAndDropOn(IRenderedWebElement element)
        {
            Point currentLocation = this.Location;
            Point destination     = element.Location;

            this.DragAndDropBy(destination.X - currentLocation.X, destination.Y - currentLocation.Y);
        }
Exemplo n.º 5
0
        public void ShouldCountElementsAsVisibleIfStylePropertyHasBeenSet()
        {
            driver.Url = javascriptPage;

            IRenderedWebElement shown = (IRenderedWebElement)driver.FindElement(By.Id("visibleSubElement"));

            Assert.IsTrue(shown.Displayed);
        }
Exemplo n.º 6
0
        public void ShouldNotAllowAnElementWithZeroWidthToBeCountedAsDisplayed()
        {
            driver.Url = javascriptPage;

            IRenderedWebElement zeroWidth = (IRenderedWebElement)driver.FindElement(By.Id("zerowidth"));

            Assert.IsFalse(zeroWidth.Displayed);
        }
Exemplo n.º 7
0
        private Point drag(IRenderedWebElement elem, Point initialLocation, int moveRightBy, int moveDownBy)
        {
            Point expectedLocation = new Point(initialLocation.X, initialLocation.Y);

            elem.DragAndDropBy(moveRightBy, moveDownBy);
            expectedLocation.Offset(moveRightBy, moveDownBy);
            return(expectedLocation);
        }
Exemplo n.º 8
0
        public void HiddenInputElementsAreNeverVisible()
        {
            driver.Url = javascriptPage;

            IRenderedWebElement shown = (IRenderedWebElement)driver.FindElement(By.Name("hidden"));

            Assert.IsFalse(shown.Displayed);
        }
Exemplo n.º 9
0
        public void ElementInDiv()
        {
            driver.Url = dragAndDropPage;
            IRenderedWebElement img = (IRenderedWebElement)driver.FindElement(By.Id("test3"));
            Point expectedLocation  = drag(img, img.Location, 100, 100);

            Assert.AreEqual(expectedLocation, img.Location);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="driver">The driver used to execute the command.</param>
        /// <param name="locator">The first parameter to the command.</param>
        /// <param name="value">The second parameter to the command.</param>
        /// <returns>The result of the command.</returns>
        protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value)
        {
            IRenderedWebElement dragger = (IRenderedWebElement)this.finder.FindElement(driver, locator);
            IRenderedWebElement draggee = (IRenderedWebElement)this.finder.FindElement(driver, value);

            dragger.DragAndDropOn(draggee);

            return(null);
        }
Exemplo n.º 11
0
        public void ShouldAllowInheritedStylesToBeUsed()
        {
            driver.Url = javascriptPage;

            IRenderedWebElement element = (IRenderedWebElement)driver.FindElement(By.Id("green-item"));
            String backgroundColour     = element.GetValueOfCssProperty("background-color");

            Assert.AreEqual("transparent", backgroundColour);
        }
Exemplo n.º 12
0
        public void ShouldNotCrashWhenCallingGetSizeOnAnObsoleteElement()
        {
            driver.Url = simpleTestPage;
            IRenderedWebElement elem = (IRenderedWebElement)driver.FindElement(By.Id("links"));

            driver.Url = xhtmlTestPage;
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(500));
            Size elementSize = elem.Size;
        }
Exemplo n.º 13
0
        public void DragAndDropToElement()
        {
            driver.Url = dragAndDropPage;
            IRenderedWebElement img1 = (IRenderedWebElement)driver.FindElement(By.Id("test1"));
            IRenderedWebElement img2 = (IRenderedWebElement)driver.FindElement(By.Id("test2"));

            img2.DragAndDropOn(img1);
            Assert.AreEqual(img1.Location, img2.Location);
        }
        public void ShouldBeAbleToDetermineTheSizeOfAnElement()
        {
            driver.Url = xhtmlTestPage;

            IRenderedWebElement element = (IRenderedWebElement)driver.FindElement(By.Id("username"));
            Size size = element.Size;

            Assert.Greater(size.Width, 0);
            Assert.Greater(size.Height, 0);
        }
Exemplo n.º 15
0
        public void ShouldCorrectlyIdentifyThatAnElementHasWidth()
        {
            driver.Url = xhtmlTestPage;

            IRenderedWebElement shrinko = (IRenderedWebElement)driver.FindElement(By.Id("amazing"));
            Size size = shrinko.Size;

            Assert.IsTrue(size.Width > 0, "Width expected to be greater than 0");
            Assert.IsTrue(size.Height > 0, "Height expected to be greater than 0");
        }
        public void ShouldBeAbleToDetermineTheLocationOfAnElement()
        {
            driver.Url = xhtmlTestPage;

            IRenderedWebElement element = (IRenderedWebElement)driver.FindElement(By.Id("username"));
            Point location = element.Location;

            Assert.Greater(location.X, 0);
            Assert.Greater(location.Y, 0);
        }
        public void ShouldNotCrashWhenCallingGetSizeOnAnObsoleteElement()
        {
            driver.Url = simpleTestPage;
            IRenderedWebElement elem = (IRenderedWebElement)driver.FindElement(By.Id("links"));

            driver.Url = xhtmlTestPage;
            //TODO (jimevan): this is an ugly sleep. Remove when implicit waiting is implemented.
            System.Threading.Thread.Sleep(500);
            Size elementSize = elem.Size;
        }
Exemplo n.º 18
0
        public void ShouldClearRenderedElement()
        {
            driver.Url = javascriptPage;

            IRenderedWebElement textbox = (IRenderedWebElement)driver.FindElement(By.Id("keyUp"));

            textbox.SendKeys("a@#$ç.ó");
            textbox.Clear();
            Assert.AreEqual("", textbox.Value);
        }
Exemplo n.º 19
0
        public void VisibilityShouldTakeIntoAccountParentVisibility()
        {
            driver.Url = javascriptPage;

            IRenderedWebElement childDiv   = (IRenderedWebElement)driver.FindElement(By.Id("hiddenchild"));
            IRenderedWebElement hiddenLink = (IRenderedWebElement)driver.FindElement(By.Id("hiddenlink"));

            Assert.IsFalse(childDiv.Displayed);
            Assert.IsFalse(hiddenLink.Displayed);
        }
Exemplo n.º 20
0
        public void RemovingAnElementDynamicallyFromTheDomShouldCauseAStaleRefException()
        {
            driver.Url = javascriptPage;

            IRenderedWebElement toBeDeleted = (IRenderedWebElement)driver.FindElement(By.Id("deleted"));

            Assert.IsTrue(toBeDeleted.Displayed);

            driver.FindElement(By.Id("delete")).Click();
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(500));
            bool displayedAfterDelete = toBeDeleted.Displayed;
        }
Exemplo n.º 21
0
        public void ShouldModifyTheVisibilityOfAnElementDynamically()
        {
            driver.Url = javascriptPage;

            IRenderedWebElement element = (IRenderedWebElement)driver.FindElement(By.Id("hideMe"));

            Assert.IsTrue(element.Displayed);

            element.Click();

            Assert.IsFalse(element.Displayed);
        }
Exemplo n.º 22
0
        public void RemovingAnElementDynamicallyFromTheDomShouldCauseAStaleRefException()
        {
            driver.Url = javascriptPage;

            IRenderedWebElement toBeDeleted = (IRenderedWebElement)driver.FindElement(By.Id("deleted"));

            Assert.IsTrue(toBeDeleted.Displayed);

            driver.FindElement(By.Id("delete")).Click();
            //TODO (jimevan): this is an ugly sleep. Remove when implicit waiting is implemented.
            System.Threading.Thread.Sleep(500);
            bool displayedAfterDelete = toBeDeleted.Displayed;
        }
Exemplo n.º 23
0
        public void ShouldPickUpStyleOfAnElement()
        {
            driver.Url = javascriptPage;

            IRenderedWebElement element = (IRenderedWebElement)driver.FindElement(By.Id("green-parent"));
            String backgroundColour     = element.GetValueOfCssProperty("background-color");

            Assert.AreEqual("#008000", backgroundColour);

            element          = (IRenderedWebElement)driver.FindElement(By.Id("red-item"));
            backgroundColour = element.GetValueOfCssProperty("background-color");

            Assert.AreEqual("#ff0000", backgroundColour);
        }
Exemplo n.º 24
0
        public void DragAndDrop()
        {
            driver.Url = dragAndDropPage;
            IRenderedWebElement img = (IRenderedWebElement)driver.FindElement(By.Id("test1"));
            Point expectedLocation  = drag(img, img.Location, 150, 200);

            Assert.AreEqual(expectedLocation, img.Location);
            expectedLocation = drag(img, img.Location, -50, -25);
            Assert.AreEqual(expectedLocation, img.Location);
            expectedLocation = drag(img, img.Location, 0, 0);
            Assert.AreEqual(expectedLocation, img.Location);
            expectedLocation = drag(img, img.Location, 1, -1);
            Assert.AreEqual(expectedLocation, img.Location);
        }
Exemplo n.º 25
0
        public void ShouldReturnWhetherElementIsDisplayed()
        {
            driver.Url = javascriptPage;

            IRenderedWebElement hidden = (IRenderedWebElement)driver.FindElement(By.Id("hidden"));

            Assert.IsFalse(hidden.Displayed);

            IRenderedWebElement none = (IRenderedWebElement)driver.FindElement(By.Id("none"));

            Assert.IsFalse(none.Displayed);

            IRenderedWebElement displayed = (IRenderedWebElement)driver.FindElement(By.Id("displayed"));

            Assert.IsTrue(displayed.Displayed);
        }
Exemplo n.º 26
0
        public void DragTooFar()
        {
            driver.Url = dragAndDropPage;
            IRenderedWebElement img = (IRenderedWebElement)driver.FindElement(By.Id("test1"));

            // Dragging too far left and up does not move the element. It will be at
            // its original location after the drag.
            Point originalLocation = new Point(0, 0);

            img.DragAndDropBy(int.MinValue, int.MinValue);
            Assert.AreEqual(originalLocation, img.Location);

            img.DragAndDropBy(int.MaxValue, int.MaxValue);
            //We don't know where the img is dragged to , but we know it's not too
            //far, otherwise this function will not return for a long long time
        }
Exemplo n.º 27
0
        public void ShouldHandleNonIntegerPositionAndSize()
        {
            driver.Url = rectanglesPage;

            IRenderedWebElement r2 = (IRenderedWebElement)driver.FindElement(By.Id("r2"));
            String left            = r2.GetValueOfCssProperty("left");

            Assert.IsTrue(left.StartsWith("10.9"), "left (\"" + left + "\") should start with \"10.9\".");
            String top = r2.GetValueOfCssProperty("top");

            Assert.IsTrue(top.StartsWith("10.1"), "top (\"" + top + "\") should start with \"10.1\".");
            Assert.AreEqual(new Point(11, 10), r2.Location);
            String width = r2.GetValueOfCssProperty("width");

            Assert.IsTrue(width.StartsWith("48.6"), "width (\"" + left + "\") should start with \"48.6\".");
            String height = r2.GetValueOfCssProperty("height");

            Assert.IsTrue(height.StartsWith("49.3"), "height (\"" + left + "\") should start with \"49.3\".");
            Assert.AreEqual(r2.Size, new Size(49, 49));
        }
Exemplo n.º 28
0
        //[Test]
        //[Category("Javascript")]
        //[Ignore]
        public void CanClickOnSuckerFishMenuItem()
        {
            driver.Url = javascriptPage;

            IRenderedWebElement element = (IRenderedWebElement)driver.FindElement(By.Id("menu1"));

            if (!Platform.CurrentPlatform.IsPlatformType(PlatformType.Windows))
            {
                Assert.Ignore("Skipping test: Simulating hover needs native events");
            }

            IRenderedWebElement target = (IRenderedWebElement)driver.FindElement(By.Id("item1"));

            Assert.IsTrue(target.Displayed);
            target.Click();

            String text = driver.FindElement(By.Id("result")).Text;

            Assert.IsTrue(text.Contains("item 1"));
        }
Exemplo n.º 29
0
        public void ShouldAllowUsersToHoverOverElements()
        {
            driver.Url = javascriptPage;

            IRenderedWebElement element = (IRenderedWebElement)driver.FindElement(By.Id("menu1"));

            if (!Platform.CurrentPlatform.IsPlatformType(PlatformType.Windows))
            {
                Assert.Ignore("Skipping test: Simulating hover needs native events");
            }

            IRenderedWebElement item = (IRenderedWebElement)driver.FindElement(By.Id("item1"));

            Assert.AreEqual("", item.Text);

            ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].style.background = 'green'", element);
            element.Hover();

            item = (IRenderedWebElement)driver.FindElement(By.Id("item1"));
            Assert.AreEqual("Item 1", item.Text);
        }
Exemplo n.º 30
0
        public void ShouldAllowUsersToDragAndDropToElementsOffTheCurrentViewPort()
        {
            driver.Url = dragAndDropPage;

            IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
            int height             = Convert.ToInt32(js.ExecuteScript("return window.outerHeight;"));
            int width = Convert.ToInt32(js.ExecuteScript("return window.outerWidth;"));

            js.ExecuteScript("window.resizeTo(300, 300);");

            try
            {
                driver.Url = dragAndDropPage;
                IRenderedWebElement img = (IRenderedWebElement)driver.FindElement(By.Id("test3"));
                Point expectedLocation  = drag(img, img.Location, 100, 100);
                Assert.AreEqual(expectedLocation, img.Location);
            }
            finally
            {
                js.ExecuteScript("window.resizeTo(arguments[0], arguments[1]);", width, height);
            }
        }
Exemplo n.º 31
0
 /// <summary>
 /// Drag and Drop an element to another element
 /// </summary>
 /// <param name="element">Element you wish to drop on</param>
 public virtual void DragAndDropOn(IRenderedWebElement element)
 {
     Point currentLocation = Location;
     Point destination = element.Location;
     DragAndDropBy(destination.X - currentLocation.X, destination.Y - currentLocation.Y);
 }
Exemplo n.º 32
0
        /// <summary>
        /// Drag and Drop an element to another element.
        /// </summary>
        /// <param name="element">Element you wish to drop on.</param>
        public void DragAndDropOn(IRenderedWebElement element)
        {
            IntPtr hwnd = IntPtr.Zero;
            int x = 0;
            int y = 0;
            int width = 0;
            int height = 0;
            WebDriverResult result = NativeDriverLibrary.Instance.GetElementDetailsOnceScrolledOnToScreen(elementHandle, ref hwnd, ref x, ref y, ref width, ref height);
            ResultHandler.VerifyResultCode(result, "Unable to determine location once scrolled on to screen");

            int startX = x + (width / 2);
            int startY = y + (height / 2);

            NativeDriverLibrary.Instance.MouseDownAt(hwnd, startX, startY);

            SafeInternetExplorerWebElementHandle other = ((InternetExplorerWebElement)element).Wrapper;
            result = NativeDriverLibrary.Instance.GetElementDetailsOnceScrolledOnToScreen(other, ref hwnd, ref x, ref y, ref width, ref height);
            ResultHandler.VerifyResultCode(result, "Unable to determine location of target once scrolled on to screen");

            int endX = x + (width / 2);
            int endY = y + (height / 2);

            int duration = driver.Manage().Speed.Timeout;
            NativeDriverLibrary.Instance.MouseMoveTo(hwnd, duration, startX, startY, endX, endY);
            NativeDriverLibrary.Instance.MouseUpAt(hwnd, endX, endY);
        }
Exemplo n.º 33
0
 /// <summary>
 /// Drag and Drop onto another element. Not Supported in Chrome yet
 /// </summary>
 /// <param name="element">Element to be dropped on</param>
 public override void DragAndDropOn(IRenderedWebElement element)
 {
     throw new NotImplementedException("Not yet supported in Chrome");
 }
 /// <summary>
 /// Drag and Drop an element to another element
 /// </summary>
 /// <param name="element">Element you wish to drop on</param>
 public void DragAndDropOn(IRenderedWebElement element)
 {
     IRenderedWebElement renderedElement = WrappedElement as IRenderedWebElement;
     renderedElement.DragAndDropOn(element);
 }
Exemplo n.º 35
0
 private Point drag(IRenderedWebElement elem, Point initialLocation, int moveRightBy, int moveDownBy)
 {
     Point expectedLocation = new Point(initialLocation.X, initialLocation.Y);
     elem.DragAndDropBy(moveRightBy, moveDownBy);
     expectedLocation.Offset(moveRightBy, moveDownBy);
     return expectedLocation;
 }