public void TestGestures_MouseActivity_GestureBodyIsCorrect() { Dictionary<string, object> offset, scale; const int offsetX = 100; const int offsetY = 100; // Make pan gesture and check, that body of gesture is correct. action = new ActionsExtension(Driver); action.MoveByOffset(offsetX, offsetY).Perform(); action.ClickAndHold(); action.MoveByOffset(offsetX, offsetY); action.Release(); action.Perform(); vcPageObj.WaitAnimation(); offset = ExecuteScriptGetJson("return offset;"); Assert.AreEqual((double)offsetX, Convert.ToDouble(offset["xOffset"]), 5); Assert.AreEqual((double)offsetY, Convert.ToDouble(offset["yOffset"]), 5); action.SetDefault(); // Make zoom gesture and check, that body of gesture is correct. GoToUrl(); action.MoveByOffset(offsetX, offsetY).Perform(); action.DoubleClick(); action.Perform(); vcPageObj.WaitAnimation(); scale = ExecuteScriptGetJson("return scale;"); Assert.AreEqual((double)offsetX, Convert.ToDouble(scale["xOrigin"]), 10); Assert.AreEqual((double)offsetY, Convert.ToDouble(scale["yOrigin"]), 10); }
public void MinZoom(int sYear, int sMonth, int sDay, int eYear, int eMonth, int eDay, int zoom, double l) { action = new ActionsExtension(Driver); IWebElement vc = Driver.FindElement(By.Id("vc")); const int offsetX = 100; const int offsetY = 100; var d = (Driver as IJavaScriptExecutor).ExecuteScript ("return $(\"#axis\").axis(\"getYearsBetweenDates\"," + sYear + "," + sMonth + "," + sDay + "," + eYear + "," + eMonth + "," + eDay + ");"); double n = Convert.ToDouble(d); double r = n + l; (Driver as IJavaScriptExecutor).ExecuteScript("$(\"#axis\").axis(\"setRange\"," + l + "," + r + ");"); action.MoveToElement(vcPageObj.VirtualCanvas, offsetX, offsetY).Perform(); //action.MoveByOffset(offsetX, offsetY); for (int k = 0; k < zoom; k++) { action.DoubleClick(); } action.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; int a1 = 123, a2 = 2, a3 = 3, b3 = 4; var v = (Driver as IJavaScriptExecutor).ExecuteScript ("return $(\"#axis\").axis(\"getYearsBetweenDates\"," + a1 + "," + a2 + "," + a3 + "," + a1 + "," + a2 + "," + b3 + ");"); double w = Convert.ToDouble(v); Assert.IsTrue(z > w); }
public void TestViewportController_ZoomForcesViewportToExceedMinPermittedZoomIn_ViewportDoesNotExceedMinPermittedZoomIn() { GoToUrl(); double zoomFactor = ExecuteScriptGetNumber(@"return window.zoomLevelFactor;"); dynamic timelines = ExecuteScript("return window.deeperZoomConstraints;"); for (int i = 0; i < timelines.Count; i++) { /* Arrange * Set up the viewport such that a zoom gesture * forces the viewport to exceed the minimum zoomin level. */ Driver.Navigate().Refresh(); IWebElement vcElem = Driver.FindElement(By.Id("vc")); dynamic timeline = timelines[i]; double left = timeline["left"]; double right = timeline["right"]; double minScale = timeline["scale"]; double aboveMinScale = minScale * zoomFactor; // for all scale in [minScale, aboveMinScale) => scale / zoomFactor < minScale Random rnd = new Random(); double scale = minScale + rnd.NextDouble() * (aboveMinScale - minScale); var vc = new VirtualCanvasComponent(Driver); vc.SetVisible(new JsVisible((left + right) / 2, 0, scale)); vc.UpdateViewport(); /* Act * ZoomIn. */ ActionsExtension act = new ActionsExtension(Driver); act.MoveToElement(vcElem, 10, 10); act.DoubleClick(); act.Perform(); vc.WaitAnimation(); /* Assert * Verify that the viewport after zooming doesn't * exceed the minimum zoomin level. */ var vp = vc.GetViewport(); Assert.IsTrue(vp.Scale >= minScale); } }
public void TestViewportController_ZoomForcesViewportToExceedMaxPermittedZoomOut_ViewportDoesNotExceedMaxPermittedZoomOut() { /* Arrange * Set up the viewport such that a zoom gesture * forces the viewport to exceed maximum zoomout level. */ GoToUrl(); IWebElement vcElem = Driver.FindElement(By.Id("vc")); double width = vcElem.Size.Width - 2; // border of 1 px on each side double additionalPermitedPixels = ExecuteScriptGetNumber(@"return window.timelinesAbsenceInterval;"); double zoomFactor = ExecuteScriptGetNumber(@"return window.zoomLevelFactor;"); double maxScaleWithoutPadding = 13.7 * Ga / width; double maxScale = (13.7 * Ga + 2 * additionalPermitedPixels * maxScaleWithoutPadding) / width; double belowMaxScale = maxScale / zoomFactor; // for all scale in (belowMaxScale, maxScale] => scale * zoomFactor > maxScale Random rnd = new Random(); double scale = belowMaxScale + rnd.NextDouble() * (maxScale - belowMaxScale); var vc = new VirtualCanvasComponent(Driver); vc.SetVisible(new JsVisible(-13.7 * Ga / 2, 0, scale)); vc.UpdateViewport(); /* Act * ZoomOut. */ ExecuteScript(@"setZoomOut()"); ActionsExtension act = new ActionsExtension(Driver); act.MoveToElement(vcElem, 10, 10); act.DoubleClick(); act.Perform(); vc.WaitAnimation(); /* Assert * Verify that the viewport after zooming doesn't * exceed the maximum zoomout level. */ var vp = vc.GetViewport(); Assert.IsTrue(vp.Scale <= maxScale); }
public void TestGestures_MouseActivity_GesturesGenerated() { const int offsetX = 100; const int offsetY = 100; action = new ActionsExtension(Driver); bool zoomHandled = (bool)ExecuteScript("return zoomHandled;"); ; bool panHandled = (bool)ExecuteScript("return panHandled;"); bool pinHandled = (bool)ExecuteScript("return pinHandled;"); Assert.IsFalse(zoomHandled); Assert.IsFalse(panHandled); Assert.IsFalse(pinHandled); // Pin and pan gestures. action.MoveToElement(vcPageObj.VirtualCanvas, offsetX, offsetY); action.ClickAndHold(); action.MoveByOffset(offsetX, offsetY); action.Release(); action.Perform(); vcPageObj.WaitAnimation(); zoomHandled = (bool)ExecuteScript("return zoomHandled;"); panHandled = (bool)ExecuteScript("return panHandled;"); pinHandled = (bool)ExecuteScript("return pinHandled;"); Assert.IsFalse(zoomHandled); Assert.IsTrue(panHandled); Assert.IsTrue(pinHandled); // Zoom gesture. action.DoubleClick(); action.Perform(); vcPageObj.WaitAnimation(); zoomHandled = (bool)ExecuteScript("return zoomHandled;"); panHandled = (bool)ExecuteScript("return panHandled;"); pinHandled = (bool)ExecuteScript("return pinHandled;"); Assert.IsTrue(zoomHandled); Assert.IsTrue(panHandled); Assert.IsTrue(pinHandled); }
public void TestMouseBehavior_DoubleClickOnCanvas_NextLevelOfZoom() { const int offsetX = 100; const int offsetY = 100; action = new ActionsExtension(Driver); // NOTE: Uses user environment variable SELENIUM_SCR. WebDriverScreenshotMaker.SaveScreenshot(Driver, "TestMouseBehaviour", "SingleClickCanvasBefore", ImageFormat.Png, true); action.MoveToElement(vcPageObj.VirtualCanvas, offsetX, offsetY); action.DoubleClick(); action.Perform(); vcPageObj.WaitAnimation(); WebDriverScreenshotMaker.SaveScreenshot(Driver, "TestMouseBehaviour", "SingleClickCanvasAfter", ImageFormat.Png, true); }
public void TestGesture_ZoomWithInertialMotion_ViewportUpdatesCorrectly() { IWebElement vcElem = Driver.FindElement(By.Id("vc")); int width = vcElem.Size.Width; int height = vcElem.Size.Height; // center infodot as reference var vc = new VirtualCanvasComponent(Driver); vc.SetVisible(new JsVisible(-3194.8898068225376, 401.0288546497742, 0.38537988462392836)); vc.UpdateViewport(); Random rnd = new Random(); Point zoomPt = new Point(rnd.Next(0, width), rnd.Next(0, height)); JsCoordinates p1 = vc.PointScreenToVirtual(new JsCoordinates(zoomPt.X, zoomPt.Y)); ActionsExtension act = new ActionsExtension(Driver); act.MoveToElement(vcElem, Convert.ToInt32(zoomPt.X), Convert.ToInt32(zoomPt.Y)); act.DoubleClick(); act.Perform(); vc.WaitAnimation(); JsCoordinates p2 = vc.PointVirtualToScreen(p1); // Assert that the zoom-pt remains fixed after zooming. Assert.AreEqual(zoomPt.X, p2.X, 5); Assert.AreEqual(zoomPt.Y, p2.Y, 5); }
public void TestGesture_ZoomWithInertialMotion_ViewportUpdatesCorrectly() { IWebElement vcElem = Driver.FindElement(By.Id("vc")); Assert.IsNotNull(vcElem, "err: cannot find canvas element"); Assert.IsTrue(vcElem.Size.Width > 10 && vcElem.Size.Height > 10, "err: canvas size should be atleast (10px,10px) to run test"); int width = vcElem.Size.Width - 10; // assuming a max border width of 5px on each side int height = vcElem.Size.Height - 10; VirtualCanvasComponent vc = new VirtualCanvasComponent(Driver); vc.SetVisible(new JsVisible(-3194.8898068225376, 401.0288546497742, 0.38537988462392836)); vc.UpdateViewport(); Random rnd = new Random(); Point zoomPt = new Point(rnd.Next(0, width), rnd.Next(0, height)); zoomPt.Offset(5, 5); JsCoordinates p1 = vc.PointScreenToVirtual(new JsCoordinates(zoomPt.X, zoomPt.Y)); action = new ActionsExtension(Driver); action.MoveToElement(vcElem, Convert.ToInt32(zoomPt.X), Convert.ToInt32(zoomPt.Y)); action.DoubleClick(); action.Perform(); vc.WaitAnimation(); JsCoordinates p2 = vc.PointVirtualToScreen(p1); // Assert that the zoom-pt remains fixed after zooming. Assert.AreEqual(zoomPt.X, p2.X, 5); Assert.AreEqual(zoomPt.Y, p2.Y, 5); }