//an boundary constraint (to prevent the user from observing the future and the past(e.g. before 13.7Ga BC) )
        public void MaxZoom(double lt, double rt, int zoom)
        {
            IWebElement buttonZoomOut = Driver.FindElement(By.Id("buttonZoomOut"));
            Actions actions = new Actions(Driver);

            (Driver as IJavaScriptExecutor).ExecuteScript("$(\"#axis\").axis(\"setRange\"," + lt + "," + rt + ");");

            actions.Build();
            actions.MoveToElement(buttonZoomOut, 0, 0);
            for (int k = 0; k < zoom; k++)
            {
                actions.Click();
            }
            actions.Release();
            actions.Perform();

            var afterZoom = (Driver as IJavaScriptExecutor).
            ExecuteScript("return $(\"#axis\").axis(\"getRange\");");

            var afterzooml = Convert.ToDouble((afterZoom as Dictionary<string, object>)["left"]);
            var afterzoomr = Convert.ToDouble((afterZoom as Dictionary<string, object>)["right"]);

            Assert.IsTrue(afterzooml >= -13700000000.0);
            Assert.IsTrue(afterzoomr <= 0.0);
        }
예제 #2
0
        private void PerformDragAndDropWithMouse()
        {
            driver.Url = draggableLists;

            IWebElement dragReporter = driver.FindElement(By.Id("dragging_reports"));

            IWebElement toDrag   = driver.FindElement(By.Id("rightitem-3"));
            IWebElement dragInto = driver.FindElement(By.Id("sortable1"));

            Actions actionProvider = new Actions(driver);
            IAction holdItem       = actionProvider.ClickAndHold(toDrag).Build();

            IAction moveToSpecificItem = actionProvider.MoveToElement(driver.FindElement(By.Id("leftitem-4"))).Build();

            IAction moveToOtherList = actionProvider.MoveToElement(dragInto).Build();

            IAction drop = actionProvider.Release(dragInto).Build();

            Assert.AreEqual("Nothing happened.", dragReporter.Text);

            holdItem.Perform();
            moveToSpecificItem.Perform();
            moveToOtherList.Perform();

            Assert.IsTrue(Regex.IsMatch(dragReporter.Text, "Nothing happened\\. (?:DragOut *)+"));
            drop.Perform();
        }
        /// <summary>
        /// Click and hold an element
        /// </summary>
        /// <param name="element">Page element</param>
        /// <param name="ms">Number of milliseconds to hold down the click</param>
        public static void ClickLong(this IBrowser browser, PageElement element, int ms)
        {
            var action = new Actions(browser.IWebDriver);

            action.ClickAndHold(browser.Find(element)).Build().Perform();
            Thread.Sleep(ms);
            action.Release(browser.Find(element)).Build().Perform();
        }
        public void DragSlider()
        {
            // Wait for element
            driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 45));

            // Grab the element and then feed it to the actions statement below.
            IWebElement element = driver.FindElement(By.XPath("//div[@id='aj_sl1']/div[2]/img"));

            Console.WriteLine(element.ToString());
            Console.ReadLine();

            Actions actionsProvider = new Actions(driver);
            actionsProvider.DragAndDropToOffset(element, 50, 0);

            actionsProvider.ClickAndHold(element);
            actionsProvider.MoveByOffset(50, 0);
            actionsProvider.Release(element);
        }
예제 #5
0
        public void ShouldAllowDragAndDrop()
        {
            driver.Url = droppableItems;

            DateTime waitEndTime = DateTime.Now.Add(TimeSpan.FromSeconds(15));

            while (!IsElementAvailable(driver, By.Id("draggable")) && (DateTime.Now < waitEndTime))
            {
                System.Threading.Thread.Sleep(200);
            }

            if (!IsElementAvailable(driver, By.Id("draggable")))
            {
                throw new Exception("Could not find draggable element after 15 seconds.");
            }

            IWebElement toDrag   = driver.FindElement(By.Id("draggable"));
            IWebElement dropInto = driver.FindElement(By.Id("droppable"));

            Actions actionProvider = new Actions(driver);

            IAction holdDrag = actionProvider.ClickAndHold(toDrag).Build();

            IAction move = actionProvider.MoveToElement(dropInto).Build();

            IAction drop = actionProvider.Release(dropInto).Build();

            holdDrag.Perform();
            move.Perform();
            drop.Perform();

            dropInto = driver.FindElement(By.Id("droppable"));
            string text = dropInto.FindElement(By.TagName("p")).Text;

            Assert.AreEqual("Dropped!", text);
        }
