Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref = "Actions"/> class.
        /// </summary>
        /// <param name = "driver">The <see cref = "IWebDriver"/> object on which the actions built will be performed.</param>
        public Actions(IWebDriver driver)
        {
            this.driver = driver;
            IHasInputDevices inputDevicesDriver = driver as IHasInputDevices;

            if (inputDevicesDriver == null)
            {
                IWrapsDriver wrapper = driver as IWrapsDriver;
                while (wrapper != null)
                {
                    inputDevicesDriver = wrapper.WrappedDriver as IHasInputDevices;
                    if (inputDevicesDriver != null)
                    {
                        this.driver = wrapper.WrappedDriver;
                        break;
                    }

                    wrapper = wrapper.WrappedDriver as IWrapsDriver;
                }
            }

            if (inputDevicesDriver == null)
            {
                throw new ArgumentException("The IWebDriver object must implement or wrap a driver that implements IHasInputDevices.", "driver");
            }

            this.keyboard = inputDevicesDriver.Keyboard;
            this.mouse    = inputDevicesDriver.Mouse;
        }
Пример #2
0
        public void ShouldAllowUsersToHoverOverElements()
        {
            driver.Url = javascriptPage;

            IWebElement element = 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;
            }

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

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

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

            actionBuilder.MoveToElement(element).Perform();

            item = driver.FindElement(By.Id("item1"));
            Assert.AreEqual("Item 1", item.Text);
        }
Пример #3
0
        public void TestDragAndDrop3()
        {
            RemoteWebElement dragElement = _chromeDriver.FindElementById("draggable") as RemoteWebElement;

            Assert.AreNotEqual(dragElement, null);

            RemoteWebElement dropElement = _chromeDriver.FindElementById("droppable") as RemoteWebElement;

            Assert.AreNotEqual(dragElement, null);

            Actions actions = new Actions(_chromeDriver);

            IHasInputDevices inputDevices = (IHasInputDevices)_chromeDriver;



            inputDevices.Mouse.MouseMove(dragElement.Coordinates);

            inputDevices.Mouse.MouseDown(dragElement.Coordinates);

            inputDevices.Mouse.MouseMove(dragElement.Coordinates, 1, 1);


            //
            inputDevices.Mouse.MouseMove(dropElement.Coordinates);
            inputDevices.Mouse.MouseUp(dropElement.Coordinates);
        }
Пример #4
0
        /// <summary>
        /// Moves the mouse to the element and offset specified.
        /// </summary>
        /// <returns>This command always returns <see langword="null"/>.</returns>
        public override object Execute()
        {
            IHasInputDevices hasInputDevicesDriver = this.Session.Driver as IHasInputDevices;
            IMouse           mouse = hasInputDevicesDriver.Mouse;

            ICoordinates elementLocation = null;

            if (this.elementProvided)
            {
                IWebElement element          = this.Session.KnownElements.GetElement(this.elementId);
                ILocatable  locatableElement = element as ILocatable;
                elementLocation = locatableElement.Coordinates;
            }

            if (this.offsetsProvided)
            {
                mouse.MouseMove(elementLocation, this.offsetX, this.offsetY);
            }
            else
            {
                mouse.MouseMove(elementLocation);
            }

            mouse.MouseDown(null);
            return(null);
        }
Пример #5
0
        //******************************************
        //public virtual void MoveMouseTo()
        //{
        //    Actions action = new Actions(this.Page.Driver);
        //    action.MoveToElement(this.Element).Build().Perform();
        //}
        //******************************************

        public virtual void MoveMouseTo(int centerOffsetX, int centerOffsetY)
        {
            IHasInputDevices device = this.Page.Driver as IHasInputDevices;

            ICoordinates point = new Coordinates(this.CenterCoordinates, centerOffsetX, centerOffsetY);

            if (point == null)
            {
                throw new InvalidOperationException(string.Format("Невозможно получить координаты элемента (XPath: {0}) для имитации события MouseUp.", this.XPath));
            }

            Size size = this.Element.Size;

            Console.WriteLine("Имитация MouseMove() в [{0};{1}]", point.LocationInDom.X, point.LocationInDom.Y);

            ILocatable hoverItem = (ILocatable)this.Page.Driver.FindElement(By.XPath(this.XPath));

            if (hoverItem == null)
            {
                throw new InvalidOperationException(string.Format("Невозможно получить координаты элемента (XPath: {0}) для имитации события MouseUp.", this.XPath));
            }

            device.Mouse.MouseMove(hoverItem.Coordinates);
            //device.Mouse.MouseMove(point, 0, 0);
        }
