org.openqa.selenium.ImmutableCapabilities Java Examples

The following examples show how to use org.openqa.selenium.ImmutableCapabilities. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RemoteWebDriverUnitTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void canHandleElementCssPropertyCommand() throws IOException {
  CommandExecutor executor = prepareExecutorMock(echoCapabilities, valueResponder("red"));

  RemoteWebDriver driver = new RemoteWebDriver(executor, new ImmutableCapabilities());
  RemoteWebElement element = new RemoteWebElement();
  element.setParent(driver);
  element.setId(UUID.randomUUID().toString());

  String color = element.getCssValue("color");

  assertThat(color).isEqualTo("red");
  verifyCommands(
      executor, driver.getSessionId(),
      new CommandPayload(DriverCommand.GET_ELEMENT_VALUE_OF_CSS_PROPERTY,
                         ImmutableMap.of("id", element.getId(), "propertyName", "color")));
}
 
Example #2
Source File: RemoteSession.java    From selenium with Apache License 2.0 6 votes vote down vote up
protected RemoteSession(
    Dialect downstream,
    Dialect upstream,
    HttpHandler codec,
    SessionId id,
    Map<String, Object> capabilities) {
  this.downstream = Require.nonNull("Downstream dialect", downstream);
  this.upstream = Require.nonNull("Upstream dialect", upstream);
  this.codec = Require.nonNull("Codec", codec);
  this.id = Require.nonNull("Session id", id);
  this.capabilities = Require.nonNull("Capabilities", capabilities);

  File tempRoot = new File(StandardSystemProperty.JAVA_IO_TMPDIR.value(), id.toString());
  Require.stateCondition(tempRoot.mkdirs(), "Could not create directory %s", tempRoot);
  this.filesystem = TemporaryFilesystem.getTmpFsBasedOn(tempRoot);

  CommandExecutor executor = new ActiveSessionCommandExecutor(this);
  this.driver = new Augmenter().augment(new RemoteWebDriver(
      executor,
      new ImmutableCapabilities(getCapabilities())));
}
 
Example #3
Source File: RemoteWebDriverUnitTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void canHandleGetCookiesCommand() throws IOException {
  CommandExecutor executor = prepareExecutorMock(
      echoCapabilities,
      valueResponder(Arrays.asList(
          ImmutableMap.of("name", "cookie1", "value", "value1", "sameSite", "Lax"),
          ImmutableMap.of("name", "cookie2", "value", "value2"))));

  RemoteWebDriver driver = new RemoteWebDriver(executor, new ImmutableCapabilities());
  Set<Cookie> cookies = driver.manage().getCookies();

  assertThat(cookies)
      .hasSize(2)
      .contains(
          new Cookie.Builder("cookie1", "value1").sameSite("Lax").build(),
          new Cookie("cookie2", "value2"));
  verifyCommands(
      executor, driver.getSessionId(),
      new CommandPayload(DriverCommand.GET_ALL_COOKIES, ImmutableMap.of()));
}
 
Example #4
Source File: RemoteWebDriverUnitTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void canHandleElementGetAttributeCommand() throws IOException {
  CommandExecutor executor = prepareExecutorMock(echoCapabilities, valueResponder("test"));

  RemoteWebDriver driver = new RemoteWebDriver(executor, new ImmutableCapabilities());
  RemoteWebElement element = new RemoteWebElement();
  element.setParent(driver);
  element.setId(UUID.randomUUID().toString());

  String attr = element.getAttribute("id");

  assertThat(attr).isEqualTo("test");
  verifyCommands(
      executor, driver.getSessionId(),
      new CommandPayload(DriverCommand.GET_ELEMENT_ATTRIBUTE, ImmutableMap.of(
          "id", element.getId(), "name", "id")));
}
 
