下面列出了怎么用org.openqa.selenium.remote.ExecuteMethod的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testMergesRemoteLogs() {
final ExecuteMethod executeMethod = mock(ExecuteMethod.class);
when(executeMethod.execute(
DriverCommand.GET_LOG, ImmutableMap.of(RemoteLogs.TYPE_KEY, LogType.PROFILER)))
.thenReturn(Arrays.asList(ImmutableMap.of(
"level", Level.INFO.getName(),
"timestamp", 1L,
"message", "second")));
LocalLogs localLogs = LocalLogs.getStoringLoggerInstance(singleton(LogType.PROFILER));
RemoteLogs logs = new RemoteLogs(executeMethod, localLogs);
localLogs.addEntry(LogType.PROFILER, new LogEntry(Level.INFO, 0, "first"));
localLogs.addEntry(LogType.PROFILER, new LogEntry(Level.INFO, 2, "third"));
List<LogEntry> entries = logs.get(LogType.PROFILER).getAll();
assertThat(entries).hasSize(3);
for (int i = 0; i < entries.size(); ++i) {
assertThat(entries.get(i).getTimestamp()).isEqualTo(i);
}
}
@Override
public ExecuteMethod getExecuteMethod() {
return executeMethod;
}
@Override
public HasDevTools getImplementation(Capabilities caps, ExecuteMethod executeMethod) {
Optional<DevTools> devTools = SeleniumCdpConnection.create(caps).map(DevTools::new);
return () -> devTools.orElseThrow(() -> new IllegalStateException("Unable to create connection to " + caps));
}
@Override
public LocationContext getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {
return new RemoteLocationContext(executeMethod);
}
public RemoteLocationContext(ExecuteMethod executeMethod) {
this.executeMethod = executeMethod;
}
@Override
public ApplicationCache getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {
return new RemoteApplicationCache(executeMethod);
}
public RemoteLocalStorage(ExecuteMethod executeMethod) {
this.executeMethod = executeMethod;
}
@Override
public WebStorage getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {
return new RemoteWebStorage(executeMethod);
}
public RemoteApplicationCache(ExecuteMethod executeMethod) {
this.executeMethod = executeMethod;
}
public RemoteWebStorage(ExecuteMethod executeMethod) {
this.executeMethod = executeMethod;
}
public RemoteSessionStorage(ExecuteMethod executeMethod) {
this.executeMethod = executeMethod;
}
public RemoteNetworkConnection(ExecuteMethod executeMethod) {
this.executeMethod = executeMethod;
}
@Override
public NetworkConnection getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {
return new RemoteNetworkConnection(executeMethod);
}