예제 #6
0
        public void ShouldAllowDragAndDrop()
        {
            driver.Url = droppableItems;

            DateTime waitEndTime = DateTime.Now.Add(TimeSpan.FromSeconds(15));

            while (!IsElementAvailable(driver, By.Id("draggable")) && (DateTime.Now < waitEndTime))
            {
                System.Threading.Thread.Sleep(200);
            }

            if (!IsElementAvailable(driver, By.Id("draggable")))
            {
                throw new Exception("Could not find draggable element after 15 seconds.");
            }

            IWebElement toDrag = driver.FindElement(By.Id("draggable"));
            IWebElement dropInto = driver.FindElement(By.Id("droppable"));

            Actions actionProvider = new Actions(driver);

            IAction holdDrag = actionProvider.ClickAndHold(toDrag).Build();

            IAction move = actionProvider.MoveToElement(dropInto).Build();

            IAction drop = actionProvider.Release(dropInto).Build();

            holdDrag.Perform();
            move.Perform();
            drop.Perform();

            dropInto = driver.FindElement(By.Id("droppable"));
            string text = dropInto.FindElement(By.TagName("p")).Text;

            Assert.AreEqual("Dropped!", text);
        }
예제 #7
0
        private void PerformDragAndDropWithMouse()
        {
            driver.Url = draggableLists;

            IWebElement dragReporter = driver.FindElement(By.Id("dragging_reports"));

            IWebElement toDrag = driver.FindElement(By.Id("rightitem-3"));
            IWebElement dragInto = driver.FindElement(By.Id("sortable1"));

            Actions actionProvider = new Actions(driver);
            IAction holdItem = actionProvider.ClickAndHold(toDrag).Build();

            IAction moveToSpecificItem = actionProvider.MoveToElement(driver.FindElement(By.Id("leftitem-4"))).Build();

            IAction moveToOtherList = actionProvider.MoveToElement(dragInto).Build();

            IAction drop = actionProvider.Release(dragInto).Build();

            Assert.AreEqual("Nothing happened.", dragReporter.Text);

            holdItem.Perform();
            moveToSpecificItem.Perform();
            moveToOtherList.Perform();

            Assert.AreEqual("Nothing happened. DragOut", dragReporter.Text);
            drop.Perform();
        }
