[java] Making TestChromeDriver a subclass of ChromeDriver
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.OutputType;
+import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
-import org.openqa.selenium.html5.LocalStorage;
-import org.openqa.selenium.html5.Location;
-import org.openqa.selenium.html5.LocationContext;
-import org.openqa.selenium.html5.SessionStorage;
-import org.openqa.selenium.html5.WebStorage;
import org.openqa.selenium.remote.DriverCommand;
-import org.openqa.selenium.remote.RemoteWebDriver;
-import org.openqa.selenium.remote.html5.RemoteLocationContext;
-import org.openqa.selenium.remote.html5.RemoteWebStorage;
import java.io.File;
import java.io.IOException;
-import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
* entire test suite. We do not use {@link org.openqa.selenium.chrome.ChromeDriver} since that starts and stops the service
* with each instance (and that is too expensive for our purposes).
*/
-public class TestChromeDriver extends RemoteWebDriver implements WebStorage, LocationContext {
+public class TestChromeDriver extends ChromeDriver {
private final static Logger LOG = Logger.getLogger(TestChromeDriver.class.getName());
- private static ChromeDriverService service;
- private RemoteWebStorage webStorage;
- private RemoteLocationContext locationContext;
-
public TestChromeDriver(Capabilities capabilities) {
- super(getServiceUrl(), chromeWithCustomCapabilities(capabilities));
- webStorage = new RemoteWebStorage(getExecuteMethod());
- locationContext = new RemoteLocationContext(getExecuteMethod());
+ super(getService(), chromeWithCustomCapabilities(capabilities));
}
- private static URL getServiceUrl() {
+ private static ChromeDriverService getService() {
try {
- if (service == null) {
Path logFile = Files.createTempFile("chromedriver", ".log");
- service = new ChromeDriverService.Builder()
+ ChromeDriverService service = new ChromeDriverService.Builder()
.withVerbose(true)
.withLogFile(logFile.toFile())
.build();
@@ -70,8 +55,7 @@ private static URL getServiceUrl() {
service.start();
// Fugly.
Runtime.getRuntime().addShutdownHook(new Thread(() -> service.stop()));
- }
- return service.getUrl();
+ return service;
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -103,24 +87,4 @@ private static Capabilities chromeWithCustomCapabilities(Capabilities originalCa
// ... and convert it.
return target.convertFromBase64Png(base64);
}
-
- @Override
- public LocalStorage getLocalStorage() {
- return webStorage.getLocalStorage();
- }
-
- @Override
- public SessionStorage getSessionStorage() {
- return webStorage.getSessionStorage();
- }
-
- @Override
- public Location location() {
- return locationContext.location();
- }
-
- @Override
- public void setLocation(Location location) {
- locationContext.setLocation(location);
- }
}