Example #5
Source File: NewSessionPayloadTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void convertEverythingToFirstMatchOnlyifPayloadContainsAlwaysMatchSectionAndOssCapabilities() {
  List<Capabilities> capabilities = create(ImmutableMap.of(
      "desiredCapabilities", ImmutableMap.of(
          "browserName", "firefox",
          "platform", "WINDOWS"),
      "capabilities", ImmutableMap.of(
          "alwaysMatch", singletonMap(
              "platformName", "macos"),
          "firstMatch", asList(
              singletonMap("browserName", "foo"),
              singletonMap("browserName", "firefox")))));

  assertEquals(asList(
      // From OSS
      new ImmutableCapabilities("browserName", "firefox", "platform", "WINDOWS"),
      // Generated from OSS
      new ImmutableCapabilities("browserName", "firefox", "platformName", "windows"),
      // From the actual W3C capabilities
      new ImmutableCapabilities("browserName", "foo", "platformName", "macos"),
      new ImmutableCapabilities("browserName", "firefox", "platformName", "macos")),
               capabilities);
}
 
Example #6
Source File: RemoteWebDriverScreenshotTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void testShouldBeAbleToDisableSnapshotOnException() {
  if (!(driver instanceof RemoteWebDriver)) {
    System.out.println("Skipping test: driver is not a remote webdriver");
    return;
  }

  Capabilities caps = new ImmutableCapabilities("webdriver.remote.quietExceptions", true);

  WebDriver noScreenshotDriver = new WebDriverBuilder().get(caps);

  noScreenshotDriver.get(pages.simpleTestPage);

  assertThatExceptionOfType(NoSuchElementException.class)
      .isThrownBy(() -> noScreenshotDriver.findElement(By.id("doesnayexist")))
      .satisfies(e -> {
        Throwable t = e;
        while (t != null) {
          assertThat(t).isNotInstanceOf(ScreenshotException.class);
          t = t.getCause();
        }
      });
}
 
Example #7
Source File: ActiveSessionFactoryTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void factoriesFoundViaServiceLoadersAreUsedFirst() {
  WebDriver driver = Mockito.mock(WebDriver.class);
  Capabilities caps = new ImmutableCapabilities("browserName", "chrome");
  DriverProvider provider = new StubbedProvider(caps, driver);

  ActiveSessionFactory sessionFactory = new ActiveSessionFactory(new NullTracer()) {
    @Override
    protected Iterable<DriverProvider> loadDriverProviders() {
      return ImmutableSet.of(provider);
    }
  };

  ActiveSession session = sessionFactory.apply(
      new CreateSessionRequest(ImmutableSet.of(Dialect.W3C), caps, ImmutableMap.of()))
      .get();
  assertEquals(driver, session.getWrappedDriver());
}
 
Example #8
Source File: ProtocolHandshakeTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void requestShouldIncludeJsonWireProtocolCapabilities() throws IOException {
  Map<String, Object> params = singletonMap("desiredCapabilities", new ImmutableCapabilities());
  Command command = new Command(null, DriverCommand.NEW_SESSION, params);

  HttpResponse response = new HttpResponse();
  response.setStatus(HTTP_OK);
  response.setContent(utf8String(
      "{\"value\": {\"sessionId\": \"23456789\", \"capabilities\": {}}}"));
  RecordingHttpClient client = new RecordingHttpClient(response);

  new ProtocolHandshake().createSession(client, command);

  Map<String, Object> json = getRequestPayloadAsMap(client);

  assertThat(json.get("desiredCapabilities")).isEqualTo(EMPTY_MAP);
}
 
Example #9
Source File: RedisBackedSessionMapTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void canGetTheUriOfASessionWithoutNeedingUrl() throws URISyntaxException {
  SessionMap sessions = new RedisBackedSessionMap(tracer, uri);

  Session expected = new Session(
    new SessionId(UUID.randomUUID()),
    new URI("http://example.com/foo"),
    new ImmutableCapabilities());
  sessions.add(expected);

  SessionMap reader = new RedisBackedSessionMap(tracer, uri);

  URI seen = reader.getUri(expected.getId());

  assertThat(seen).isEqualTo(expected.getUri());
}
 