예제 #8
0
        // Mark this test with TestMethod attribute, if need to check error
        // of mouse move actions in Selenium.
        public void TestGestures_SeleniumMouseMoveError()
        {
            Dictionary<string, object> offset;

            const int startX = 100;
            const int startY = 100;

            Actions action = new Actions(Driver);
            action.MoveToElement(vcPageObj.VirtualCanvas, startX, startY).Perform();

            for (int i = 0; i < 101; i++)
            {
                GoToUrl();

                action.Build();
                action.ClickAndHold();
                action.MoveByOffset(i, i);
                action.Release();
                action.MoveByOffset(-i, -i);
                action.Perform();

                offset = ExecuteScriptGetJson("return offset;");
                Console.WriteLine("Expected offset ({0}, {1}); Observed offset: ({2}, {3});", i, i, offset["xOffset"], offset["yOffset"]);
            }
        }
        ////inner zoom not deeper 1 day
        public void MinZoomDay(int sYear, int sMonth, int sDay, int eYear, int eMonth, int eDay, double l, int zoom)
        {
            IWebElement buttonZoomIn = Driver.FindElement(By.Id("buttonZoomIn"));
            Actions actions = new Actions(Driver);

            var d = (Driver as IJavaScriptExecutor).ExecuteScript
                        ("return $(\"#axis\").axis(\"getYearsBetweenDates\"," +
                        sYear + "," + sMonth + "," + sDay + "," + eYear + "," + eMonth + "," + eDay + ");");

            (Driver as IJavaScriptExecutor).ExecuteScript("$(\"#axis\").axis(\"setPresent\"," + sYear + "," + sMonth + "," + sDay + ");");

            double betwenDays = Convert.ToDouble(d);
            double r = betwenDays + l;
            (Driver as IJavaScriptExecutor).ExecuteScript("$(\"#axis\").axis(\"setRange\"," + l + "," + r + ");");

            actions.Build();
            actions.MoveToElement(buttonZoomIn, 0, 0);
            for (int k = 0; k < zoom; k++)
            {
                actions.Click();
            }
            actions.Release();
            actions.Perform();

            var afterZoom = (Driver as IJavaScriptExecutor).
            ExecuteScript("return $(\"#axis\").axis(\"getRange\");");
            var azl = Convert.ToDouble((afterZoom as Dictionary<string, object>)["left"]);
            var azr = Convert.ToDouble((afterZoom as Dictionary<string, object>)["right"]);
            double z = azr - azl;

            double d1 = OneDay(1233, 3, 4, 5);
            double d2 = OneDay(23, 8, 17, 18);
            double d3 = OneDay(2005, 11, 1, 2);
            Assert.IsTrue(z >= d1);
            Assert.IsTrue(z >= d2);
            Assert.IsTrue(z >= d3);
        }
예제 #10
0
        // zoom out
        public void ZoomOut(double l, double r)
        {
            IWebElement buttonZoomOut = Driver.FindElement(By.Id("buttonZoomOut"));
            Actions actions = new Actions(Driver);

            (Driver as IJavaScriptExecutor).ExecuteScript("$(\"#axis\").axis(\"setRange\"," + l + "," + r + ");");
            var beforeZoomOut = (Driver as IJavaScriptExecutor).
            ExecuteScript("return $(\"#axis\").axis(\"getRange\");");
            var bzl = Convert.ToDouble((beforeZoomOut as Dictionary<string, object>)["left"]);
            var bzr = Convert.ToDouble((beforeZoomOut as Dictionary<string, object>)["right"]);
            double z1 = bzr - bzl;

            actions.Build();
            actions.MoveToElement(buttonZoomOut, 0, 0);
            actions.Click();
            actions.Release();
            actions.Perform();

            var afterZoomOut = (Driver as IJavaScriptExecutor).
            ExecuteScript("return $(\"#axis\").axis(\"getRange\");");
            var azl = Convert.ToDouble((afterZoomOut as Dictionary<string, object>)["left"]);
            var azr = Convert.ToDouble((afterZoomOut as Dictionary<string, object>)["right"]);
            double z2 = azr - azl;

            if (z1 <= OneDay(134, 5, 2, 4))
            {
                Assert.IsTrue(z1 <= z2);
            }
            else
            {
                Assert.IsTrue(z1 < z2);
            }
        }
예제 #11
0
        public void TestZoomOutMarker()
        {
            GoToUrl();

            IWebElement buttonHelper = Driver.FindElement(By.Id("buttonHelper"));
            IWebElement buttonZoomMarkerOut = Driver.FindElement(By.Id("buttonZoomMarkerOut"));
            Actions actions = new Actions(Driver);

            actions.Build();
            actions.MoveToElement(buttonHelper, 0, 0);
            actions.Click();

            var afterHelper = (Driver as IJavaScriptExecutor).
            ExecuteScript("return $(\"#axis\").axis(\"getRange\");");
            var ahl = Convert.ToDouble((afterHelper as Dictionary<string, object>)["left"]);
            var ahr = Convert.ToDouble((afterHelper as Dictionary<string, object>)["right"]);
            double z1 = ahr - ahl;

            actions.MoveToElement(buttonZoomMarkerOut, 0, 0);
            actions.Click();
            actions.Release();
            actions.Perform();

            var afterZoomOutMarker = (Driver as IJavaScriptExecutor).
            ExecuteScript("return $(\"#axis\").axis(\"getRange\");");
            var azml = Convert.ToDouble((afterZoomOutMarker as Dictionary<string, object>)["left"]);
            var azmr = Convert.ToDouble((afterZoomOutMarker as Dictionary<string, object>)["right"]);
            double z2 = azmr - azml;

            Assert.IsTrue(ahl > azml && ahr < azmr && z1 < z2);
        }
