Search in sources :

Example 1 with Sequence

use of org.openqa.selenium.interactions.Sequence in project dollarx by loyada.

the class SingleBrowserPathIntegrationTest method DragAndDropToElement.

@Test
public void DragAndDropToElement() throws Operations.OperationFailedException {
    div.dragAndDrop().to(span);
    verify(((Interactive) driverMock)).perform(captor.capture());
    Object[] actions = captor.getAllValues().get(0).toArray();
    Sequence firstSequence = (Sequence) actions[0];
    Map<String, Object> keysActions = firstSequence.toJson();
    assertThat(keysActions.get("type"), equalTo("pointer"));
    List<Map<String, Object>> ops = (List<Map<String, Object>>) keysActions.get("actions");
    assertThat(ops.get(0).get("type"), equalTo("pointerMove"));
    assertThat(ops.get(0).get("origin"), is(webElement));
    assertThat(ops.get(1).get("type"), equalTo("pointerDown"));
    assertThat(ops.get(2).get("type"), equalTo("pointerMove"));
    assertThat(ops.get(2).get("origin"), is(webElement2));
    assertThat(ops.get(ops.size() - 1).get("type"), equalTo("pointerUp"));
}
Also used : List(java.util.List) Sequence(org.openqa.selenium.interactions.Sequence) Map(java.util.Map) Test(org.junit.Test)

Example 2 with Sequence

use of org.openqa.selenium.interactions.Sequence in project dollarx by loyada.

the class SingleBrowserPathIntegrationTest method sendKeysToElement.

@Test
public void sendKeysToElement() throws Operations.OperationFailedException {
    div.sendKeys("abc", "d");
    verify(((Interactive) driverMock)).perform(captor.capture());
    Object[] actions = captor.getAllValues().get(0).toArray();
    Sequence firstSequence = (Sequence) actions[0];
    final int keyboardInd = firstSequence.toJson().get("type").equals("key") ? 0 : 1;
    List<Map<String, Object>> ops = (List<Map<String, Object>>) ((Sequence) actions[keyboardInd]).toJson().get("actions");
    // first 3 actions are with pointer: move, clickdown, clickup
    List<Map<String, Object>> keysOps = ops.subList(3, ops.size());
    List<Object> keys = keysOps.stream().map(op -> op.get("value")).collect(Collectors.toList());
    assertEquals(keys, Arrays.asList("a", "a", "b", "b", "c", "c", "d", "d"));
    List<Object> opsTypesWithKeys = keysOps.stream().map(op -> op.get("type")).collect(Collectors.toList());
    assertEquals(opsTypesWithKeys, Arrays.asList("keyDown", "keyUp", "keyDown", "keyUp", "keyDown", "keyUp", "keyDown", "keyUp"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) Arrays(java.util.Arrays) SingleBrowserPath.div(com.github.loyada.jdollarx.singlebrowser.SingleBrowserPath.div) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) WebDriver(org.openqa.selenium.WebDriver) RunWith(org.junit.runner.RunWith) WebElement(org.openqa.selenium.WebElement) Captor(org.mockito.Captor) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) SingleBrowserPath.span(com.github.loyada.jdollarx.singlebrowser.SingleBrowserPath.span) Assert.assertThat(org.junit.Assert.assertThat) ArgumentCaptor(org.mockito.ArgumentCaptor) Map(java.util.Map) Interactive(org.openqa.selenium.interactions.Interactive) Before(org.junit.Before) Sequence(org.openqa.selenium.interactions.Sequence) By(org.openqa.selenium.By) Collection(java.util.Collection) Operations(com.github.loyada.jdollarx.Operations) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) List(java.util.List) Sequence(org.openqa.selenium.interactions.Sequence) Map(java.util.Map) Test(org.junit.Test)

Example 3 with Sequence

use of org.openqa.selenium.interactions.Sequence in project dollarx by loyada.

the class BrowserActionsIntegrationTest method DragAndDropToOffset.