Example #10
Source File: RemoteWebDriverUnitTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void canHandleElementGeRectCommand() throws IOException {
  CommandExecutor executor = prepareExecutorMock(
      echoCapabilities,
      valueResponder(ImmutableMap.of("x", 10, "y", 20, "width", 100, "height", 200)));

  RemoteWebDriver driver = new RemoteWebDriver(executor, new ImmutableCapabilities());
  RemoteWebElement element = new RemoteWebElement();
  element.setParent(driver);
  element.setId(UUID.randomUUID().toString());

  Rectangle rect = element.getRect();

  assertThat(rect).isEqualTo(new Rectangle(new Point(10, 20), new Dimension(100, 200)));
  verifyCommands(
      executor, driver.getSessionId(),
      new CommandPayload(DriverCommand.GET_ELEMENT_RECT, ImmutableMap.of("id", element.getId())));
}
 
Example #11
Source File: ProxyCdpTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldForwardTextMessageToServer() throws URISyntaxException, InterruptedException {
  HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();

  // Create a backend server which will capture any incoming text message
  AtomicReference<String> text = new AtomicReference<>();
  CountDownLatch latch = new CountDownLatch(1);
  Server<?> backend = createBackendServer(latch, text, "");

  // Push a session that resolves to the backend server into the session map
  SessionId id = new SessionId(UUID.randomUUID());
  sessions.add(new Session(id, backend.getUrl().toURI(), new ImmutableCapabilities()));

  // Now! Send a message. We expect it to eventually show up in the backend
  WebSocket socket = clientFactory.createClient(proxyServer.getUrl())
    .openSocket(new HttpRequest(GET, String.format("/session/%s/cdp", id)), new WebSocket.Listener(){});

  socket.sendText("Cheese!");

  assertThat(latch.await(5, SECONDS)).isTrue();
  assertThat(text.get()).isEqualTo("Cheese!");

  socket.close();
}
 
Example #12
Source File: LocalNodeTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws URISyntaxException {
  Tracer tracer = DefaultTestTracer.createTracer();
  EventBus bus = new GuavaEventBus();
  URI uri = new URI("http://localhost:1234");
  Capabilities stereotype = new ImmutableCapabilities("cheese", "brie");
  node = LocalNode.builder(tracer, bus, uri, uri, null)
      .add(stereotype, new TestSessionFactory((id, caps) -> new Session(id, uri, caps)))
      .build();

  CreateSessionResponse sessionResponse = node.newSession(
      new CreateSessionRequest(
          ImmutableSet.of(W3C),
          stereotype,
          ImmutableMap.of()))
      .orElseThrow(() -> new AssertionError("Unable to create session"));
  session = sessionResponse.getSession();
}
 
Example #13
Source File: ProtocolHandshakeTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void firstMatchSeparatesCapsForDifferentBrowsers() throws IOException {
  Capabilities caps = new ImmutableCapabilities(
      "moz:firefoxOptions", EMPTY_MAP,
      "browserName", "chrome");

  Map<String, Object> params = singletonMap("desiredCapabilities", caps);
  Command command = new Command(null, DriverCommand.NEW_SESSION, params);

  HttpResponse response = new HttpResponse();
  response.setStatus(HTTP_OK);
  response.setContent(utf8String(
      "{\"sessionId\": \"23456789\", \"status\": 0, \"value\": {}}"));
  RecordingHttpClient client = new RecordingHttpClient(response);

  new ProtocolHandshake().createSession(client, command);

  Map<String, Object> handshakeRequest = getRequestPayloadAsMap(client);

  List<Map<String, Object>> capabilities = mergeW3C(handshakeRequest);

  assertThat(capabilities).contains(
      singletonMap("moz:firefoxOptions", EMPTY_MAP),
      singletonMap("browserName", "chrome"));
}
 
Example #14
Source File: JsonWireProtocolResponseTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void successfulResponseGetsParsedProperly() {
  Capabilities caps = new ImmutableCapabilities("cheese", "peas");
  Map<String, ?> payload =
      ImmutableMap.of(
          "status", 0,
          "value", caps.asMap(),
          "sessionId", "cheese is opaque");
  InitialHandshakeResponse initialResponse = new InitialHandshakeResponse(
      0,
      200,
      payload);

  ProtocolHandshake.Result result =
      new JsonWireProtocolResponse().getResponseFunction().apply(initialResponse);

  assertThat(result).isNotNull();
  assertThat(result.getDialect()).isEqualTo(Dialect.OSS);
  Response response = result.createResponse();

  assertThat(response.getState()).isEqualTo("success");
  assertThat((int) response.getStatus()).isEqualTo(0);

  assertThat(response.getValue()).isEqualTo(caps.asMap());
}
 
