private CharSequence escapeParenthesis(final String chars) { return chars.replaceAll("\\(", Keys.chord(Keys.SHIFT, "9")); }
@Override protected CharSequence[] modifyCharSequence(CharSequence... keysToSend) { final List<CharSequence> modKeysToSend = newArrayList(); for (CharSequence charSequence : keysToSend) { final String key = charSequence.toString(); if (Keys.END.toString().equals(key)) { modKeysToSend.add(Keys.chord(Keys.COMMAND, Keys.RIGHT)); } else if (Keys.HOME.toString().equals(key)) { modKeysToSend.add(Keys.chord(Keys.COMMAND, Keys.LEFT)); } else if (Keys.PAGE_UP.toString().equals(key)) { modKeysToSend.add(Keys.chord(Keys.COMMAND, Keys.UP)); } else if (Keys.PAGE_DOWN.toString().equals(key)) { modKeysToSend.add(Keys.chord(Keys.COMMAND, Keys.DOWN)); } else { modKeysToSend.add(charSequence); } } return modKeysToSend.toArray(new CharSequence[modKeysToSend.size()]); } }
private String toKeys(String keys) { if(isKeyCord(keys)) { keys = keys.substring(5); String[] items = keys.split("(?<!\\\\)\\|"); CharSequence[] charSequences = new CharSequence[items.length]; for(int i = 0; i < items.length;i++) { String item = items[i]; try { charSequences[i] = Keys.valueOf(item); } catch (IllegalArgumentException e) { charSequences[i] = item; } } return Keys.chord(charSequences); } return keys; }
/** * Get the special key representation, {@link Keys}, of the supplied character if there is one. If * there is no special key tied to this character, null will be returned. * * @param key unicode character code * @return special key linked to the character code, or null if character is not a special key */ private static Keys getKeyFromUnicode(char key) { for (Keys unicodeKey : Keys.values()) { if (unicodeKey.charAt(0) == key) { return unicodeKey; } } return null; }
private CharSequence getKeyOrCharacter(String key) { try { return Keys.valueOf(key.toUpperCase()); } catch (IllegalArgumentException ex) { return key; } }
@Override public void keyUp(Keys theKey) throws WidgetException { try { Actions builder = new Actions(getGUIDriver().getWrappedDriver()); synchronized (InteractiveElement.class) { getGUIDriver().focus(); for (org.openqa.selenium.Keys key : org.openqa.selenium.Keys.values()) { if (key.name().equals(theKey.name())) { builder.keyUp(getWebElement(), key).build().perform(); break; } } } } catch (Exception e) { throw new WidgetException("Error while performing key up using " + theKey.name(), getByLocator(), e); } }
public String pressKey(Keys theKey) { return keyboardActionObject + ".pressKey(Keys." + theKey.name() + ")"; }
/** * Returns sequence of backspaces and deletes that will clear element. * clear() can't be used because generates separate onchange event * See https://github.com/yandex-qatools/htmlelements/issues/65 */ public String getClearCharSequence() { return StringUtils.repeat(Keys.DELETE.toString() + Keys.BACK_SPACE, getText().length()); } }
@Override public void keyDown(Keys theKey) throws WidgetException { try { Actions builder = new Actions(getGUIDriver().getWrappedDriver()); synchronized (InteractiveElement.class) { getGUIDriver().focus(); for (org.openqa.selenium.Keys key : org.openqa.selenium.Keys.values()) { if (key.name().equals(theKey.name())) { builder.keyDown(getWebElement(), key).build().perform(); break; } } } } catch (Exception e) { throw new WidgetException("Error while performing key down using " + theKey.name(), getByLocator(), e); } }
public String keyDown(String webElement, Keys keys) { return builderActionObject + ".keyDown(" + webElement + ", Keys." + keys.name() + ")"; }
/** * Get the special key representation, {@link Keys}, of the supplied character if there is one. If * there is no special key tied to this character, null will be returned. * * @param key unicode character code * @return special key linked to the character code, or null if character is not a special key */ public static Keys getKeyFromUnicode(char key) { for (Keys unicodeKey : values()) { if (unicodeKey.charAt(0) == key) { return unicodeKey; } } return null; } }
/** * Simulate pressing many keys at once in a "chord". Takes a sequence of Keys.XXXX or strings; * appends each of the values to a string, and adds the chord termination key (Keys.NULL) and * returns the resultant string. * * Note: When the low-level webdriver key handlers see Keys.NULL, active modifier keys * (CTRL/ALT/SHIFT/etc) release via a keyup event. * * @param value characters to send * @return String representation of the char sequence */ public static String chord(CharSequence... value) { return chord(Arrays.asList(value)); }
/** * Returns sequence of backspaces and deletes that will clear element. * clear() can't be used because generates separate onchange event * See https://github.com/yandex-qatools/htmlelements/issues/65 */ public String getClearCharSequence() { return StringUtils.repeat(Keys.DELETE.toString() + Keys.BACK_SPACE, getText().length()); } }
@Override public void keyUp(Keys theKey) throws WidgetException { try { Actions builder = new Actions(getGUIDriver().getWrappedDriver()); synchronized (InteractiveElement.class) { getGUIDriver().focus(); for (org.openqa.selenium.Keys key : org.openqa.selenium.Keys.values()) { if (key.name().equals(theKey.name())) { builder.keyUp(getWebElement(), key).build().perform(); break; } } } } catch (Exception e) { throw new WidgetException("Error while performing key up using " + theKey.name(), getByLocator(), e); } }
public String keyUp(String webElement, Keys keys) { return builderActionObject + ".keyUp(" + webElement + ", Keys." + keys.name() + ")"; }