下面列出了org.openqa.selenium.remote.RemoteWebElement#setId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void encodesWrappedElementInMoveOrigin() {
RemoteWebElement innerElement = new RemoteWebElement();
innerElement.setId("12345");
WebElement element = new WrappedWebElement(innerElement);
PointerInput pointerInput = new PointerInput(Kind.MOUSE, null);
Interaction move = pointerInput.createPointerMove(
Duration.ofMillis(100), Origin.fromElement(element), 0, 0);
Sequence sequence = new Sequence(move.getSource(), 0).addAction(move);
String rawJson = new Json().toJson(sequence);
ActionSequenceJson json = new Json().toType(
rawJson,
ActionSequenceJson.class,
PropertySetting.BY_FIELD);
assertThat(json.actions).hasSize(1);
ActionJson firstAction = json.actions.get(0);
assertThat(firstAction.origin).containsEntry(W3C.getEncodedElementKey(), "12345");
}
@Test
public void testDecoratedElementsShouldBeUnwrapped() {
final RemoteWebElement element = new RemoteWebElement();
element.setId("foo");
WebDriver driver = mock(WebDriver.class);
when(driver.findElement(new ByIdOrName("element"))).thenReturn(element);
PublicPage page = new PublicPage();
PageFactory.initElements(driver, page);
Object seen = new WebElementToJsonConverter().apply(page.element);
Object expected = new WebElementToJsonConverter().apply(element);
assertThat(seen).isEqualTo(expected);
}
@SuppressWarnings("unchecked")
@Test
public void convertsAListWithAWebElement() {
RemoteWebElement element = new RemoteWebElement();
element.setId("abc123");
RemoteWebElement element2 = new RemoteWebElement();
element2.setId("anotherId");
Object value = CONVERTER.apply(asList(element, element2));
assertThat(value).isInstanceOf(Collection.class);
List<Object> list = new ArrayList<>((Collection<Object>) value);
assertThat(list).hasSize(2);
assertIsWebElementObject(list.get(0), "abc123");
assertIsWebElementObject(list.get(1), "anotherId");
}
@Test
public void convertsRemoteWebElementToWireProtocolMap() {
RemoteWebElement element = new RemoteWebElement();
element.setId("abc123");
Object value = CONVERTER.apply(element);
assertIsWebElementObject(value, "abc123");
}
@Test
public void unwrapsWrappedElements() {
RemoteWebElement element = new RemoteWebElement();
element.setId("abc123");
Object value = CONVERTER.apply(wrapElement(element));
assertIsWebElementObject(value, "abc123");
}
@Test
public void unwrapsWrappedElements_multipleLevelsOfWrapping() {
RemoteWebElement element = new RemoteWebElement();
element.setId("abc123");
WrappedWebElement wrapped = wrapElement(element);
wrapped = wrapElement(wrapped);
wrapped = wrapElement(wrapped);
wrapped = wrapElement(wrapped);
Object value = CONVERTER.apply(wrapped);
assertIsWebElementObject(value, "abc123");
}
@SuppressWarnings("unchecked")
@Test
public void convertsAMapWithAWebElement() {
RemoteWebElement element = new RemoteWebElement();
element.setId("abc123");
Object value = CONVERTER.apply(ImmutableMap.of("one", element));
assertThat(value).isInstanceOf(Map.class);
Map<String, Object> map = (Map<String, Object>) value;
assertThat(map.size()).isEqualTo(1);
assertIsWebElementObject(map.get("one"), "abc123");
}
@Test
public void convertsAnArrayWithAWebElement() {
RemoteWebElement element = new RemoteWebElement();
element.setId("abc123");
Object value = CONVERTER.apply(new Object[] { element });
assertContentsInOrder(new ArrayList<>((Collection<?>) value),
ImmutableMap.of(
Dialect.OSS.getEncodedElementKey(), "abc123",
Dialect.W3C.getEncodedElementKey(), "abc123"));
}