Пример #6
0
        /// <summary>
        /// Presses the left mouse button at the last coordinates set for the driver.
        /// </summary>
        /// <returns>This command always returns <see langword="null"/>.</returns>
        public override object Execute()
        {
            IHasInputDevices hasInputDevicesDriver = this.Session.Driver as IHasInputDevices;
            IMouse           mouse = hasInputDevicesDriver.Mouse;

            mouse.MouseDown(null);
            return(null);
        }
        /// <summary>
        /// Sends keys to the element referenced by this <see cref="CommandHandler"/>.
        /// </summary>
        /// <returns>This command always returns <see langword="null"/>.</returns>
        public override object Execute()
        {
            IHasInputDevices inputDevicesDriver = Session.Driver as IHasInputDevices;
            IKeyboard        keyboard           = inputDevicesDriver.Keyboard;

            keyboard.SendKeys(this.KeysToSend);
            return(null);
        }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Actions"/> class.
        /// </summary>
        /// <param name="driver">The <see cref="IWebDriver"/> object on which the actions built will be performed.</param>
        public Actions(IWebDriver driver)
        {
            IHasInputDevices inputDevicesDriver = driver as IHasInputDevices;

            if (inputDevicesDriver != null)
            {
                this.keyboard = inputDevicesDriver.Keyboard;
                this.mouse    = inputDevicesDriver.Mouse;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultActionSequenceBuilder"/> class.
        /// </summary>
        /// <param name="driver">The <see cref="IWebDriver"/> object on which the actions built will be performed.</param>
        public DefaultActionSequenceBuilder(IWebDriver driver)
        {
            IHasInputDevices inputDevicesDriver = driver as IHasInputDevices;

            if (inputDevicesDriver != null)
            {
                this.keyboard = inputDevicesDriver.Keyboard;
                this.mouse    = inputDevicesDriver.Mouse;
            }
        }
Пример #10
0
        public virtual void MouseUp(int centerOffsetX, int centerOffsetY)
        {
            IHasInputDevices device = this.Page.Driver as IHasInputDevices;

            ICoordinates point = new Coordinates(this.CenterCoordinates, centerOffsetX, centerOffsetY);

            if (point == null)
            {
                throw new InvalidOperationException(string.Format("Невозможно получить координаты элемента (XPath: {0}) для имитации события MouseUp.", this.XPath));
            }

            Console.WriteLine("Имитация MouseUp() в [{0};{1}]", point.LocationInDom.X, point.LocationInDom.Y);

            device.Mouse.MouseUp(point);
        }
Пример #11
0
        /// <summary>
        /// Clicks at the last coordinates set for the driver.
        /// </summary>
        /// <returns>This command always returns <see langword="null"/>.</returns>
        public override object Execute()
        {
            IHasInputDevices hasInputDevicesDriver = this.Session.Driver as IHasInputDevices;
            IMouse           mouse = hasInputDevicesDriver.Mouse;

            if (this.leftMouseButton)
            {
                mouse.Click(null);
            }
            else
            {
                mouse.ContextClick(null);
            }

            return(null);
        }
Пример #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Actions"/> class.
        /// </summary>
        /// <param name="driver">The <see cref="IWebDriver"/> object on which the actions built will be performed.</param>
        public Actions(IWebDriver driver)
        {
            //this.driver = driver;
            IHasInputDevices inputDevicesDriver = GetDriverAs <IHasInputDevices>(driver);

            if (inputDevicesDriver == null)
            {
                throw new ArgumentException("The IWebDriver object must implement or wrap a driver that implements IHasInputDevices.", "driver");
            }

            IActionExecutor actionExecutor = GetDriverAs <IActionExecutor>(driver);

            if (actionExecutor == null)
            {
                throw new ArgumentException("The IWebDriver object must implement or wrap a driver that implements IActionExecutor.", "driver");
            }

            this.keyboard       = inputDevicesDriver.Keyboard;
            this.mouse          = inputDevicesDriver.Mouse;
            this.actionExecutor = actionExecutor;
        }
Пример #13
0
        public Actions(IWebDriver driver)
        {
            IHasInputDevices hasInputDevices = driver as IHasInputDevices;

            if (hasInputDevices == null)
            {
                for (IWrapsDriver wrapsDriver = driver as IWrapsDriver; wrapsDriver != null; wrapsDriver = (wrapsDriver.WrappedDriver as IWrapsDriver))
                {
                    hasInputDevices = (wrapsDriver.WrappedDriver as IHasInputDevices);
                    if (hasInputDevices != null)
                    {
                        break;
                    }
                }
            }
            if (hasInputDevices == null)
            {
                throw new ArgumentException("The IWebDriver object must implement or wrap a driver that implements IHasInputDevices.", "driver");
            }
            this.keyboard = hasInputDevices.Keyboard;
            this.mouse    = hasInputDevices.Mouse;
        }
Пример #14
0
        public void TestDragAndDrop4()
        {
            RemoteWebElement dragElement = _chromeDriver.FindElementById("draggable") as RemoteWebElement;

            Assert.AreNotEqual(dragElement, null);

            RemoteWebElement dropElement = _chromeDriver.FindElementById("droppable") as RemoteWebElement;

            Assert.AreNotEqual(dragElement, null);

            Actions actions = new Actions(_chromeDriver);

            IHasInputDevices inputDevices = (IHasInputDevices)_chromeDriver;

            inputDevices.Mouse.Click(dragElement.Coordinates);

            inputDevices.Mouse.MouseMove(dragElement.Coordinates);

            inputDevices.Mouse.MouseDown(dragElement.Coordinates);

            //
            _chromeDriver.ExecuteScript(jsDragStart, dragElement);

            _chromeDriver.ExecuteScript(jsDrag, dragElement, dragElement.Location.X, dragElement.Location.Y);

            //
            inputDevices.Mouse.MouseMove(dropElement.Coordinates);

            //
            _chromeDriver.ExecuteScript(jsDragOver, dropElement, dropElement.Location.X, dropElement.Location.Y);
            //
            _chromeDriver.ExecuteScript(jsDrop, dropElement, dropElement.Location.X, dropElement.Location.Y);

            //
            _chromeDriver.ExecuteScript(jsDrop, dropElement);
            inputDevices.Mouse.MouseUp(dropElement.Coordinates);
        }
        private IActionSequenceBuilder GetBuilder()
        {
            IHasInputDevices inputDevicesDriver = driver as IHasInputDevices;

            return(inputDevicesDriver.ActionBuilder);
        }
Пример #16
0
 public AddressBookPage(IWebDriver driver, IFindsByCssSelector cssSelector, IHasInputDevices inputDevices)
 {
     this.driver = driver;
     this.cssSelector = cssSelector;
     this.inputDevices = inputDevices;
 }