예제 #12
0
        //inner zoom not deeper 4 decimal fraction digits
        public void MinZoomNoMoreFourSigns(double x1, double x2, int zoom)
        {
            IWebElement buttonZoomIn = Driver.FindElement(By.Id("buttonZoomIn"));
            Actions actions = new Actions(Driver);

            (Driver as IJavaScriptExecutor).ExecuteScript("$(\"#axis\").axis(\"setRange\"," + x1 + "," + x2 + ");");

            actions.Build();
            actions.MoveToElement(buttonZoomIn, 0, 0);
            for (int k = 0; k < zoom; k++)
            {
                actions.Click();
            }
            actions.Release();
            actions.Perform();

            var afterZoom = (Driver as IJavaScriptExecutor).
            ExecuteScript("return $(\"#axis\").axis(\"getRange\");");

            var afterzooml = Convert.ToDouble((afterZoom as Dictionary<string, object>)["left"]);
            var afterzoomr = Convert.ToDouble((afterZoom as Dictionary<string, object>)["right"]);
            double aftern = afterzoomr - afterzooml;

            int decimaldigitsl = Counter(afterzooml);
            int decimaldigitsr = Counter(afterzoomr);
            int decimaldigitsn = Counter(aftern);

            Assert.IsTrue(decimaldigitsl <= 4 && decimaldigitsr <= 4);
            Assert.IsTrue(decimaldigitsn <= 4);
        }
예제 #13
0
 public IMouseActions Release(BaseElement onElement)
 {
     actions.Release(onElement.IWebElement);
     return(this);
 }
예제 #14
0
 /// <summary>
 /// Releases the element from a ClickAndHold.
 /// </summary>
 /// <param name="element"></param>
 public static void Release(this IWebElement element)
 {
     Actions act = new Actions(Browser.Driver);
     act.Release(element).Perform();
 }
예제 #15
-1
        public void TestMouse_MoveAndClick_Rectangle()
        {
            GoToUrl();

            IWebElement vc = Driver.FindElement(By.Id("vc"));
            IWebElement button = Driver.FindElement(By.Id("button"));

            var rectCenterX = Convert.ToDouble((Driver as IJavaScriptExecutor).ExecuteScript("return rectCenterX;"));
            var scale = Convert.ToDouble((Driver as IJavaScriptExecutor).ExecuteScript("return scale;"));

            Actions actions = new Actions(Driver);
            // building mouse moves on the virtual canvas element
            actions.Build();
            actions.MoveToElement(vc, vc.Size.Width / 2 + (int)(rectCenterX / scale), vc.Size.Height / 2);
            actions.Click();
            actions.MoveToElement(button, 0, 0);
            actions.Release();
            actions.Perform();

            var res = (Driver as IJavaScriptExecutor).ExecuteScript("return isRectMovedIn;");
            Assert.AreNotEqual(0.0, Convert.ToDouble(res));
            res = (Driver as IJavaScriptExecutor).ExecuteScript("return isRectMovedOut;");
            Assert.AreNotEqual(0.0, Convert.ToDouble(res));
            res = (Driver as IJavaScriptExecutor).ExecuteScript("return isRectClicked;");
            Assert.AreNotEqual(0.0, Convert.ToDouble(res));
        }