Skip to content

Commit 923806a

Browse files
feat: Implementation of Chromium driver plus capabilities (#2003)
1 parent d8cf93c commit 923806a

11 files changed

+632
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.chromium;
18+
19+
import io.appium.java_client.AppiumClientConfig;
20+
import io.appium.java_client.AppiumDriver;
21+
import io.appium.java_client.remote.AutomationName;
22+
import io.appium.java_client.service.local.AppiumDriverLocalService;
23+
import io.appium.java_client.service.local.AppiumServiceBuilder;
24+
import org.openqa.selenium.Capabilities;
25+
import org.openqa.selenium.remote.HttpCommandExecutor;
26+
import org.openqa.selenium.remote.http.ClientConfig;
27+
import org.openqa.selenium.remote.http.HttpClient;
28+
29+
import java.net.URL;
30+
31+
/**
32+
* <p>ChromiumDriver is an officially supported Appium driver created to automate Mobile browsers
33+
* and web views based on the Chromium engine. The driver uses W3CWebDriver protocol and is built
34+
* on top of chromium driver server.</p>
35+
* <br>
36+
* <p>Read <a href='https://github.com/appium/appium-chromium-driver'>appium-chromium-driver</a>
37+
* for more details on how to configure and use it.</p>
38+
*/
39+
public class ChromiumDriver extends AppiumDriver {
40+
private static final String AUTOMATION_NAME = AutomationName.CHROMIUM;
41+
42+
public ChromiumDriver(HttpCommandExecutor executor, Capabilities capabilities) {
43+
super(executor, ensureAutomationName(capabilities, AUTOMATION_NAME));
44+
}
45+
46+
public ChromiumDriver(URL remoteAddress, Capabilities capabilities) {
47+
super(remoteAddress, ensureAutomationName(capabilities, AUTOMATION_NAME));
48+
}
49+
50+
public ChromiumDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities capabilities) {
51+
super(remoteAddress, httpClientFactory, ensureAutomationName(capabilities, AUTOMATION_NAME));
52+
}
53+
54+
public ChromiumDriver(AppiumDriverLocalService service, Capabilities capabilities) {
55+
super(service, ensureAutomationName(capabilities, AUTOMATION_NAME));
56+
}
57+
58+
public ChromiumDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,
59+
Capabilities capabilities) {
60+
super(service, httpClientFactory, ensureAutomationName(capabilities, AUTOMATION_NAME));
61+
}
62+
63+
public ChromiumDriver(AppiumServiceBuilder builder, Capabilities capabilities) {
64+
super(builder, ensureAutomationName(capabilities, AUTOMATION_NAME));
65+
}
66+
67+
public ChromiumDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory,
68+
Capabilities capabilities) {
69+
super(builder, httpClientFactory, ensureAutomationName(capabilities, AUTOMATION_NAME));
70+
}
71+
72+
public ChromiumDriver(HttpClient.Factory httpClientFactory, Capabilities capabilities) {
73+
super(httpClientFactory, ensureAutomationName(capabilities, AUTOMATION_NAME));
74+
}
75+
76+
/**
77+
* This is a special constructor used to connect to a running driver instance.
78+
* It does not do any necessary verifications, but rather assumes the given
79+
* driver session is already running at `remoteSessionAddress`.
80+
* The maintenance of driver state(s) is the caller's responsibility.
81+
* !!! This API is supposed to be used for **debugging purposes only**.
82+
*
83+
* @param remoteSessionAddress The address of the **running** session including the session identifier.
84+
* @param platformName The name of the target platform.
85+
*/
86+
public ChromiumDriver(URL remoteSessionAddress, String platformName) {
87+
super(remoteSessionAddress, platformName, AUTOMATION_NAME);
88+
}
89+
90+
/**
91+
* Creates a new instance based on the given ClientConfig and {@code capabilities}.
92+
* The HTTP client is default client generated by {@link HttpCommandExecutor#getDefaultClientFactory}.
93+
* For example:
94+
*
95+
* <pre>
96+
*
97+
* ClientConfig clientConfig = ClientConfig.defaultConfig()
98+
* .baseUri(URI.create("WebDriver URL"))
99+
* .readTimeout(Duration.ofMinutes(5));
100+
* ChromiumOptions options = new ChromiumOptions();
101+
* ChromiumDriver driver = new ChromiumDriver(clientConfig, options);
102+
*
103+
* </pre>
104+
*
105+
* @param clientConfig take a look at {@link ClientConfig}
106+
* @param capabilities take a look at {@link Capabilities}
107+
*
108+
*/
109+
public ChromiumDriver(ClientConfig clientConfig, Capabilities capabilities) {
110+
super(AppiumClientConfig.fromClientConfig(clientConfig), ensureAutomationName(capabilities, AUTOMATION_NAME));
111+
}
112+
113+
/**
114+
* Creates a new instance based on the given ClientConfig and {@code capabilities}.
115+
* The HTTP client is default client generated by {@link HttpCommandExecutor#getDefaultClientFactory}.
116+
* For example:
117+
*
118+
* <pre>
119+
*
120+
* AppiumClientConfig appiumClientConfig = AppiumClientConfig.defaultConfig()
121+
* .directConnect(true)
122+
* .baseUri(URI.create("WebDriver URL"))
123+
* .readTimeout(Duration.ofMinutes(5));
124+
* ChromiumOptions options = new ChromiumOptions();
125+
* ChromiumDriver driver = new ChromiumDriver(options, appiumClientConfig);
126+
*
127+
* </pre>
128+
*
129+
* @param appiumClientConfig take a look at {@link AppiumClientConfig}
130+
* @param capabilities take a look at {@link Capabilities}
131+
*
132+
*/
133+
public ChromiumDriver(AppiumClientConfig appiumClientConfig, Capabilities capabilities) {
134+
super(appiumClientConfig, ensureAutomationName(capabilities, AUTOMATION_NAME));
135+
}
136+
137+
public ChromiumDriver(Capabilities capabilities) {
138+
super(ensureAutomationName(capabilities, AUTOMATION_NAME));
139+
}
140+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.chromium.options;
18+
19+
import io.appium.java_client.remote.AutomationName;
20+
import io.appium.java_client.remote.options.BaseOptions;
21+
import io.appium.java_client.remote.options.SupportsBrowserNameOption;
22+
import org.openqa.selenium.Capabilities;
23+
24+
import java.util.Map;
25+
26+
/**
27+
* <p>Options class that sets options for Chromium when testing websites.</p>
28+
* <br>
29+
* @see <a href='https://github.com/appium/appium-chromium-driver#usage'>appium-chromium-driver usage section</a>
30+
*/
31+
public class ChromiumOptions extends BaseOptions<ChromiumOptions> implements
32+
SupportsBrowserNameOption<ChromiumOptions>,
33+
SupportsChromeDrivePortOption<ChromiumOptions>,
34+
SupportsExecutableOption<ChromiumOptions>,
35+
SupportsExecutableDirOption<ChromiumOptions>,
36+
SupportsVerboseOption<ChromiumOptions>,
37+
SupportsLogPathOption<ChromiumOptions>,
38+
SupportsBuildCheckOption<ChromiumOptions>,
39+
SupportsAutodownloadOption<ChromiumOptions>,
40+
SupportsUseSystemExecutableOption<ChromiumOptions> {
41+
public ChromiumOptions() {
42+
setCommonOptions();
43+
}
44+
45+
public ChromiumOptions(Capabilities source) {
46+
super(source);
47+
setCommonOptions();
48+
}
49+
50+
public ChromiumOptions(Map<String, ?> source) {
51+
super(source);
52+
setCommonOptions();
53+
}
54+
55+
private void setCommonOptions() {
56+
setAutomationName(AutomationName.CHROMIUM);
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.chromium.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.util.Optional;
24+
25+
import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean;
26+
27+
public interface SupportsAutodownloadOption<T extends BaseOptions<T>> extends
28+
Capabilities, CanSetCapability<T> {
29+
String AUTODOWNLOAD_ENABLED = "autodownloadEnabled";
30+
31+
/**
32+
* Set to false for disabling automatic downloading of Chrome drivers.
33+
* Unless disable build check preference has been user-set, the capability
34+
* is present because the default value is true.
35+
*
36+
* @param autodownloadEnabled flag.
37+
* @return self instance for chaining.
38+
*/
39+
default T setAutodownloadEnabled(boolean autodownloadEnabled) {
40+
return amend(AUTODOWNLOAD_ENABLED, autodownloadEnabled);
41+
}
42+
43+
/**
44+
* Get the auto download flag.
45+
*
46+
* @return auto download flag.
47+
*/
48+
default Optional<Boolean> isAutodownloadEnabled() {
49+
return Optional.ofNullable(toSafeBoolean(getCapability(AUTODOWNLOAD_ENABLED)));
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.chromium.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.util.Optional;
24+
25+
import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean;
26+
27+
public interface SupportsBuildCheckOption<T extends BaseOptions<T>> extends
28+
Capabilities, CanSetCapability<T> {
29+
String DISABLE_BUILD_CHECK = "disableBuildCheck";
30+
31+
/**
32+
* Set to true to add the --disable-build-check flag when starting WebDriver.
33+
* Unless disable build check preference has been user-set, the capability
34+
* is not present because the default value is false.
35+
*
36+
* @param BuildCheckDisabled flag for --disable-build-check.
37+
* @return self instance for chaining.
38+
*/
39+
default T setBuildCheckDisabled(boolean BuildCheckDisabled) {
40+
return amend(DISABLE_BUILD_CHECK, BuildCheckDisabled);
41+
}
42+
43+
/**
44+
* Get disable build check flag.
45+
*
46+
* @return disable build check flag.
47+
*/
48+
default Optional<Boolean> isBuildCheckDisabled() {
49+
return Optional.ofNullable(toSafeBoolean(getCapability(DISABLE_BUILD_CHECK)));
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.chromium.options;
18+
19+
import io.appium.java_client.remote.options.BaseOptions;
20+
import io.appium.java_client.remote.options.CanSetCapability;
21+
import org.openqa.selenium.Capabilities;
22+
23+
import java.util.Optional;
24+
25+
import static io.appium.java_client.internal.CapabilityHelpers.toInteger;
26+
27+
public interface SupportsChromeDrivePortOption<T extends BaseOptions<T>> extends
28+
Capabilities, CanSetCapability<T> {
29+
String CHROME_DRIVER_PORT = "chromedriverPort";
30+
31+
/**
32+
* The port to start WebDriver processes on. Unless the chrome drive port preference
33+
* has been user-set, it will listen on port 9515, which is the default
34+
* value for this capability.
35+
*
36+
* @param port port number in range 0..65535.
37+
* @return self instance for chaining.
38+
*/
39+
default T setChromeDriverPort(int port) {
40+
return amend(CHROME_DRIVER_PORT, port);
41+
}
42+
43+
/**
44+
* Get the number of the port for the chrome driver to listen on.
45+
*
46+
* @return Chrome driver port value.
47+
*/
48+
default Optional<Integer> getChromeDriverPort() {
49+
return Optional.ofNullable(toInteger(getCapability(CHROME_DRIVER_PORT)));
50+
}
51+
}

0 commit comments

Comments
 (0)