List of usage examples for org.openqa.selenium Keys SUBTRACT
Keys SUBTRACT
To view the source code for org.openqa.selenium Keys SUBTRACT.
Click Source Link
From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.WebDriverRunner.java
License:Open Source License
public File saveScreenshotTo(String fileName, boolean generateSource) { File screenshotFile = new File(fileName); screenshotFile.getParentFile().mkdirs(); driver.manage().window().maximize(); File screenshot = null;/* www . jav a 2s .c o m*/ if (BehaveConfig.getRunner_screenShotZoomout() != 0) { WebElement html = driver.findElement(By.tagName("html")); for (int x = 0; x < BehaveConfig.getRunner_screenShotZoomout(); x++) { html.sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT)); } screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); html.sendKeys(Keys.chord(Keys.CONTROL, "0")); } else { screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); } if (screenshot != null) { try { FileUtils.copyFile(screenshot, new File(screenshotFile.getAbsolutePath())); if (generateSource) { writeHtmlFile(screenshotFile.getAbsolutePath()); } } catch (IOException e) { throw new BehaveException(message.getString("exception-save-screenshot"), e); } } return screenshotFile; }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test./*w w w. j a v a2 s . c o m*/ */ @Test public void numberpadKeys() { final WebDriver driver = getWebDriver("/javascriptPage.html"); final WebElement element = driver.findElement(By.id("keyReporter")); element.sendKeys("abcd" + Keys.MULTIPLY + Keys.SUBTRACT + Keys.ADD + Keys.DECIMAL + Keys.SEPARATOR + Keys.NUMPAD0 + Keys.NUMPAD9 + Keys.ADD + Keys.SEMICOLON + Keys.EQUALS + Keys.DIVIDE + Keys.NUMPAD3 + "abcd"); assertThat(element.getAttribute("value"), is("abcd*-+.,09+;=/3abcd")); }
From source file:com.liferay.cucumber.selenium.BaseWebDriverImpl.java
License:Open Source License
@Override public void typeKeys(String locator, String value) { WebElement webElement = getWebElement(locator); if (!webElement.isEnabled()) { return;/*from w w w .j a v a 2 s .c o m*/ } if (value.contains("line-number=")) { value = value.replaceAll("line-number=\"\\d+\"", ""); } int i = 0; Set<Integer> specialCharIndexes = getSpecialCharIndexes(value); for (int specialCharIndex : specialCharIndexes) { webElement.sendKeys(value.substring(i, specialCharIndex)); String specialChar = String.valueOf(value.charAt(specialCharIndex)); if (specialChar.equals("-")) { webElement.sendKeys(Keys.SUBTRACT); } else if (specialChar.equals("\t")) { webElement.sendKeys(Keys.TAB); } else { webElement.sendKeys(Keys.SHIFT, _keysSpecialChars.get(specialChar)); } i = specialCharIndex + 1; } webElement.sendKeys(value.substring(i, value.length())); }
From source file:com.thoughtworks.selenium.webdriven.commands.SendKeys.java
License:Apache License
@Override protected Void handleSeleneseCommand(WebDriver driver, String locator, String value) { alertOverride.replaceAlertMethod(driver); value = value.replace("${KEY_ALT}", Keys.ALT); value = value.replace("${KEY_CONTROL}", Keys.CONTROL); value = value.replace("${KEY_CTRL}", Keys.CONTROL); value = value.replace("${KEY_META}", Keys.META); value = value.replace("${KEY_COMMAND}", Keys.COMMAND); value = value.replace("${KEY_SHIFT}", Keys.SHIFT); value = value.replace("${KEY_BACKSPACE}", Keys.BACK_SPACE); value = value.replace("${KEY_BKSP}", Keys.BACK_SPACE); value = value.replace("${KEY_DELETE}", Keys.DELETE); value = value.replace("${KEY_DEL}", Keys.DELETE); value = value.replace("${KEY_ENTER}", Keys.ENTER); value = value.replace("${KEY_EQUALS}", Keys.EQUALS); value = value.replace("${KEY_ESCAPE}", Keys.ESCAPE); value = value.replace("${KEY_ESC}", Keys.ESCAPE); value = value.replace("${KEY_INSERT}", Keys.INSERT); value = value.replace("${KEY_INS}", Keys.INSERT); value = value.replace("${KEY_PAUSE}", Keys.PAUSE); value = value.replace("${KEY_SEMICOLON}", Keys.SEMICOLON); value = value.replace("${KEY_SPACE}", Keys.SPACE); value = value.replace("${KEY_TAB}", Keys.TAB); value = value.replace("${KEY_LEFT}", Keys.LEFT); value = value.replace("${KEY_UP}", Keys.UP); value = value.replace("${KEY_RIGHT}", Keys.RIGHT); value = value.replace("${KEY_DOWN}", Keys.DOWN); value = value.replace("${KEY_PAGE_UP}", Keys.PAGE_UP); value = value.replace("${KEY_PGUP}", Keys.PAGE_UP); value = value.replace("${KEY_PAGE_DOWN}", Keys.PAGE_DOWN); value = value.replace("${KEY_PGDN}", Keys.PAGE_DOWN); value = value.replace("${KEY_END}", Keys.END); value = value.replace("${KEY_HOME}", Keys.HOME); value = value.replace("${KEY_NUMPAD0}", Keys.NUMPAD0); value = value.replace("${KEY_N0}", Keys.NUMPAD0); value = value.replace("${KEY_NUMPAD1}", Keys.NUMPAD1); value = value.replace("${KEY_N1}", Keys.NUMPAD1); value = value.replace("${KEY_NUMPAD2}", Keys.NUMPAD2); value = value.replace("${KEY_N2}", Keys.NUMPAD2); value = value.replace("${KEY_NUMPAD3}", Keys.NUMPAD3); value = value.replace("${KEY_N3}", Keys.NUMPAD3); value = value.replace("${KEY_NUMPAD4}", Keys.NUMPAD4); value = value.replace("${KEY_N4}", Keys.NUMPAD4); value = value.replace("${KEY_NUMPAD5}", Keys.NUMPAD5); value = value.replace("${KEY_N5}", Keys.NUMPAD5); value = value.replace("${KEY_NUMPAD6}", Keys.NUMPAD6); value = value.replace("${KEY_N6}", Keys.NUMPAD6); value = value.replace("${KEY_NUMPAD7}", Keys.NUMPAD7); value = value.replace("${KEY_N7}", Keys.NUMPAD7); value = value.replace("${KEY_NUMPAD8}", Keys.NUMPAD8); value = value.replace("${KEY_N8}", Keys.NUMPAD8); value = value.replace("${KEY_NUMPAD9}", Keys.NUMPAD9); value = value.replace("${KEY_N9}", Keys.NUMPAD9); value = value.replace("${KEY_ADD}", Keys.ADD); value = value.replace("${KEY_NUM_PLUS}", Keys.ADD); value = value.replace("${KEY_DECIMAL}", Keys.DECIMAL); value = value.replace("${KEY_NUM_PERIOD}", Keys.DECIMAL); value = value.replace("${KEY_DIVIDE}", Keys.DIVIDE); value = value.replace("${KEY_NUM_DIVISION}", Keys.DIVIDE); value = value.replace("${KEY_MULTIPLY}", Keys.MULTIPLY); value = value.replace("${KEY_NUM_MULTIPLY}", Keys.MULTIPLY); value = value.replace("${KEY_SEPARATOR}", Keys.SEPARATOR); value = value.replace("${KEY_SEP}", Keys.SEPARATOR); value = value.replace("${KEY_SUBTRACT}", Keys.SUBTRACT); value = value.replace("${KEY_NUM_MINUS}", Keys.SUBTRACT); value = value.replace("${KEY_F1}", Keys.F1); value = value.replace("${KEY_F2}", Keys.F2); value = value.replace("${KEY_F3}", Keys.F3); value = value.replace("${KEY_F4}", Keys.F4); value = value.replace("${KEY_F5}", Keys.F5); value = value.replace("${KEY_F6}", Keys.F6); value = value.replace("${KEY_F7}", Keys.F7); value = value.replace("${KEY_F8}", Keys.F8); value = value.replace("${KEY_F9}", Keys.F9); value = value.replace("${KEY_F10}", Keys.F10); value = value.replace("${KEY_F11}", Keys.F11); value = value.replace("${KEY_F12}", Keys.F12); finder.findElement(driver, locator).sendKeys(value); return null;/* ww w. j a v a2 s .c o m*/ }
From source file:com.vaadin.tests.components.orderedlayout.OrderedLayoutExpandTest.java
License:Apache License
@Test public void testNoAbortingLayoutAfter100PassesError() throws Exception { setDebug(true);/* w w w . j a va 2 s . co m*/ openTestURL(); if (!getDesiredCapabilities().equals(Browser.CHROME.getDesiredCapabilities())) { // Chrome uses css to to set zoom level to 110% that is known to // cause issues with the test app. // Other browsers tries to set browser's zoom level directly. WebElement html = driver.findElement(By.tagName("html")); // reset to 100% just in case html.sendKeys(Keys.chord(Keys.CONTROL, "0")); // zoom browser to 75% (ie) or 90% (FF). It depends on browser // how much "Ctrl + '-'" zooms out. html.sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT)); } // open debug window's Examine component hierarchy tab openDebugExamineComponentHierarchyTab(); // click "Check layouts for potential problems" button clickDebugCheckLayoutsForPotentialProblems(); // find div containing a successful layout analyze result WebElement pass = findLayoutAnalyzePassElement(); // find div containing a error message with // "Aborting layout after 100 passess" message. WebElement error = findLayoutAnalyzeAbortedElement(); Assert.assertNull(error); Assert.assertNotNull(pass); if (!getDesiredCapabilities().equals(Browser.CHROME.getDesiredCapabilities())) { WebElement html = driver.findElement(By.tagName("html")); // reset zoom level back to 100% html.sendKeys(Keys.chord(Keys.CONTROL, "0")); } }
From source file:org.apache.zeppelin.ZeppelinIT.java
License:Apache License
@Test public void testAngularDisplay() throws InterruptedException { if (!endToEndTestEnabled()) { return;//from w w w . j a va2s . c om } String noteName = createNewNoteAndGetName(); driver.findElement(By.partialLinkText(noteName)).click(); // wait for first paragraph's " READY " status text waitForParagraph(1, "READY"); /* * print angular template * %angular <div id='angularTestButton' ng-click='myVar=myVar+1'>BindingTest_{{myVar}}_</div> */ WebElement paragraph1Editor = driver.findElement(By.xpath(getParagraphXPath(1) + "//textarea")); paragraph1Editor.sendKeys("println" + Keys.chord(Keys.SHIFT, "9") + "\"" + Keys.chord(Keys.SHIFT, "5") + "angular <div id='angularTestButton' " + "ng" + Keys.chord(Keys.SUBTRACT) + "click='myVar=myVar+1'>" + "BindingTest_{{myVar}}_</div>\")"); paragraph1Editor.sendKeys(Keys.chord(Keys.SHIFT, Keys.ENTER)); waitForParagraph(1, "FINISHED"); // check expected text assertEquals("BindingTest__", driver.findElement(By.xpath(getParagraphXPath(1) + "//div[@id=\"angularTestButton\"]")).getText()); /* * Bind variable * z.angularBind("myVar", 1) */ assertEquals(1, driver.findElements(By.xpath(getParagraphXPath(2) + "//textarea")).size()); WebElement paragraph2Editor = driver.findElement(By.xpath(getParagraphXPath(2) + "//textarea")); paragraph2Editor.sendKeys("z.angularBind" + Keys.chord(Keys.SHIFT, "9") + "\"myVar\", 1)"); paragraph2Editor.sendKeys(Keys.chord(Keys.SHIFT, Keys.ENTER)); waitForParagraph(2, "FINISHED"); // check expected text assertEquals("BindingTest_1_", driver.findElement(By.xpath(getParagraphXPath(1) + "//div[@id=\"angularTestButton\"]")).getText()); /* * print variable * print("myVar="+z.angular("myVar")) */ WebElement paragraph3Editor = driver.findElement(By.xpath(getParagraphXPath(3) + "//textarea")); paragraph3Editor.sendKeys("print" + Keys.chord(Keys.SHIFT, "9") + "\"myVar=\"" + Keys.chord(Keys.ADD) + "z.angular" + Keys.chord(Keys.SHIFT, "9") + "\"myVar\"))"); paragraph3Editor.sendKeys(Keys.chord(Keys.SHIFT, Keys.ENTER)); waitForParagraph(3, "FINISHED"); // check expected text assertEquals("myVar=1", driver.findElement(By.xpath(getParagraphXPath(3) + "//div[@ng-bind=\"paragraph.result.msg\"]")) .getText()); /* * Click element */ driver.findElement(By.xpath(getParagraphXPath(1) + "//div[@id=\"angularTestButton\"]")).click(); // check expected text assertEquals("BindingTest_2_", driver.findElement(By.xpath(getParagraphXPath(1) + "//div[@id=\"angularTestButton\"]")).getText()); /* * Register watcher * z.angularWatch("myVar", (before:Object, after:Object, context:org.apache.zeppelin.interpreter.InterpreterContext) => { * z.run(2, context) * } */ WebElement paragraph4Editor = driver.findElement(By.xpath(getParagraphXPath(4) + "//textarea")); paragraph4Editor.sendKeys( "z.angularWatch" + Keys.chord(Keys.SHIFT, "9") + "\"myVar\", " + Keys.chord(Keys.SHIFT, "9") + "before:Object, after:Object, context:org.apache.zeppelin.interpreter.InterpreterContext)" + Keys.EQUALS + ">{ z.run" + Keys.chord(Keys.SHIFT, "9") + "2, context)}"); paragraph4Editor.sendKeys(Keys.chord(Keys.SHIFT, Keys.ENTER)); waitForParagraph(4, "FINISHED"); /* * Click element, again and see watcher works */ driver.findElement(By.xpath(getParagraphXPath(1) + "//div[@id=\"angularTestButton\"]")).click(); // check expected text assertEquals("BindingTest_3_", driver.findElement(By.xpath(getParagraphXPath(1) + "//div[@id=\"angularTestButton\"]")).getText()); waitForParagraph(3, "FINISHED"); // check expected text by watcher assertEquals("myVar=3", driver.findElement(By.xpath(getParagraphXPath(3) + "//div[@ng-bind=\"paragraph.result.msg\"]")) .getText()); /* * Unbind * z.angularUnbind("myVar") */ WebElement paragraph5Editor = driver.findElement(By.xpath(getParagraphXPath(5) + "//textarea")); paragraph5Editor.sendKeys("z.angularUnbind" + Keys.chord(Keys.SHIFT, "9") + "\"myVar\")"); paragraph5Editor.sendKeys(Keys.chord(Keys.SHIFT, Keys.ENTER)); waitForParagraph(5, "FINISHED"); // check expected text assertEquals("BindingTest__", driver.findElement(By.xpath(getParagraphXPath(1) + "//div[@id=\"angularTestButton\"]")).getText()); /* * Bind again and see rebind works. */ paragraph2Editor = driver.findElement(By.xpath(getParagraphXPath(2) + "//textarea")); paragraph2Editor.sendKeys(Keys.chord(Keys.SHIFT, Keys.ENTER)); waitForParagraph(2, "FINISHED"); // check expected text assertEquals("BindingTest_1_", driver.findElement(By.xpath(getParagraphXPath(1) + "//div[@id=\"angularTestButton\"]")).getText()); System.out.println("testCreateNotebook Test executed"); }
From source file:org.callimachusproject.webdriver.helpers.WebBrowserDriver.java
License:Apache License
private void sendKeys(WebElement element, CharSequence... keys) { StringBuilder sb = new StringBuilder(); List<CharSequence> list = new ArrayList<CharSequence>(keys.length * 2); for (CharSequence key : keys) { if (key instanceof String) { for (char chr : ((String) key).toCharArray()) { switch (chr) { case '-': sendKeys(element, list, sb); list.add(Keys.SUBTRACT); break; case '!': sendKeys(element, list, sb); list.add(Keys.chord(Keys.SHIFT, "1")); break; case '@': sendKeys(element, list, sb); list.add(Keys.chord(Keys.SHIFT, "2")); break; case '#': sendKeys(element, list, sb); list.add(Keys.chord(Keys.SHIFT, "3")); break; case '$': sendKeys(element, list, sb); list.add(Keys.chord(Keys.SHIFT, "4")); break; case '%': sendKeys(element, list, sb); list.add(Keys.chord(Keys.SHIFT, "5")); break; case '^': sendKeys(element, list, sb); list.add(Keys.chord(Keys.SHIFT, "6")); break; case '&': sendKeys(element, list, sb); list.add(Keys.chord(Keys.SHIFT, "7")); break; case '*': sendKeys(element, list, sb); list.add(Keys.chord(Keys.SHIFT, "8")); break; case '(': sendKeys(element, list, sb); list.add(Keys.chord(Keys.SHIFT, "9")); break; case ')': sendKeys(element, list, sb); list.add(Keys.chord(Keys.SHIFT, "0")); break; case '{': case '}': case '<': case '>': case '[': case ']': case '"': case '\'': case '\n': sendKeys(element, list, sb); sb.append(chr);/*from w w w . j a va 2s . com*/ sendKeys(element, list, sb); break; default: sb.append(chr); } } } else { list.add(key); } } sendKeys(element, list, sb); }
From source file:org.eclipse.scout.rt.testing.ui.rap.RapMock.java
License:Open Source License
protected Keys toSeleniumKey(Key key) { switch (key) { case Shift:/*from w ww.ja v a 2 s. com*/ return Keys.SHIFT; case Control: return Keys.CONTROL; case Alt: return Keys.ALT; case Delete: return Keys.DELETE; case Backspace: return Keys.BACK_SPACE; case Enter: return Keys.ENTER; case Esc: return Keys.ESCAPE; case Tab: return Keys.TAB; case ContextMenu: throw new IllegalArgumentException("Unknown keyboard key: " + key); case Up: return Keys.UP; case Down: return Keys.DOWN; case Left: return Keys.LEFT; case Right: return Keys.RIGHT; case Windows: return Keys.META; case F1: return Keys.F1; case F2: return Keys.F2; case F3: return Keys.F3; case F4: return Keys.F4; case F5: return Keys.F5; case F6: return Keys.F6; case F7: return Keys.F7; case F8: return Keys.F8; case F9: return Keys.F9; case F10: return Keys.F10; case F11: return Keys.F11; case F12: return Keys.F12; case Home: return Keys.HOME; case End: return Keys.END; case PageUp: return Keys.PAGE_UP; case PageDown: return Keys.PAGE_DOWN; case NumPad0: return Keys.NUMPAD0; case NumPad1: return Keys.NUMPAD1; case NumPad2: return Keys.NUMPAD2; case NumPad3: return Keys.NUMPAD3; case NumPad4: return Keys.NUMPAD4; case NumPad5: return Keys.NUMPAD5; case NumPad6: return Keys.NUMPAD6; case NumPad7: return Keys.NUMPAD7; case NumPad8: return Keys.NUMPAD8; case NumPadMultiply: return Keys.MULTIPLY; case NumPadDivide: return Keys.DIVIDE; case NumPadAdd: return Keys.ADD; case NumPadSubtract: return Keys.SUBTRACT; case NumPadDecimal: return Keys.DECIMAL; case NumPadSeparator: return Keys.SEPARATOR; default: throw new IllegalArgumentException("Unknown keyboard key: " + key); } }
From source file:org.jspringbot.keyword.selenium.SeleniumHelper.java
License:Open Source License
public void zoomOut(int times) { WebElement html = driver.findElement(By.tagName("html")); for (int i = 0; i < times; i++) { if (isMacOS()) { html.sendKeys(Keys.chord(Keys.COMMAND, Keys.SUBTRACT)); } else {/*from ww w.j a v a2 s . c o m*/ html.sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT)); } } }
From source file:org.jspringbot.keyword.selenium.SeleniumHelper.java
License:Open Source License
private String mapAsciiKeyCodeToKey(int keyCode) { Map<Integer, Keys> keysMap = new HashMap<Integer, Keys>(); keysMap.put(0, Keys.NULL);/*from w w w . ja va 2 s.co m*/ keysMap.put(8, Keys.BACK_SPACE); keysMap.put(9, Keys.TAB); keysMap.put(10, Keys.RETURN); keysMap.put(13, Keys.ENTER); keysMap.put(24, Keys.CANCEL); keysMap.put(27, Keys.ESCAPE); keysMap.put(32, Keys.SPACE); keysMap.put(42, Keys.MULTIPLY); keysMap.put(43, Keys.ADD); keysMap.put(44, Keys.SUBTRACT); keysMap.put(56, Keys.DECIMAL); keysMap.put(57, Keys.DIVIDE); keysMap.put(59, Keys.SEMICOLON); keysMap.put(61, Keys.EQUALS); keysMap.put(127, Keys.DELETE); Keys key = keysMap.get(keyCode); if (key == null) { Character c = (char) keyCode; return c.toString(); } return key.toString(); }