Example #15
Source File: RemoteWebDriverUnitTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void canHandleSwitchToFrameByNameCommand() throws IOException {
  CommandExecutor executor = prepareExecutorMock(
      echoCapabilities,
      valueResponder(Arrays.asList(
          ImmutableMap.of(ELEMENT_KEY, UUID.randomUUID().toString()),
          ImmutableMap.of(ELEMENT_KEY, UUID.randomUUID().toString()))));

  RemoteWebDriver driver = new RemoteWebDriver(executor, new ImmutableCapabilities());
  WebDriver driver2 = driver.switchTo().frame("frameName");

  assertThat(driver2).isSameAs(driver);
  verify(executor).execute(argThat(
      command -> command.getName().equals(DriverCommand.NEW_SESSION)));
  verify(executor).execute(argThat(
      command -> command.getName().equals(DriverCommand.FIND_ELEMENTS)));
  verify(executor).execute(argThat(
      command -> Optional.of(command)
          .filter(cmd -> cmd.getName().equals(DriverCommand.SWITCH_TO_FRAME))
          .filter(cmd -> cmd.getParameters().size() == 1)
          .filter(cmd -> isWebElement(cmd.getParameters().get("id")))
          .isPresent()));
  verifyNoMoreInteractions(executor);
}
 
Example #16
Source File: NewSessionPipelineTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotUseFactoriesThatDoNotSupportTheCapabilities() {
  SessionFactory toBeIgnored = mock(SessionFactory.class);
  when(toBeIgnored.test(any())).thenReturn(false);
  when(toBeIgnored.apply(any())).thenThrow(new AssertionError("Must not be called"));

  ActiveSession session = mock(ActiveSession.class);
  SessionFactory toBeUsed = mock(SessionFactory.class);
  when(toBeUsed.test(any())).thenReturn(true);
  when(toBeUsed.apply(any())).thenReturn(Optional.of(session));

  NewSessionPipeline pipeline = NewSessionPipeline.builder()
      .add(toBeIgnored)
      .add(toBeUsed)
      .create();

  ActiveSession seen =
      pipeline.createNewSession(NewSessionPayload.create(new ImmutableCapabilities()));

  assertEquals(session, seen);
  verify(toBeIgnored, atLeast(1)).test(any());
}
 
Example #17
Source File: JsonWireProtocolResponseTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIgnoreAw3CProtocolReply() {
  Capabilities caps = new ImmutableCapabilities("cheese", "peas");
  Map<String, Map<String, Object>> payload =
      ImmutableMap.of(
          "value", ImmutableMap.of(
              "capabilities", caps.asMap(),
              "sessionId", "cheese is opaque"));
  InitialHandshakeResponse initialResponse = new InitialHandshakeResponse(
      0,
      200,
      payload);

  ProtocolHandshake.Result result =
      new JsonWireProtocolResponse().getResponseFunction().apply(initialResponse);

  assertThat(result).isNull();
}
 
Example #18
Source File: RedisBackedSessionMapTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void canCreateARedisBackedSessionMap() throws URISyntaxException {
  SessionMap sessions = new RedisBackedSessionMap(tracer, uri);

  Session expected = new Session(
    new SessionId(UUID.randomUUID()),
    new URI("http://example.com/foo"),
    new ImmutableCapabilities("cheese", "beyaz peynir"));
  sessions.add(expected);

  SessionMap reader = new RedisBackedSessionMap(tracer, uri);

  Session seen = reader.get(expected.getId());

  assertThat(seen).isEqualTo(expected);
}
 
Example #19
Source File: SyntheticNewSessionPayloadTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldDoNothingIfOssPayloadMatchesAValidMergedW3CPayload() {
  Map<String, String> caps = ImmutableMap.of(
      "browserName", "cheese",
      "se:cake", "more cheese");

  Map<String, Object> payload= ImmutableMap.of(
      "desiredCapabilities", caps,
      "capabilities", ImmutableMap.of(
          "alwaysMatch", ImmutableMap.of("browserName", "cheese"),
          "firstMatch", singletonList(ImmutableMap.of("se:cake", "more cheese"))));

  List<Capabilities> allCaps = getCapabilities(payload);

  assertThat(allCaps).containsExactly(new ImmutableCapabilities(caps));
}
 
