public void ShouldAllowSendingKeysWithShiftPressed() { driver.Url = javascriptPage; IWebElement keysEventInput = driver.FindElement(By.Id("theworks")); keysEventInput.Click(); Actions actionProvider = new Actions(driver); IAction pressShift = actionProvider.KeyDown(keysEventInput, Keys.Shift).Build(); pressShift.Perform(); IAction sendLowercase = actionProvider.SendKeys(keysEventInput, "ab").Build(); sendLowercase.Perform(); IAction releaseShift = actionProvider.KeyUp(keysEventInput, Keys.Shift).Build(); releaseShift.Perform(); AssertThatFormEventsFiredAreExactly("focus keydown keydown keypress keyup keydown keypress keyup keyup"); Assert.AreEqual("AB", keysEventInput.GetAttribute("value")); }
public void ShouldAllowSelectingMultipleItems() { if (!IsNativeEventsEnabled || (!Platform.CurrentPlatform.IsPlatformType(PlatformType.Linux))) { Assert.Ignore("Skipping ShouldAllowSelectingMultipleItems: Only works with native events on Linux."); } driver.Url = selectableItemsPage; IWebElement reportingElement = driver.FindElement(By.Id("infodiv")); Assert.AreEqual("no info", reportingElement.Text); ReadOnlyCollection<IWebElement> listItems = driver.FindElements(By.TagName("li")); Actions actionBuider = new Actions(driver); IAction selectThreeItems = actionBuider.KeyDown(Keys.Control) .Click(listItems[1]) .Click(listItems[3]) .Click(listItems[5]) .KeyUp(Keys.Control).Build(); selectThreeItems.Perform(); Assert.AreEqual("#item2 #item4 #item6", reportingElement.Text); // Now click on another element, make sure that's the only one selected. actionBuider.Click(listItems[6]).Build().Perform(); Assert.AreEqual("#item7", reportingElement.Text); }
public void ShouldAllowSelectingMultipleItems() { driver.Url = selectableItemsPage; IWebElement reportingElement = driver.FindElement(By.Id("infodiv")); Assert.AreEqual("no info", reportingElement.Text); ReadOnlyCollection<IWebElement> listItems = driver.FindElements(By.TagName("li")); Actions actionBuider = new Actions(driver); IAction selectThreeItems = actionBuider.KeyDown(Keys.Control) .Click(listItems[1]) .Click(listItems[3]) .Click(listItems[5]) .KeyUp(Keys.Control).Build(); selectThreeItems.Perform(); Assert.AreEqual("#item2 #item4 #item6", reportingElement.Text); // Now click on another element, make sure that's the only one selected. actionBuider.Click(listItems[6]).Build().Perform(); Assert.AreEqual("#item7", reportingElement.Text); }
public static void ZoomBackToNormal() { Actions zoomBackToNormal = new Actions(Browser.Driver); zoomBackToNormal.KeyDown(Keys.Control) .SendKeys("0") .KeyUp(Keys.Control); zoomBackToNormal.Perform(); }
public static void ZoomOut() { Actions zoomOut = new Actions(Browser.Driver); zoomOut.KeyDown(Keys.Control) .SendKeys(Keys.Subtract) .SendKeys(Keys.Subtract) .KeyUp(Keys.Control); zoomOut.Perform(); }
public void ShouldAllowSendingKeyDownOnly() { driver.Url = javascriptPage; IWebElement keysEventInput = driver.FindElement(By.Id("theworks")); Actions actionProvider = new Actions(driver); IAction pressShift = actionProvider.KeyDown(keysEventInput, Keys.Shift).Build(); pressShift.Perform(); IWebElement keyLoggingElement = driver.FindElement(By.Id("result")); string logText = keyLoggingElement.Text; IAction releaseShift = actionProvider.KeyDown(keysEventInput, Keys.Shift).Build(); releaseShift.Perform(); Assert.IsTrue(logText.EndsWith("keydown"), "Key down event not isolated, got: " + logText); }
public void ShouldAllowSendingKeyDownOnly() { driver.Url = javascriptPage; IWebElement keysEventInput = driver.FindElement(By.Id("theworks")); Actions actionProvider = new Actions(driver); IAction pressShift = actionProvider.KeyDown(keysEventInput, Keys.Shift).Build(); pressShift.Perform(); IWebElement keyLoggingElement = driver.FindElement(By.Id("result")); string logText = keyLoggingElement.Text; IAction releaseShift = actionProvider.KeyDown(keysEventInput, Keys.Shift).Build(); releaseShift.Perform(); Assert.IsTrue(logText.EndsWith("keydown"), "Key down event not isolated. Log text should end with 'keydown', got: " + logText); }
public void ShouldAllowSendingKeyDownOnly() { driver.Url = javascriptPage; IWebElement keysEventInput = driver.FindElement(By.Id("theworks")); // Scroll the element into view before attempting any actions on it. ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView();", keysEventInput); Actions actionProvider = new Actions(driver); IAction pressShift = actionProvider.KeyDown(keysEventInput, Keys.Shift).Build(); pressShift.Perform(); IWebElement keyLoggingElement = driver.FindElement(By.Id("result")); string logText = keyLoggingElement.Text; IAction releaseShift = actionProvider.KeyDown(keysEventInput, Keys.Shift).Build(); releaseShift.Perform(); Assert.That(logText, Does.EndWith("keydown")); }
public void ShouldAllowSendingKeyUp() { driver.Url = javascriptPage; IWebElement keysEventInput = driver.FindElement(By.Id("theworks")); Actions actionProvider = new Actions(driver); IAction pressShift = actionProvider.KeyDown(keysEventInput, Keys.Shift).Build(); pressShift.Perform(); IWebElement keyLoggingElement = driver.FindElement(By.Id("result")); string eventsText = keyLoggingElement.Text; Assert.IsTrue(keyLoggingElement.Text.EndsWith("keydown"), "Key down should be isolated for this test to be meaningful. Event text should end with 'keydown', got events: " + eventsText); IAction releaseShift = actionProvider.KeyUp(keysEventInput, Keys.Shift).Build(); releaseShift.Perform(); eventsText = keyLoggingElement.Text; Assert.IsTrue(keyLoggingElement.Text.EndsWith("keyup"), "Key up event not isolated. Event text should end with 'keyup', got: " + eventsText); }
public void ShouldAllowSendingKeyUp() { driver.Url = javascriptPage; IWebElement keysEventInput = driver.FindElement(By.Id("theworks")); Actions actionProvider = new Actions(driver); IAction pressShift = actionProvider.KeyDown(keysEventInput, Keys.Shift).Build(); pressShift.Perform(); IWebElement keyLoggingElement = driver.FindElement(By.Id("result")); string eventsText = keyLoggingElement.Text; Assert.IsTrue(keyLoggingElement.Text.EndsWith("keydown"), "Key down should be isolated for this test to be meaningful. Event text should end with 'keydown', got events: " + eventsText); IAction releaseShift = actionProvider.KeyUp(keysEventInput, Keys.Shift).Build(); releaseShift.Perform(); eventsText = keyLoggingElement.Text; Assert.IsTrue(keyLoggingElement.Text.EndsWith("keyup"), "Key up event not isolated. Event text should end with 'keyup', got: " + eventsText); }
public void TestKeyBoard() { NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite()); Actions act = new Actions(ObjectRepository.Driver); // ctrl + t // act.KeyDown(Keys.LeftControl) // .SendKeys("t") // .KeyUp(Keys.LeftControl) // .Build() // .Perform(); // ctrl + shift +a // act.KeyDown(Keys.LeftControl) // .KeyDown(Keys.LeftShift) // .SendKeys("a") // .KeyUp(Keys.LeftShift) // .KeyUp(Keys.LeftControl) // .Build() // .Perform(); // alt + f + x // act.KeyDown(Keys.LeftAlt) // .SendKeys("f") // .SendKeys("x") // .Build() // .Perform(); IWebElement ele1 = ObjectRepository.Driver.FindElement(By.Id("quicksearch_top")); IWebElement ele2 = ObjectRepository.Driver.FindElement(By.Id("quicksearch_main")); ele1.SendKeys("fx"); act.KeyDown(ele2, Keys.LeftShift) .SendKeys(ele2, "f") .SendKeys(ele2, "x") .KeyUp(ele2, Keys.LeftShift) .Build() .Perform(); Thread.Sleep(5000); }
public void ShouldHandleMultiSelect() { Actions actions = new Actions(ngDriver.WrappedDriver); GetPageContent("ng_multi_select.htm"); IWebElement element = ngDriver.FindElement(NgBy.Model("selectedValues")); // use core Selenium IList<IWebElement> options = new SelectElement(element).Options; IEnumerator<IWebElement> etr = options.Where(o => Convert.ToBoolean(o.GetAttribute("selected"))).GetEnumerator(); while (etr.MoveNext()) { Console.Error.WriteLine(etr.Current.Text); } foreach (IWebElement option in options) { // http://selenium.googlecode.com/svn/trunk/docs/api/dotnet/html/AllMembers_T_OpenQA_Selenium_Keys.htm actions.KeyDown(Keys.Control).Click(option).KeyUp(Keys.Control).Build().Perform(); // triggers ngDriver.WaitForAngular() Assert.IsNotEmpty(ngDriver.Url); } // re-read select options element = ngDriver.FindElement(NgBy.Model("selectedValues")); options = new SelectElement(element).Options; etr = options.Where(o => Convert.ToBoolean(o.GetAttribute("selected"))).GetEnumerator(); while (etr.MoveNext()) { Console.Error.WriteLine(etr.Current.Text); } }
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); }
public static void ClearBrowserCache() { // Use Ctrl + F5 // Logger.WriteInformationToLog("Clearing Cache - using Ctrl + F5"); var builder = new Actions(SeleniumDriver.Instance); builder.KeyDown(Keys.Control).SendKeys(Keys.F5).KeyUp(Keys.Control).Perform(); }
public void SelectAll(NgWebDriver driver) { Actions action = new Actions(driver.WrappedDriver); IAction chord = action.KeyDown(_ele.WrappedElement, OpenQA.Selenium.Keys.Control) .SendKeys("a") .KeyUp(_ele.WrappedElement, OpenQA.Selenium.Keys.Control) .Build(); chord.Perform(); }
public void KeysTest() { List<string> keyComboNames = new List<string>() { "Control", "Shift", "Alt", "Control + Shift", "Control + Alt", "Shift + Alt", "Control + Shift + Alt" }; List<string> colorNames = new List<string>() { "red", "green", "lightblue", "yellow", "lightgreen", "silver", "magenta" }; List<List<string>> modifierCombonations = new List<List<string>>() { new List<string>() { Keys.Control }, new List<string>() { Keys.Shift }, new List<string>() { Keys.Alt }, new List<string>() { Keys.Control, Keys.Shift }, new List<string>() { Keys.Control, Keys.Alt }, new List<string>() { Keys.Shift, Keys.Alt }, new List<string>() { Keys.Control, Keys.Shift, Keys.Alt} }; List<string> expectedColors = new List<string>() { "rgba(255, 0, 0, 1)", "rgba(0, 128, 0, 1)", "rgba(173, 216, 230, 1)", "rgba(255, 255, 0, 1)", "rgba(144, 238, 144, 1)", "rgba(192, 192, 192, 1)", "rgba(255, 0, 255, 1)" }; bool passed = true; string errors = string.Empty; driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("keyboard_shortcut.html"); IWebElement body = driver.FindElement(By.CssSelector("body")); Actions actions = new Actions(driver); for (int i = 0; i < keyComboNames.Count; i++) { for (int j = 0; j < modifierCombonations[i].Count; j++) { actions.KeyDown(modifierCombonations[i][j]); } actions.SendKeys("1"); // Alternatively, the following single line of code would release // all modifier keys, instead of looping through each key. // actions.SendKeys(Keys.Null); for (int j = 0; j < modifierCombonations[i].Count; j++) { actions.KeyUp(modifierCombonations[i][j]); } actions.Perform(); string background = body.GetCssValue("background-color"); passed = passed && background == expectedColors[i]; if (background != expectedColors[i]) { if (errors.Length > 0) { errors += "\n"; } errors += string.Format("Key not properly processed for {0}. Background should be {1}, Expected: '{2}', Actual: '{3}'", keyComboNames[i], colorNames[i], expectedColors[i], background); } } Assert.IsTrue(passed, errors); }
public void OpenNewBrowserTab() { Actions action = new Actions(this.driver); action.KeyDown(Keys.LeftControl).KeyDown("T").KeyUp("T").KeyUp(Keys.LeftControl).Build().Perform(); }
/// <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; } }