Skip to content

Commit

Permalink
Minor tweak to the ActionsTest
Browse files Browse the repository at this point in the history
This makes it easier for later work with the w3c
interactions to land cleanly. Notably, there's no
guarantee that `Actions.build` will return a
`CompositeAction`. Don't rely on that assumption.

In addition, because the only place that we relied
on `CompositeAction.getNumberOfActions` was for some
tests, this method has been marked deprecated.
  • Loading branch information
shs96c committed Feb 20, 2017
1 parent 763d78c commit 6b968f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public CompositeAction addAction(Action action) {
return this;
}

/**
* @deprecated No replacement.
*/
@VisibleForTesting
@Deprecated
int getNumberOfActions() {
return actionsList.size();
}
Expand Down
47 changes: 14 additions & 33 deletions java/client/test/org/openqa/selenium/interactions/ActionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.openqa.selenium.interactions;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
Expand Down Expand Up @@ -62,14 +61,7 @@ public void setUp() {

@Test
public void creatingAllKeyboardActions() {
Actions builder = new Actions(driver);

builder.keyDown(Keys.SHIFT).sendKeys("abc").keyUp(Keys.CONTROL);

CompositeAction returnedAction = (CompositeAction) builder.build();
returnedAction.perform();

assertEquals("Expected 3 keyboard actions", 3, returnedAction.getNumberOfActions());
new Actions(driver).keyDown(Keys.SHIFT).sendKeys("abc").keyUp(Keys.CONTROL).perform();

InOrder order = inOrder(mockMouse, mockKeyboard, mockCoordinates);
order.verify(mockKeyboard).pressKey(Keys.SHIFT);
Expand All @@ -80,14 +72,7 @@ public void creatingAllKeyboardActions() {

@Test
public void providingAnElementToKeyboardActions() {
Actions builder = new Actions(driver);

builder.keyDown(dummyLocatableElement, Keys.SHIFT);

CompositeAction returnedAction = (CompositeAction) builder.build();
returnedAction.perform();

assertEquals("Expected 1 keyboard action", 1, returnedAction.getNumberOfActions());
new Actions(driver).keyDown(dummyLocatableElement, Keys.SHIFT).perform();

InOrder order = inOrder(mockMouse, mockKeyboard, mockCoordinates);
order.verify(mockMouse).click(mockCoordinates);
Expand All @@ -103,18 +88,17 @@ public void supplyingIndividualElementsToKeyboardActions() {
final WebElement dummyElement2 = mockLocatableElementWithCoordinates(dummyCoordinates2);
final WebElement dummyElement3 = mockLocatableElementWithCoordinates(dummyCoordinates3);

Actions builder = new Actions(driver);

builder.keyDown(dummyLocatableElement, Keys.SHIFT)
new Actions(driver)
.keyDown(dummyLocatableElement, Keys.SHIFT)
.sendKeys(dummyElement2, "abc")
.keyUp(dummyElement3, Keys.CONTROL);

CompositeAction returnedAction = (CompositeAction) builder.build();
returnedAction.perform();

assertEquals("Expected 3 keyboard actions", 3, returnedAction.getNumberOfActions());

InOrder order = inOrder(mockMouse, mockKeyboard, mockCoordinates, dummyCoordinates2,
.keyUp(dummyElement3, Keys.CONTROL)
.perform();

InOrder order = inOrder(
mockMouse,
mockKeyboard,
mockCoordinates,
dummyCoordinates2,
dummyCoordinates3);
order.verify(mockMouse).click(mockCoordinates);
order.verify(mockKeyboard).pressKey(Keys.SHIFT);
Expand All @@ -127,17 +111,14 @@ public void supplyingIndividualElementsToKeyboardActions() {

@Test
public void creatingAllMouseActions() {
CompositeAction returnedAction = (CompositeAction) new Actions(driver)
new Actions(driver)
.clickAndHold(dummyLocatableElement)
.release(dummyLocatableElement)
.click(dummyLocatableElement)
.doubleClick(dummyLocatableElement)
.moveToElement(dummyLocatableElement)
.contextClick(dummyLocatableElement)
.build();

returnedAction.perform();
assertEquals("Expected 6 mouse actions", 6, returnedAction.getNumberOfActions());
.perform();

InOrder order = inOrder(mockMouse, mockKeyboard, mockCoordinates);
order.verify(mockMouse).mouseMove(mockCoordinates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.openqa.selenium.interactions;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;

import org.junit.Test;
Expand All @@ -26,27 +25,9 @@
import org.mockito.InOrder;
import org.mockito.Mockito;

/**
* Tests the CompositeAction class
*
*/
@RunWith(JUnit4.class)
public class CompositeActionTest {

@Test
public void addingActions() {
CompositeAction sequence = new CompositeAction();
final Action dummyAction1 = mock(Action.class);
final Action dummyAction2 = mock(Action.class, "dummy2");
final Action dummyAction3 = mock(Action.class, "dummy3");

sequence.addAction(dummyAction1)
.addAction(dummyAction2)
.addAction(dummyAction3);

assertEquals(3, sequence.getNumberOfActions());
}

@Test
public void invokingActions() {
CompositeAction sequence = new CompositeAction();
Expand Down

0 comments on commit 6b968f4

Please sign in to comment.