Example #20
Source File: RemoteWebDriverUnitTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void canHandleExecuteScriptCommand() throws IOException {
  CommandExecutor executor = prepareExecutorMock(
      echoCapabilities, valueResponder("Hello, world!"));

  RemoteWebDriver driver = new RemoteWebDriver(executor, new ImmutableCapabilities());
  driver.setLogLevel(Level.WARNING);
  Object result = driver.executeScript("return 1", 1, "2");

  assertThat(result).isEqualTo("Hello, world!");
  verifyCommands(
      executor, driver.getSessionId(),
      new CommandPayload(DriverCommand.EXECUTE_SCRIPT, ImmutableMap.of(
          "script", "return 1", "args", Arrays.asList(1, "2"))));
}
 
Example #21
Source File: RemoteWebDriverUnitTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void canHandleAlertSendKeysCommand() throws IOException {
  CommandExecutor executor = prepareExecutorMock(
      echoCapabilities, valueResponder("Are you sure?"), nullResponder);

  RemoteWebDriver driver = new RemoteWebDriver(executor, new ImmutableCapabilities());
  driver.switchTo().alert().sendKeys("no");

  verifyCommands(
      executor, driver.getSessionId(),
      new CommandPayload(DriverCommand.GET_ALERT_TEXT, emptyMap()),
      new CommandPayload(DriverCommand.SET_ALERT_VALUE, ImmutableMap.of("text", "no")));
}
 
Example #22
Source File: RemoteWebDriverUnitTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void canHandleSwitchToAlertCommand() throws IOException {
  CommandExecutor executor = prepareExecutorMock(
      echoCapabilities, valueResponder("Alarm!"));

  RemoteWebDriver driver = new RemoteWebDriver(executor, new ImmutableCapabilities());
  Alert alert = driver.switchTo().alert();

  assertThat(alert.getText()).isEqualTo("Alarm!");
  verifyCommands(
      executor, driver.getSessionId(),
      new MultiCommandPayload(2, DriverCommand.GET_ALERT_TEXT, emptyMap()));
}
 
Example #23
Source File: SafariOptionsTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void roundTrippingToCapabilitiesAndBackWorks() {
  SafariOptions expected = new SafariOptions().setUseTechnologyPreview(true);

  // Convert to a Map so we can create a standalone capabilities instance, which we then use to
  // create a new set of options. This is the round trip, ladies and gentlemen.
  SafariOptions seen = new SafariOptions(new ImmutableCapabilities(expected.asMap()));

  assertThat(seen).isEqualTo(expected);
}
 
Example #24
Source File: EdgeDriverInfoTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void canDetectBrowserByVendorSpecificCapability() {
  assertThat(new EdgeDriverInfo()).is(supporting(
      new ImmutableCapabilities(EdgeOptions.CAPABILITY, Collections.emptyMap())));
  assertThat(new EdgeDriverInfo()).is(supporting(
      new ImmutableCapabilities("edgeOptions", Collections.emptyMap())));
}
 
Example #25
Source File: AugmenterTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotAddInterfaceWhenBooleanValueForItIsFalse() {
  Capabilities caps = new ImmutableCapabilities("magic.numbers", false);
  WebDriver driver = new RemoteWebDriver(new StubExecutor(caps), caps);

  WebDriver returned = getAugmenter()
    .addDriverAugmentation("magic.numbers", HasMagicNumbers.class, (c, exe) -> () -> 42)
    .augment(driver);

  assertThat(returned).isSameAs(driver);
  assertThat(returned).isNotInstanceOf(HasMagicNumbers.class);
}
 
