19
19
package org .openqa .selenium .chrome ;
20
20
21
21
import org .openqa .selenium .Capabilities ;
22
- import org .openqa .selenium .OutputType ;
23
22
import org .openqa .selenium .WebDriver ;
24
23
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 ;
26
29
import org .openqa .selenium .remote .FileDetector ;
27
30
import org .openqa .selenium .remote .RemoteWebDriver ;
31
+ import org .openqa .selenium .remote .html5 .RemoteLocationContext ;
32
+ import org .openqa .selenium .remote .html5 .RemoteWebStorage ;
28
33
import org .openqa .selenium .remote .service .DriverCommandExecutor ;
29
34
30
35
/**
39
44
*
40
45
* import static org.junit.Assert.assertEquals;
41
46
*
42
- * import org.junit.After;
43
- * import org.junit.AfterClass;
44
- * import org.junit.Before;
45
- * import org.junit.BeforeClass;
47
+ * import org.junit.*;
46
48
* import org.junit.runner.RunWith;
47
- * import org.junit.runners.BlockJUnit4ClassRunner
49
+ * import org.junit.runners.JUnit4;
48
50
* import org.openqa.selenium.chrome.ChromeDriverService;
49
51
* import org.openqa.selenium.remote.DesiredCapabilities;
50
52
* import org.openqa.selenium.remote.RemoteWebDriver;
51
53
*
52
- * {@literal @RunWith(BlockJUnit4ClassRunner .class)}
54
+ * {@literal @RunWith(JUnit4 .class)}
53
55
* public class ChromeTest extends TestCase {
54
56
*
55
57
* private static ChromeDriverService service;
89
91
* assertEquals("webdriver - Google Search", driver.getTitle());
90
92
* }
91
93
* }
92
- *
93
94
* </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
+ *
95
102
* @see ChromeDriverService#createDefaultService
96
103
*/
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 ;
98
109
99
110
/**
100
111
* Creates a new ChromeDriver using the {@link ChromeDriverService#createDefaultService default}
@@ -158,6 +169,8 @@ public ChromeDriver(ChromeDriverService service, ChromeOptions options) {
158
169
*/
159
170
public ChromeDriver (ChromeDriverService service , Capabilities capabilities ) {
160
171
super (new DriverCommandExecutor (service ), capabilities );
172
+ locationContext = new RemoteLocationContext (getExecuteMethod ());
173
+ webStorage = new RemoteWebStorage (getExecuteMethod ());
161
174
}
162
175
163
176
@ Override
@@ -167,10 +180,23 @@ public void setFileDetector(FileDetector detector) {
167
180
"via RemoteWebDriver" );
168
181
}
169
182
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 );
175
201
}
176
202
}
0 commit comments