//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); }
protected string RightClick(IWebElement element) { var action = new OpenQA.Selenium.Interactions.Actions(myDriver); action.MoveToElement(element).ContextClick(element); action.Build().Perform(); return(null); }
/// <summary> /// Hover mouse above first element, then click on second element /// </summary> /// <param name="elementToHover">first IWebElement element</param> /// <param name="elementToClick">second IWebElement element</param> /// <returns></returns> public static IWebElement MouseHoverThenClick(this IWebElement elementToHover, IWebElement elementToClick) { OpenQA.Selenium.Interactions.Actions action = new OpenQA.Selenium.Interactions.Actions(Browser.Driver); action.MoveToElement(elementToHover); action.MoveToElement(elementToClick); action.Click(elementToClick); action.Build().Perform(); return(elementToHover); }
public string fileupload(IWebDriver driver, string pageData) { try { OpenQA.Selenium.Interactions.Actions actions = new OpenQA.Selenium.Interactions.Actions(driver); actions.MoveToElement(driver.FindElement(By.XPath("//div[@class='k-button k-upload-button']"))); actions.Click(); actions.Build().Perform(); Thread.Sleep(24000); return("Pass"); } catch (Exception ex) { return(ex.Message); } }
public void MouseActiveLeft(double left, double right, int shift) { Actions action = new Actions(Driver); IWebElement axi = Driver.FindElement(By.Id("axis")); (Driver as IJavaScriptExecutor).ExecuteScript("$(\"#axis\").axis(\"setRange\"," + left + "," + right + ");"); var before = (Driver as IJavaScriptExecutor).ExecuteScript("return $(\"#axis\").axis(\"getRange\");"); var bL = Convert.ToDouble((before as Dictionary<string, object>)["left"]); var bR = Convert.ToDouble((before as Dictionary<string, object>)["right"]); action.Build(); action.DragAndDropToOffset(axi, -shift, 0); action.Perform(); var after = (Driver as IJavaScriptExecutor).ExecuteScript("return $(\"#axis\").axis(\"getRange\");"); var aL = Convert.ToDouble((after as Dictionary<string, object>)["left"]); var aR = Convert.ToDouble((after as Dictionary<string, object>)["right"]); Assert.IsTrue(aL > bL && aR > bR); }
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); }
/// <summary> /// This method set the context of OpenQA.Selenium.Interactions.Actions field to default. /// </summary> public void SetDefault() { Actions reverseBuilder = new Actions(driver); while (log.Count != 0) { Point offset = log.Pop(); reverseBuilder.MoveByOffset(offset.X, offset.Y); } IAction action = reverseBuilder.Build(); action.Perform(); log.Clear(); }
/// <summary> /// Method to click on button and Link /// /// </summary> public void Click(Dictionary<int, string> keyWordDic = null, string data = null) { try { _testObject = WaitAndGetElement(); DateTime startTime = DateTime.Now; if (Utility.GetParameter("runbyevents").Equals("true")) { switch (Browser.BrowserName.ToLower()) { case "ie": case "iexplore": ExecuteScript(_testObject, "arguments[0].click();"); try { WaitForObjectNotPresent(Utility.GetVariable("ObjectTimeout"), Utility.GetVariable("GlobalTimeout"), keyWordDic); } catch { //Nothing to throw in this case } break; default: _testObject.Click(); break; } } else { try { // Perform Shift+Click only if Shift key is passed as Data for action sheet data in case Chrome. if ("Shift".Equals(data, StringComparison.OrdinalIgnoreCase) && Browser.BrowserName.Equals(KryptonConstants.BROWSER_CHROME, StringComparison.OrdinalIgnoreCase)) { Actions objAction = new Actions(Driver); objAction = objAction.KeyDown(Keys.Shift).Click(_testObject).KeyUp(Keys.Shift); objAction.Build(); objAction.Perform(); } else { _testObject.Click(); } // Pause here for .5 sec as on mac safari VerifyTextOnPage after this looks at the page click is on and assumes that page has been received from server // find a better way to do this if (Browser.BrowserName.Equals("safari")) Thread.Sleep(2000); } catch (ElementNotVisibleException enve) { try { ExecuteScript(_testObject, "arguments[0].click();"); } catch { throw enve; } } catch (Exception e) { if (e.Message.ToLower().Contains(Exceptions.ERROR_NORESPONSEURL)) { _testObject.Click(); } else { throw; } } } //measure total time and raise exception if timeout is more than the allowed limit DateTime finishTime = DateTime.Now; double totalTime = (finishTime - startTime).TotalSeconds; if (keyWordDic != null) foreach (string modifiervalue in keyWordDic.Values) { if (modifiervalue.ToLower().Contains("timeout=")) { double timeout = double.Parse(modifiervalue.Split('=').Last()); if (totalTime > timeout) { throw new Exception("Page load took " + totalTime.ToString(CultureInfo.InvariantCulture) + " seconds to load against expected time of " + timeout + " seconds."); } Property.Remarks = "Page load took " + totalTime.ToString(CultureInfo.InvariantCulture) + " seconds to load against expected time of " + timeout + " seconds."; } } } catch (Exception e) { if (_objDataRow.ContainsKey(KryptonConstants.TEST_OBJECT)) { KryptonException.Writeexception(e); throw new NoSuchElementException(Utility.GetCommonMsgVariable("KRYPTONERRCODE0067").Replace("{MSG3}", _objDataRow[KryptonConstants.TEST_OBJECT]).Replace("{MSG4}", _objDataRow["parent"]).Replace("{MSG1}", AttributeType).Replace("{MSG2}", Attribute).Replace("{ErrorMsg}", e.Message)); // added by } throw; } }
public void AddNewModuleUsingDragAndDrop(string moduleName, string location) { Trace.WriteLine(BasePage.TraceLevelComposite + "Add a Module, Using Drag&Drop:"); WaitForElement(By.XPath(moduleName)).ScrollIntoView().WaitTillVisible().Click(); Trace.WriteLine(TraceLevelPage + "Mouse over module: '" + moduleName); Actions action = new Actions(_driver); //IWebElement dragArea = FindElement(By.XPath(moduleName)); //IWebElement to = FindElement(By.XPath(Modules.LocationDescription[location].IdWhenOnPage)); action.MoveToElement(FindElement(By.XPath(moduleName))).Perform(); action.DragAndDrop(FindElement(By.XPath(moduleName)), FindElement(By.XPath(Modules.LocationDescription[location].IdWhenOnPage)).ScrollIntoView()); //action.ClickAndHold(dragArea).MoveToElement(to.ScrollIntoView()).Release(); action.Build().Perform(); Thread.Sleep(1000); }
// 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"]); } }
public void AddNewModuleUsingDragAndDrop(string moduleName, string moduleNameOnPage, string location) { Trace.WriteLine(BasePage.TraceLevelComposite + "Add a Module, Using Drag&Drop:"); WaitForElement(By.XPath(moduleName)).ScrollIntoView().WaitTillVisible().Click(); Trace.WriteLine(TraceLevelPage + "Mouse over module: '" + moduleName); Actions action = new Actions(_driver); action.MoveToElement(FindElement(By.XPath(moduleName))).Perform(); action.DragAndDrop(FindElement(By.XPath(moduleName)), FindElement(By.XPath(location)).ScrollIntoView()); action.Build().Perform(); /*IWebElement dragElement=FindElement(By.XPath(moduleName)); IWebElement dropElement=FindElement(By.XPath(location)); Actions builder = new Actions(_driver); builder.ClickAndHold(dragElement) .MoveToElement(dropElement) .Release(dropElement); builder.Build().Perform();*/ Thread.Sleep(1000); }
////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); }
// 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); } }
public void CtrlClick_Should_Open_Link_In_Other_Window() { var b = GetMockedBrowser(); var dr = new SimpleBrowserDriver((IBrowser)b); dr.Navigate().GoToUrl("http://www.a.com/link.htm"); Assert.That(dr.WindowHandles.Count == 1); Assert.That(dr.Url == "http://www.a.com/link.htm"); var link = dr.FindElement(By.LinkText("link")); Assert.NotNull(link); link.Click(); Assert.That(dr.Url == "http://www.a.com/otherpage.htm"); dr.Navigate().Back(); Assert.That(dr.Url == "http://www.a.com/link.htm"); link = dr.FindElement(By.LinkText("link")); Actions builder = new Actions(dr); builder.KeyDown(Keys.Control).Click(link).KeyUp(Keys.Control); var act = builder.Build(); act.Perform(); Assert.That(dr.Url == "http://www.a.com/link.htm"); Assert.That(dr.WindowHandles.Count == 2); }
//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); }
/// <summary> /// MouseOver a sequence of By objects in order. /// </summary> /// <param name="bys">A variadic list of By objects to mouse over.</param> /// <returns>The browser instance.</returns> public Browser MouseOver(params By[] bys) { var actions = new Actions(WebDriver); bys.Select(by => WebDriver.FindElement(by)).ToList() .ForEach(elem => actions.MoveToElement(elem)); actions.Build().Perform(); return this; }
public static void PressKey(string key) { var builder = new Actions(SeleniumDriver.Instance); switch (key.ToLower()) { case "return": builder.SendKeys(Keys.Return); break; case "tab": builder.SendKeys(Keys.Tab); break; case "arrowdown": builder.SendKeys(Keys.ArrowDown); break; case "arrowup": builder.SendKeys(Keys.ArrowUp); break; case "arrowleft": builder.SendKeys(Keys.ArrowLeft); break; case "arrowright": builder.SendKeys(Keys.ArrowRight); break; case "home": builder.SendKeys(Keys.Home); break; case "end": builder.SendKeys(Keys.End); break; case "pageup": builder.SendKeys(Keys.PageUp); break; case "pagedown": builder.SendKeys(Keys.PageDown); break; } builder.Build().Perform(); }
public static void MouseOver(this IWebElement element) { IWebDriver driver = WebDriverTestBase.driver; var action = new Actions(driver).MoveToElement(element); Thread.Sleep(2000); action.Build().Perform(); }
public void ControlClick() { if (element != null) { IWebElement webElement = ((WebDriverElement)element)._WebElement; Actions actions = new Actions(this.driver._WebDriver); actions.MoveToElement(webElement).KeyDown(Keys.Control).Click().KeyUp(Keys.Control); actions.Build().Perform(); } }
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)); }