@Test
public void DragAndDropToOffset() throws Operations.OperationFailedException {
    browser.dragAndDrop(BasicPath.div).to(10, 10);
    verify(((Interactive) driverMock)).perform(captor.capture());
    Object[] actions = captor.getAllValues().get(0).toArray();
    Sequence firstSequence = (Sequence) actions[0];
    Map<String, Object> keysActions = firstSequence.toJson();
    assertThat(keysActions.get("type"), equalTo("pointer"));
    List<Map<String, Object>> ops = (List<Map<String, Object>>) keysActions.get("actions");
    assertThat(ops.get(0).get("type"), equalTo("pointerMove"));
    assertThat(ops.get(0).get("origin"), is(webElement));
    assertThat(ops.get(1).get("type"), equalTo("pointerDown"));
    assertThat(ops.get(2).get("type"), equalTo("pointerMove"));
    assertThat(ops.get(2).get("x"), is(10));
    assertThat(ops.get(2).get("y"), is(10));
    assertThat(ops.get(ops.size() - 1).get("type"), equalTo("pointerUp"));
}
Also used : List(java.util.List) Sequence(org.openqa.selenium.interactions.Sequence) Map(java.util.Map) Test(org.junit.Test)

Example 4 with Sequence

use of org.openqa.selenium.interactions.Sequence in project dollarx by loyada.

the class BrowserActionsIntegrationTest method scroll.

@Test
public void scroll() {
    browser.scrollTo(BasicPath.div);
    verify(((Interactive) driverMock)).perform(captor.capture());
    Object[] actions = captor.getAllValues().get(0).toArray();
    Sequence firstSequence = (Sequence) actions[0];
    Map<String, Object> firstActions = firstSequence.toJson();
    assertThat(firstActions.get("type"), equalTo("pointer"));
    Map<String, Object> op = ((List<Map<String, Object>>) firstActions.get("actions")).get(0);
    assertThat(op.get("type"), equalTo("pointerMove"));
    assertThat(op.get("origin"), is(webElement));
}
Also used : List(java.util.List) Sequence(org.openqa.selenium.interactions.Sequence) Test(org.junit.Test)

Example 5 with Sequence

use of org.openqa.selenium.interactions.Sequence in project dollarx by loyada.

the class BrowserActionsIntegrationTest method sendKeysToBrowser.

@Test
public void sendKeysToBrowser() {
    browser.sendKeys("x", "yz").toBrowser();
    verify(((Interactive) driverMock)).perform(captor.capture());
    Object[] actions = captor.getAllValues().get(0).toArray();
    Sequence firstSequence = (Sequence) actions[0];
    assertThat(firstSequence.toJson().get("type"), equalTo("key"));
    List<Map<String, Object>> ops = (List<Map<String, Object>>) firstSequence.toJson().get("actions");
    List<Object> keys = ops.stream().map(op -> op.get("value")).collect(Collectors.toList());
    assertEquals(keys, Arrays.asList("x", "x", "y", "y", "z", "z"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) Arrays(java.util.Arrays) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) WebDriver(org.openqa.selenium.WebDriver) RunWith(org.junit.runner.RunWith) WebElement(org.openqa.selenium.WebElement) Captor(org.mockito.Captor) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) ArgumentCaptor(org.mockito.ArgumentCaptor) Map(java.util.Map) Interactive(org.openqa.selenium.interactions.Interactive) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) Sequence(org.openqa.selenium.interactions.Sequence) Keys(org.openqa.selenium.Keys) By(org.openqa.selenium.By) Collection(java.util.Collection) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) NoSuchElementException(org.openqa.selenium.NoSuchElementException) List(java.util.List) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) List(java.util.List) Sequence(org.openqa.selenium.interactions.Sequence) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Sequence (org.openqa.selenium.interactions.Sequence)20 List (java.util.List)17 Test (org.junit.Test)17 Map (java.util.Map)16 Collection (java.util.Collection)5 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)4 Arrays (java.util.Arrays)3 Collectors (java.util.stream.Collectors)3 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)3 CoreMatchers.is (org.hamcrest.CoreMatchers.is)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Before (org.junit.Before)3 RunWith (org.junit.runner.RunWith)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3 Captor (org.mockito.Captor)3 Mockito.mock (org.mockito.Mockito.mock)3 Mockito.verify (org.mockito.Mockito.verify)3 Mockito.when (org.mockito.Mockito.when)3 MockitoJUnitRunner (org.mockito.runners.MockitoJUnitRunner)3 By (org.openqa.selenium.By)3