The user-facing API for emulating complex user gestures. Use this class rather than using the Keyboard or Mouse directly. Implements the builder pattern: Builds a CompositeAction containing all actions specified by the method calls. Call #perform() at the end of the method chain to a
| 46 | * <p>Call {@link #perform()} at the end of the method chain to actually perform the actions. |
| 47 | */ |
| 48 | public class Actions { |
| 49 | |
| 50 | private final WebDriver driver; |
| 51 | |
| 52 | // W3C |
| 53 | private final Map<InputSource, Sequence> sequences = new HashMap<>(); |
| 54 | |
| 55 | private @Nullable PointerInput activePointer; |
| 56 | private @Nullable KeyInput activeKeyboard; |
| 57 | private @Nullable WheelInput activeWheel; |
| 58 | private final Duration actionDuration; |
| 59 | |
| 60 | public Actions(WebDriver driver) { |
| 61 | this(driver, Duration.ofMillis(250)); |
| 62 | } |
| 63 | |
| 64 | public Actions(WebDriver driver, Duration duration) { |
| 65 | this.driver = Require.nonNull("Driver", driver); |
| 66 | this.actionDuration = duration; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Performs a modifier key press. Does not release the modifier key - subsequent interactions may |
| 71 | * assume it's kept pressed. Note that the modifier key is <b>never</b> released implicitly - |
| 72 | * either <i>keyUp(theKey)</i> or <i>sendKeys(Keys.NULL)</i> must be called to release the |
| 73 | * modifier. |
| 74 | * |
| 75 | * @param key |
| 76 | * @return A self reference. |
| 77 | */ |
| 78 | public Actions keyDown(CharSequence key) { |
| 79 | return addKeyAction(key, codePoint -> tick(getActiveKeyboard().createKeyDown(codePoint))); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Performs a modifier key press after focusing on an element. Equivalent to: |
| 84 | * <i>Actions.click(element).sendKeys(theKey);</i> |
| 85 | * |
| 86 | * @see #keyDown(CharSequence) |
| 87 | * @param key |
| 88 | * @param target WebElement to perform the action |
| 89 | * @return A self reference. |
| 90 | */ |
| 91 | public Actions keyDown(WebElement target, CharSequence key) { |
| 92 | return focusInTicks(target) |
| 93 | .addKeyAction(key, codepoint -> tick(getActiveKeyboard().createKeyDown(codepoint))); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Performs a modifier key release. Releasing a non-depressed modifier key will yield undefined |
| 98 | * behaviour. |
| 99 | * |
| 100 | * @param key |
| 101 | * @return A self reference. |
| 102 | */ |
| 103 | public Actions keyUp(CharSequence key) { |
| 104 | return addKeyAction(key, codePoint -> tick(getActiveKeyboard().createKeyUp(codePoint))); |
| 105 | } |
nothing calls this directly
no outgoing calls
no test coverage detected