|
17 | 17 |
|
18 | 18 | package org.openqa.selenium.firefox;
|
19 | 19 |
|
| 20 | +import com.google.common.base.Throwables; |
| 21 | + |
20 | 22 | import org.openqa.selenium.Beta;
|
21 | 23 | import org.openqa.selenium.Capabilities;
|
22 | 24 | import org.openqa.selenium.WebDriverException;
|
23 |
| -import org.openqa.selenium.firefox.internal.MarionetteConnection; |
24 |
| -import org.openqa.selenium.interactions.ActionChainExecutor; |
25 |
| -import org.openqa.selenium.interactions.CanPerformActionChain; |
26 |
| -import org.openqa.selenium.internal.Lock; |
27 |
| -import org.openqa.selenium.remote.RemoteActionChainExecutor; |
28 |
| -import org.openqa.selenium.remote.RemoteExecuteMethod; |
| 25 | +import org.openqa.selenium.remote.DesiredCapabilities; |
| 26 | +import org.openqa.selenium.remote.FileDetector; |
| 27 | +import org.openqa.selenium.remote.RemoteWebDriver; |
| 28 | +import org.openqa.selenium.remote.service.DriverCommandExecutor; |
29 | 29 |
|
30 | 30 | /**
|
31 | 31 | * An implementation of the {#link WebDriver} interface that drives Firefox using Marionette interface.
|
32 | 32 | */
|
33 | 33 | @Beta
|
34 |
| -public class MarionetteDriver extends FirefoxDriver implements CanPerformActionChain { |
| 34 | +public class MarionetteDriver extends RemoteWebDriver { |
| 35 | + |
| 36 | + /** |
| 37 | + * Port which is used by default. |
| 38 | + */ |
| 39 | + private final static int DEFAULT_PORT = 0; |
35 | 40 |
|
36 | 41 | public MarionetteDriver() {
|
37 |
| - this(new FirefoxBinary(), null); |
| 42 | + this(null, null, DEFAULT_PORT); |
38 | 43 | }
|
39 | 44 |
|
40 |
| - public MarionetteDriver(FirefoxProfile profile) { |
41 |
| - super(profile); |
| 45 | + public MarionetteDriver(Capabilities capabilities) { |
| 46 | + this(null, capabilities, DEFAULT_PORT); |
42 | 47 | }
|
43 | 48 |
|
44 |
| - public MarionetteDriver(Capabilities desiredCapabilities) { |
45 |
| - super(desiredCapabilities); |
| 49 | + public MarionetteDriver(int port) { |
| 50 | + this(null, null, port); |
46 | 51 | }
|
47 | 52 |
|
48 |
| - public MarionetteDriver(Capabilities desiredCapabilities, Capabilities requiredCapabilities) { |
49 |
| - super(desiredCapabilities, requiredCapabilities); |
| 53 | + public MarionetteDriver(GeckoDriverService service) { |
| 54 | + this(service, null, DEFAULT_PORT); |
50 | 55 | }
|
51 | 56 |
|
52 |
| - public MarionetteDriver(FirefoxBinary binary, FirefoxProfile profile) { |
53 |
| - super(binary, profile); |
| 57 | + public MarionetteDriver(GeckoDriverService service, Capabilities capabilities) { |
| 58 | + this(service, capabilities, DEFAULT_PORT); |
54 | 59 | }
|
55 | 60 |
|
56 |
| - public MarionetteDriver(FirefoxBinary binary, FirefoxProfile profile, Capabilities capabilities) { |
57 |
| - super(binary, profile, capabilities); |
| 61 | + public MarionetteDriver(GeckoDriverService service, Capabilities capabilities, |
| 62 | + int port) { |
| 63 | + if (capabilities == null) { |
| 64 | + capabilities = DesiredCapabilities.internetExplorer(); |
| 65 | + } |
| 66 | + |
| 67 | + if (service == null) { |
| 68 | + service = setupService(capabilities, port); |
| 69 | + } |
| 70 | + run(service, capabilities); |
58 | 71 | }
|
59 | 72 |
|
60 |
| - public MarionetteDriver(FirefoxBinary binary, FirefoxProfile profile, |
61 |
| - Capabilities desiredCapabilities, Capabilities requiredCapabilities) { |
62 |
| - super(binary, profile, desiredCapabilities, requiredCapabilities); |
| 73 | + private void run(GeckoDriverService service, Capabilities capabilities) { |
| 74 | + setCommandExecutor(new DriverCommandExecutor(service)); |
| 75 | + |
| 76 | + startSession(capabilities); |
63 | 77 | }
|
64 | 78 |
|
65 |
| - protected ExtensionConnection connectTo(FirefoxBinary binary, FirefoxProfile profile, |
66 |
| - String host) { |
67 |
| - Lock lock = obtainLock(profile); |
| 79 | + @Override |
| 80 | + public void setFileDetector(FileDetector detector) { |
| 81 | + throw new WebDriverException( |
| 82 | + "Setting the file detector only works on remote webdriver instances obtained " + |
| 83 | + "via RemoteWebDriver"); |
| 84 | + } |
| 85 | + |
| 86 | + private GeckoDriverService setupService(Capabilities caps, int port) { |
68 | 87 | try {
|
69 |
| - FirefoxBinary bin = binary == null ? new FirefoxBinary() : binary; |
| 88 | + GeckoDriverService.Builder builder = new GeckoDriverService.Builder(); |
| 89 | + builder.usingPort(port); |
70 | 90 |
|
71 |
| - return new MarionetteConnection(lock, bin, profile, host); |
72 |
| - } catch (Exception e) { |
73 |
| - throw new WebDriverException(e); |
74 |
| - } |
75 |
| - } |
| 91 | + return builder.build(); |
76 | 92 |
|
77 |
| - public ActionChainExecutor getActionChainExecutor() { |
78 |
| - return new RemoteActionChainExecutor(new RemoteExecuteMethod(this)); |
| 93 | + } catch (IllegalStateException ex) { |
| 94 | + throw Throwables.propagate(ex); |
| 95 | + } |
79 | 96 | }
|
80 | 97 | }
|
0 commit comments