下面列出了怎么用org.openqa.selenium.opera.OperaDriverService的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public DriverService createService(int port) {
BrowserConfig config = BrowserConfig.instance();
String wdPath = config.getValue(BROWSER, "webdriver-exe-path");
OperaDriverService.Builder builder = new OperaDriverService.Builder();
if (wdPath != null)
builder.usingDriverExecutable(new File(wdPath));
String environ = config.getValue(BROWSER, "browser-environment");
if (environ != null) {
Map<String, String> envMap = new HashMap<>();
BufferedReader reader = new BufferedReader(new StringReader(environ));
String line = null;
try {
while ((line = reader.readLine()) != null) {
String[] parts = line.split("=");
if (parts != null && parts.length == 2) {
envMap.put(parts[0], parts[1]);
}
}
} catch (IOException e) {
}
builder.withEnvironment(envMap);
}
String logFile = config.getValue(BROWSER, "webdriver-log-file-path");
if (logFile != null) {
builder.withLogFile(new File(logFile));
}
builder.withVerbose(config.getValue(BROWSER, "webdriver-verbose", false));
builder.withSilent(config.getValue(BROWSER, "webdriver-silent", true));
return builder.usingPort(port).build();
}
private static URL getServiceUrl() {
if (service == null) {
service = OperaDriverService.createDefaultService();
try {
service.start();
} catch (IOException e) {
throw new RuntimeException(e);
}
// Fugly.
Runtime.getRuntime().addShutdownHook(new Thread(() -> service.stop()));
}
return service.getUrl();
}
/**
* Creates a new OperaDriver instance. The {@code service} will be started along with the
* driver, and shutdown upon calling {@link #quit()}.
*
* @param service The service to use.
* @param capabilities The capabilities required from the OperaDriver.
* @deprecated Use {@link #OperaDriver(OperaDriverService, OperaOptions)} instead.
*/
@Deprecated
public OperaDriver(OperaDriverService service, Capabilities capabilities) {
super(new DriverCommandExecutor(service), capabilities);
locationContext = new RemoteLocationContext(getExecuteMethod());
webStorage = new RemoteWebStorage(getExecuteMethod());
}
/**
* Creates a new OperaDriver using the {@link OperaDriverService#createDefaultService default}
* server configuration.
*
* @see #OperaDriver(OperaDriverService, OperaOptions)
*/
public OperaDriver() {
this(OperaDriverService.createDefaultService(), new OperaOptions());
}
/**
* Creates a new OperaDriver instance. The {@code service} will be started along with the driver,
* and shutdown upon calling {@link #quit()}.
*
* @param service The service to use.
* @see #OperaDriver(OperaDriverService, OperaOptions)
*/
public OperaDriver(OperaDriverService service) {
this(service, new OperaOptions());
}
/**
* Creates a new OperaDriver instance. The {@code capabilities} will be passed to the
* chromedriver service.
*
* @param capabilities The capabilities required from the OperaDriver.
* @see #OperaDriver(OperaDriverService, Capabilities)
* @deprecated Use {@link #OperaDriver(OperaOptions)} instead.
*/
@Deprecated
public OperaDriver(Capabilities capabilities) {
this(OperaDriverService.createDefaultService(), capabilities);
}
/**
* Creates a new OperaDriver instance with the specified options.
*
* @param options The options to use.
* @see #OperaDriver(OperaDriverService, OperaOptions)
*/
public OperaDriver(OperaOptions options) {
this(OperaDriverService.createDefaultService(), options);
}
/**
* Creates a new OperaDriver instance with the specified options. The {@code service} will be
* started along with the driver, and shutdown upon calling {@link #quit()}.
*
* @param service The service to use.
* @param options The options to use.
*/
public OperaDriver(OperaDriverService service, OperaOptions options) {
this(service, (Capabilities) options);
}