Example #26
Source File: ProtocolHandshakeTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotIncludeNonProtocolExtensionKeys() throws IOException {
  Capabilities caps = new ImmutableCapabilities(
      "se:option", "cheese",
      "option", "I like sausages",
      "browserName", "amazing cake browser");

  Map<String, Object> params = singletonMap("desiredCapabilities", caps);
  Command command = new Command(null, DriverCommand.NEW_SESSION, params);

  HttpResponse response = new HttpResponse();
  response.setStatus(HTTP_OK);
  response.setContent(utf8String(
      "{\"sessionId\": \"23456789\", \"status\": 0, \"value\": {}}"));
  RecordingHttpClient client = new RecordingHttpClient(response);

  new ProtocolHandshake().createSession(client, command);

  Map<String, Object> handshakeRequest = getRequestPayloadAsMap(client);

  Object rawCaps = handshakeRequest.get("capabilities");
  assertThat(rawCaps).isInstanceOf(Map.class);

  Map<?, ?> capabilities = (Map<?, ?>) rawCaps;

  assertThat(capabilities.get("alwaysMatch")).isNull();
  List<Map<?, ?>> first = (List<Map<?, ?>>) capabilities.get("firstMatch");

  // We don't care where they are, but we want to see "se:option" and not "option"
  Set<String> keys = first.stream()
      .map(Map::keySet)
      .flatMap(Collection::stream)
      .map(String::valueOf).collect(Collectors.toSet());
  assertThat(keys)
      .contains("browserName", "se:option")
      .doesNotContain("options");
}
 
Example #27
Source File: JsonTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldConvertCapabilitiesToAMapAndIncludeCustomValues() {
  Capabilities caps = new ImmutableCapabilities("furrfu", "fishy");

  String raw = new Json().toJson(caps);
  Capabilities converted = new Json().toType(raw, Capabilities.class);

  assertThat(converted.getCapability("furrfu")).isEqualTo("fishy");
}
 
Example #28
Source File: JsonTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCoerceAListOfCapabilitiesIntoSomethingMutable() {
  // This is needed since Grid expects each of the capabilities to be mutable
  List<Capabilities> expected = Arrays.asList(
      new ImmutableCapabilities("cheese", "brie"),
      new ImmutableCapabilities("peas", 42L));

  Json json = new Json();
  String raw = json.toJson(expected);
  List<Capabilities> seen = json.toType(raw, new TypeToken<List<Capabilities>>(){}.getType());

  assertThat(seen).isEqualTo(expected);
  assertThat(seen.get(0)).isInstanceOf(MutableCapabilities.class);
}
 
Example #29
Source File: RemoteWebDriverUnitTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void canHandleSetWindowPositionCommand() throws IOException {
  CommandExecutor executor = prepareExecutorMock(echoCapabilities, nullResponder);

  RemoteWebDriver driver = new RemoteWebDriver(executor, new ImmutableCapabilities());
  driver.manage().window().setPosition(new Point(100, 200));

  verifyCommands(
      executor, driver.getSessionId(),
      new CommandPayload(DriverCommand.SET_CURRENT_WINDOW_POSITION,
                         ImmutableMap.of("x", 100, "y", 200)));
}
 
Example #30
Source File: InternetExplorerDriverTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@NoDriverBeforeTest
@NoDriverAfterTest
@NeedsLocalEnvironment
@Test
public void testPersistentHoverCanBeTurnedOff() throws Exception {
  createNewDriver(new ImmutableCapabilities(ENABLE_PERSISTENT_HOVERING, false));

  driver.get(pages.javascriptPage);
  // Move to a different element to make sure the mouse is not over the
  // element with id 'item1' (from a previous test).
  new Actions(driver).moveToElement(driver.findElement(By.id("keyUp"))).build().perform();
  WebElement element = driver.findElement(By.id("menu1"));

  final WebElement item = driver.findElement(By.id("item1"));
  assertThat(item.getText()).isEqualTo("");

  ((JavascriptExecutor) driver).executeScript("arguments[0].style.background = 'green'", element);
  new Actions(driver).moveToElement(element).build().perform();

  // Move the mouse somewhere - to make sure that the thread firing the events making
  // hover persistent is not active.
  Robot robot = new Robot();
  robot.mouseMove(50, 50);

  // Intentionally wait to make sure hover DOES NOT persist.
  Thread.sleep(1000);

  wait.until(elementTextToEqual(item, ""));

  assertThat(item.getText()).isEqualTo("");
}