Skip to content

Commit f93ea6f

Browse files
sevasevajleyba
authored andcommitted
Making ChromeDriver directly implement the interfaces representing features it implements.
Currently, LocationContext and WebStorage are the only capabilities chromedriver returns, regardless of the kind of Chrome browser it is driving. Augmentation never worked well on ChromeDriver, e.g. issue 6681 , and at times has been completely broken. Because default ChromeDriver constructor starts a new session it cannot be augmented without consequences. A workaround has not been found. Overriding getScreenshotAs() is dropped as redundant, RemoteWebDriver implementation works identically. Signed-off-by: Jason Leyba <jmleyba@gmail.com>
1 parent d18fcc7 commit f93ea6f

File tree

2 files changed

+44
-16
lines changed

2 files changed

+44
-16
lines changed

Diff for: java/client/src/org/openqa/selenium/chrome/ChromeDriver.java

+42-16
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@
1919
package org.openqa.selenium.chrome;
2020

2121
import org.openqa.selenium.Capabilities;
22-
import org.openqa.selenium.OutputType;
2322
import org.openqa.selenium.WebDriver;
2423
import org.openqa.selenium.WebDriverException;
25-
import org.openqa.selenium.remote.DriverCommand;
24+
import org.openqa.selenium.html5.LocalStorage;
25+
import org.openqa.selenium.html5.Location;
26+
import org.openqa.selenium.html5.LocationContext;
27+
import org.openqa.selenium.html5.SessionStorage;
28+
import org.openqa.selenium.html5.WebStorage;
2629
import org.openqa.selenium.remote.FileDetector;
2730
import org.openqa.selenium.remote.RemoteWebDriver;
31+
import org.openqa.selenium.remote.html5.RemoteLocationContext;
32+
import org.openqa.selenium.remote.html5.RemoteWebStorage;
2833
import org.openqa.selenium.remote.service.DriverCommandExecutor;
2934

3035
/**
@@ -39,17 +44,14 @@
3944
*
4045
* import static org.junit.Assert.assertEquals;
4146
*
42-
* import org.junit.After;
43-
* import org.junit.AfterClass;
44-
* import org.junit.Before;
45-
* import org.junit.BeforeClass;
47+
* import org.junit.*;
4648
* import org.junit.runner.RunWith;
47-
* import org.junit.runners.BlockJUnit4ClassRunner
49+
* import org.junit.runners.JUnit4;
4850
* import org.openqa.selenium.chrome.ChromeDriverService;
4951
* import org.openqa.selenium.remote.DesiredCapabilities;
5052
* import org.openqa.selenium.remote.RemoteWebDriver;
5153
*
52-
* {@literal @RunWith(BlockJUnit4ClassRunner.class)}
54+
* {@literal @RunWith(JUnit4.class)}
5355
* public class ChromeTest extends TestCase {
5456
*
5557
* private static ChromeDriverService service;
@@ -89,12 +91,21 @@
8991
* assertEquals("webdriver - Google Search", driver.getTitle());
9092
* }
9193
* }
92-
*
9394
* </pre></code>
94-
*
95+
*
96+
* Note that unlike ChromeDriver, RemoteWebDriver doesn't directly implement
97+
* role interfaces such as {@link LocationContext} and {@link WebStorage}.
98+
* Therefore, to access that functionality, it needs to be
99+
* {@link org.openqa.selenium.remote.Augmenter augmented} and then cast
100+
* to the appropriate interface.
101+
*
95102
* @see ChromeDriverService#createDefaultService
96103
*/
97-
public class ChromeDriver extends RemoteWebDriver {
104+
public class ChromeDriver extends RemoteWebDriver
105+
implements LocationContext, WebStorage {
106+
107+
private RemoteLocationContext locationContext;
108+
private RemoteWebStorage webStorage;
98109

99110
/**
100111
* Creates a new ChromeDriver using the {@link ChromeDriverService#createDefaultService default}
@@ -158,6 +169,8 @@ public ChromeDriver(ChromeDriverService service, ChromeOptions options) {
158169
*/
159170
public ChromeDriver(ChromeDriverService service, Capabilities capabilities) {
160171
super(new DriverCommandExecutor(service), capabilities);
172+
locationContext = new RemoteLocationContext(getExecuteMethod());
173+
webStorage = new RemoteWebStorage(getExecuteMethod());
161174
}
162175

163176
@Override
@@ -167,10 +180,23 @@ public void setFileDetector(FileDetector detector) {
167180
"via RemoteWebDriver");
168181
}
169182

170-
public <X> X getScreenshotAs(OutputType<X> target) {
171-
// Get the screenshot as base64.
172-
String base64 = (String) execute(DriverCommand.SCREENSHOT).getValue();
173-
// ... and convert it.
174-
return target.convertFromBase64Png(base64);
183+
@Override
184+
public LocalStorage getLocalStorage() {
185+
return webStorage.getLocalStorage();
186+
}
187+
188+
@Override
189+
public SessionStorage getSessionStorage() {
190+
return webStorage.getSessionStorage();
191+
}
192+
193+
@Override
194+
public Location location() {
195+
return locationContext.location();
196+
}
197+
198+
@Override
199+
public void setLocation(Location location) {
200+
locationContext.setLocation(location);
175201
}
176202
}

Diff for: java/client/src/org/openqa/selenium/chrome/build.desc

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
java_library(name = "chrome",
33
srcs = [ "*.java" ],
44
deps = [
5+
"//java/client/src/org/openqa/selenium:base",
6+
"//java/client/src/org/openqa/selenium:webdriver-api",
57
"//java/client/src/org/openqa/selenium/net",
68
"//java/client/src/org/openqa/selenium/remote",
79
"//java/client/src/org/openqa/selenium/remote/service",

0 commit comments

Comments
 (0)