From fef69d29bcd3b0170fec76add7c4e27b3c1f1ba3 Mon Sep 17 00:00:00 2001 From: Alessandro Miccoli Date: Tue, 5 Sep 2023 20:10:13 +0100 Subject: [PATCH 1/7] ISSUE_1995 feat: add Chromium Driver --- .../java_client/chromium/ChromiumDriver.java | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 src/main/java/io/appium/java_client/chromium/ChromiumDriver.java diff --git a/src/main/java/io/appium/java_client/chromium/ChromiumDriver.java b/src/main/java/io/appium/java_client/chromium/ChromiumDriver.java new file mode 100644 index 000000000..e340557c4 --- /dev/null +++ b/src/main/java/io/appium/java_client/chromium/ChromiumDriver.java @@ -0,0 +1,140 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.chromium; + +import io.appium.java_client.AppiumClientConfig; +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.remote.AutomationName; +import io.appium.java_client.service.local.AppiumDriverLocalService; +import io.appium.java_client.service.local.AppiumServiceBuilder; +import org.openqa.selenium.Capabilities; +import org.openqa.selenium.remote.HttpCommandExecutor; +import org.openqa.selenium.remote.http.ClientConfig; +import org.openqa.selenium.remote.http.HttpClient; + +import java.net.URL; + +/** + *

ChromiumDriver is an officially supported Appium driver created to automate Mobile browsers + * and web views based on the Chromium engine. The driver uses W3CWebDriver protocol and is built + * on top of chromium driver server.

+ *
+ *

Read appium-chromium-driver + * for more details on how to configure and use it.

+ */ +public class ChromiumDriver extends AppiumDriver { + private static final String AUTOMATION_NAME = AutomationName.CHROMIUM; + + public ChromiumDriver(HttpCommandExecutor executor, Capabilities capabilities) { + super(executor, ensureAutomationName(capabilities, AUTOMATION_NAME)); + } + + public ChromiumDriver(URL remoteAddress, Capabilities capabilities) { + super(remoteAddress, ensureAutomationName(capabilities, AUTOMATION_NAME)); + } + + public ChromiumDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities capabilities) { + super(remoteAddress, httpClientFactory, ensureAutomationName(capabilities, AUTOMATION_NAME)); + } + + public ChromiumDriver(AppiumDriverLocalService service, Capabilities capabilities) { + super(service, ensureAutomationName(capabilities, AUTOMATION_NAME)); + } + + public ChromiumDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory, + Capabilities capabilities) { + super(service, httpClientFactory, ensureAutomationName(capabilities, AUTOMATION_NAME)); + } + + public ChromiumDriver(AppiumServiceBuilder builder, Capabilities capabilities) { + super(builder, ensureAutomationName(capabilities, AUTOMATION_NAME)); + } + + public ChromiumDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory, + Capabilities capabilities) { + super(builder, httpClientFactory, ensureAutomationName(capabilities, AUTOMATION_NAME)); + } + + public ChromiumDriver(HttpClient.Factory httpClientFactory, Capabilities capabilities) { + super(httpClientFactory, ensureAutomationName(capabilities, AUTOMATION_NAME)); + } + + /** + * This is a special constructor used to connect to a running driver instance. + * It does not do any necessary verifications, but rather assumes the given + * driver session is already running at `remoteSessionAddress`. + * The maintenance of driver state(s) is the caller's responsibility. + * !!! This API is supposed to be used for **debugging purposes only**. + * + * @param remoteSessionAddress The address of the **running** session including the session identifier. + * @param platformName The name of the target platform. + */ + public ChromiumDriver(URL remoteSessionAddress, String platformName) { + super(remoteSessionAddress, platformName, AUTOMATION_NAME); + } + + /** + * Creates a new instance based on the given ClientConfig and {@code capabilities}. + * The HTTP client is default client generated by {@link HttpCommandExecutor#getDefaultClientFactory}. + * For example: + * + *
+     *
+     * ClientConfig clientConfig = ClientConfig.defaultConfig()
+     *     .baseUri(URI.create("WebDriver URL"))
+     *     .readTimeout(Duration.ofMinutes(5));
+     * ChromiumOptions options = new ChromiumOptions();
+     * ChromiumDriver driver = new ChromiumDriver(clientConfig, options);
+     *
+     * 
+ * + * @param clientConfig take a look at {@link ClientConfig} + * @param capabilities take a look at {@link Capabilities} + * + */ + public ChromiumDriver(ClientConfig clientConfig, Capabilities capabilities) { + super(AppiumClientConfig.fromClientConfig(clientConfig), ensureAutomationName(capabilities, AUTOMATION_NAME)); + } + + /** + * Creates a new instance based on the given ClientConfig and {@code capabilities}. + * The HTTP client is default client generated by {@link HttpCommandExecutor#getDefaultClientFactory}. + * For example: + * + *
+     *
+     * AppiumClientConfig appiumClientConfig = AppiumClientConfig.defaultConfig()
+     *     .directConnect(true)
+     *     .baseUri(URI.create("WebDriver URL"))
+     *     .readTimeout(Duration.ofMinutes(5));
+     * ChromiumOptions options = new ChromiumOptions();
+     * ChromiumDriver driver = new ChromiumDriver(options, appiumClientConfig);
+     *
+     * 
+ * + * @param appiumClientConfig take a look at {@link AppiumClientConfig} + * @param capabilities take a look at {@link Capabilities} + * + */ + public ChromiumDriver(AppiumClientConfig appiumClientConfig, Capabilities capabilities) { + super(appiumClientConfig, ensureAutomationName(capabilities, AUTOMATION_NAME)); + } + + public ChromiumDriver(Capabilities capabilities) { + super(ensureAutomationName(capabilities, AUTOMATION_NAME)); + } +} From 3b24fe45530f8455041599c765657330bbc2bfcf Mon Sep 17 00:00:00 2001 From: Alessandro Miccoli Date: Tue, 5 Sep 2023 20:11:08 +0100 Subject: [PATCH 2/7] ISSUE_1995 feat: add Chromium Options --- .../chromium/options/ChromiumOptions.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/main/java/io/appium/java_client/chromium/options/ChromiumOptions.java diff --git a/src/main/java/io/appium/java_client/chromium/options/ChromiumOptions.java b/src/main/java/io/appium/java_client/chromium/options/ChromiumOptions.java new file mode 100644 index 000000000..95cf303bf --- /dev/null +++ b/src/main/java/io/appium/java_client/chromium/options/ChromiumOptions.java @@ -0,0 +1,55 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.chromium.options; + +import io.appium.java_client.mac.options.SupportsSystemPortOption; +import io.appium.java_client.remote.AutomationName; +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.SupportsAcceptInsecureCertsOption; +import io.appium.java_client.remote.options.SupportsBrowserNameOption; +import io.appium.java_client.remote.options.SupportsBrowserVersionOption; +import io.appium.java_client.remote.options.SupportsPageLoadStrategyOption; +import io.appium.java_client.remote.options.SupportsProxyOption; +import io.appium.java_client.remote.options.SupportsSetWindowRectOption; +import io.appium.java_client.remote.options.SupportsUnhandledPromptBehaviorOption; +import org.openqa.selenium.Capabilities; + +import java.util.Map; + +/** + * appium-chromium-driver usage section + */ +public class ChromiumOptions extends BaseOptions +{ + public ChromiumOptions() { + setCommonOptions(); + } + + public ChromiumOptions(Capabilities source) { + super(source); + setCommonOptions(); + } + + public ChromiumOptions(Map source) { + super(source); + setCommonOptions(); + } + + private void setCommonOptions() { + setAutomationName(AutomationName.CHROMIUM); + } +} From 8566f01eff92afdc046e4a305cd495a72ba002e6 Mon Sep 17 00:00:00 2001 From: Alessandro Miccoli Date: Tue, 5 Sep 2023 21:07:52 +0100 Subject: [PATCH 3/7] ISSUE_1995 feat: add the appium capabilities of appium-chromium-driver --- .../chromium/options/ChromiumOptions.java | 22 ++++---- .../options/SupportsAutodownloadOption.java | 51 ++++++++++++++++++ .../options/SupportsBuildCheckOption.java | 51 ++++++++++++++++++ .../SupportsChromeDrivePortOption.java | 51 ++++++++++++++++++ .../options/SupportsExecutableDirOption.java | 49 +++++++++++++++++ .../options/SupportsExecutableOption.java | 50 +++++++++++++++++ .../options/SupportsLogPathOption.java | 48 +++++++++++++++++ .../SupportsUseSystemExecutableOption.java | 53 +++++++++++++++++++ .../options/SupportsVerboseOption.java | 51 ++++++++++++++++++ 9 files changed, 416 insertions(+), 10 deletions(-) create mode 100644 src/main/java/io/appium/java_client/chromium/options/SupportsAutodownloadOption.java create mode 100644 src/main/java/io/appium/java_client/chromium/options/SupportsBuildCheckOption.java create mode 100644 src/main/java/io/appium/java_client/chromium/options/SupportsChromeDrivePortOption.java create mode 100644 src/main/java/io/appium/java_client/chromium/options/SupportsExecutableDirOption.java create mode 100644 src/main/java/io/appium/java_client/chromium/options/SupportsExecutableOption.java create mode 100644 src/main/java/io/appium/java_client/chromium/options/SupportsLogPathOption.java create mode 100644 src/main/java/io/appium/java_client/chromium/options/SupportsUseSystemExecutableOption.java create mode 100644 src/main/java/io/appium/java_client/chromium/options/SupportsVerboseOption.java diff --git a/src/main/java/io/appium/java_client/chromium/options/ChromiumOptions.java b/src/main/java/io/appium/java_client/chromium/options/ChromiumOptions.java index 95cf303bf..7d925456c 100644 --- a/src/main/java/io/appium/java_client/chromium/options/ChromiumOptions.java +++ b/src/main/java/io/appium/java_client/chromium/options/ChromiumOptions.java @@ -16,16 +16,8 @@ package io.appium.java_client.chromium.options; -import io.appium.java_client.mac.options.SupportsSystemPortOption; import io.appium.java_client.remote.AutomationName; -import io.appium.java_client.remote.options.BaseOptions; -import io.appium.java_client.remote.options.SupportsAcceptInsecureCertsOption; -import io.appium.java_client.remote.options.SupportsBrowserNameOption; -import io.appium.java_client.remote.options.SupportsBrowserVersionOption; -import io.appium.java_client.remote.options.SupportsPageLoadStrategyOption; -import io.appium.java_client.remote.options.SupportsProxyOption; -import io.appium.java_client.remote.options.SupportsSetWindowRectOption; -import io.appium.java_client.remote.options.SupportsUnhandledPromptBehaviorOption; +import io.appium.java_client.remote.options.*; import org.openqa.selenium.Capabilities; import java.util.Map; @@ -33,8 +25,18 @@ /** * appium-chromium-driver usage section */ -public class ChromiumOptions extends BaseOptions +public class ChromiumOptions extends BaseOptions implements + SupportsBrowserNameOption, + SupportsChromeDrivePortOption, + SupportsExecutableOption, + SupportsExecutableDirOption, + SupportsVerboseOption, + SupportsLogPathOption, + SupportsBuildCheckOption, + SupportsAutodownloadOption, + SupportsUseSystemExecutableOption { + public ChromiumOptions() { setCommonOptions(); } diff --git a/src/main/java/io/appium/java_client/chromium/options/SupportsAutodownloadOption.java b/src/main/java/io/appium/java_client/chromium/options/SupportsAutodownloadOption.java new file mode 100644 index 000000000..a1cefdffe --- /dev/null +++ b/src/main/java/io/appium/java_client/chromium/options/SupportsAutodownloadOption.java @@ -0,0 +1,51 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.chromium.options; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsAutodownloadOption> extends + Capabilities, CanSetCapability { + String AUTODOWNLOAD_ENABLED = "autodownloadEnabled"; + + /** + * Set to false for disabling automatic downloading of Chrome drivers. + * Unless disable build check preference has been user-set, the capability + * is present because the default value is true. + * + * @param autodownloadEnabled flag. + * @return self instance for chaining. + */ + default T setAutodownloadEnabled(boolean autodownloadEnabled) { + return amend(AUTODOWNLOAD_ENABLED, autodownloadEnabled); + } + + /** + * Get the auto download flag. + * + * @return auto download flag. + */ + default Optional isAutodownloadEnabled() { + return Optional.ofNullable(toSafeBoolean(getCapability(AUTODOWNLOAD_ENABLED))); + } +} diff --git a/src/main/java/io/appium/java_client/chromium/options/SupportsBuildCheckOption.java b/src/main/java/io/appium/java_client/chromium/options/SupportsBuildCheckOption.java new file mode 100644 index 000000000..d9e95f065 --- /dev/null +++ b/src/main/java/io/appium/java_client/chromium/options/SupportsBuildCheckOption.java @@ -0,0 +1,51 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.chromium.options; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsBuildCheckOption> extends + Capabilities, CanSetCapability { + String DISABLE_BUILD_CHECK = "disableBuildCheck"; + + /** + * Set to true to add the --disable-build-check flag when starting WebDriver. + * Unless disable build check preference has been user-set, the capability + * is not present because the default value is false. + * + * @param BuildCheckDisabled flag for --disable-build-check. + * @return self instance for chaining. + */ + default T setBuildCheckDisabled(boolean BuildCheckDisabled) { + return amend(DISABLE_BUILD_CHECK, BuildCheckDisabled); + } + + /** + * Get disable build check flag. + * + * @return disable build check flag. + */ + default Optional isBuildCheckDisabled() { + return Optional.ofNullable(toSafeBoolean(getCapability(DISABLE_BUILD_CHECK))); + } +} diff --git a/src/main/java/io/appium/java_client/chromium/options/SupportsChromeDrivePortOption.java b/src/main/java/io/appium/java_client/chromium/options/SupportsChromeDrivePortOption.java new file mode 100644 index 000000000..68cace279 --- /dev/null +++ b/src/main/java/io/appium/java_client/chromium/options/SupportsChromeDrivePortOption.java @@ -0,0 +1,51 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.chromium.options; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toInteger; + +public interface SupportsChromeDrivePortOption> extends + Capabilities, CanSetCapability { + String CHROME_DRIVER_PORT = "chromedriverPort"; + + /** + * The port to start WebDriver processes on. Unless the chrome drive port preference + * has been user-set, it will listen on port 9515, which is the default + * value for this capability. + * + * @param port port number in range 0..65535. + * @return self instance for chaining. + */ + default T setChromeDriverPort(int port) { + return amend(CHROME_DRIVER_PORT, port); + } + + /** + * Get the number of the port for the chrome driver to listen on. + * + * @return Chrome driver port value. + */ + default Optional getChromeDriverPort() { + return Optional.ofNullable(toInteger(getCapability(CHROME_DRIVER_PORT))); + } +} diff --git a/src/main/java/io/appium/java_client/chromium/options/SupportsExecutableDirOption.java b/src/main/java/io/appium/java_client/chromium/options/SupportsExecutableDirOption.java new file mode 100644 index 000000000..c525ab7ad --- /dev/null +++ b/src/main/java/io/appium/java_client/chromium/options/SupportsExecutableDirOption.java @@ -0,0 +1,49 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.chromium.options; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +public interface SupportsExecutableDirOption> extends + Capabilities, CanSetCapability { + String EXECUTABLE_DIR = "executableDir"; + + /** + * A directory within which is found any number of WebDriver binaries. + * If set, the driver will search this directory for WebDrivers of the + * appropriate version to use for your browser. + * + * @param directory of WebDriver binaries. + * @return self instance for chaining. + */ + default T setExecutableDir(String directory) { + return amend(EXECUTABLE_DIR, directory); + } + + /** + * Get a directory within which is found any number of WebDriver binaries. + * + * @return executable directory of a Driver binary. + */ + default Optional getExecutableDir() { + return Optional.ofNullable((String) getCapability(EXECUTABLE_DIR)); + } +} diff --git a/src/main/java/io/appium/java_client/chromium/options/SupportsExecutableOption.java b/src/main/java/io/appium/java_client/chromium/options/SupportsExecutableOption.java new file mode 100644 index 000000000..1683e67c5 --- /dev/null +++ b/src/main/java/io/appium/java_client/chromium/options/SupportsExecutableOption.java @@ -0,0 +1,50 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.chromium.options; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toInteger; + +public interface SupportsExecutableOption> extends + Capabilities, CanSetCapability { + String EXECUTABLE = "executable"; + + /** + * The absolute path to a WebDriver binary executable. + * If set, the driver will use that path instead of its own WebDriver. + * + * @param path absolute of a WebDriver. + * @return self instance for chaining. + */ + default T setExecutable(String path) { + return amend(EXECUTABLE, path); + } + + /** + * Get the absolute path to a WebDriver binary executable. + * + * @return executable absolute path. + */ + default Optional getExecutable() { + return Optional.ofNullable((String) getCapability(EXECUTABLE)); + } +} diff --git a/src/main/java/io/appium/java_client/chromium/options/SupportsLogPathOption.java b/src/main/java/io/appium/java_client/chromium/options/SupportsLogPathOption.java new file mode 100644 index 000000000..cf1b8713d --- /dev/null +++ b/src/main/java/io/appium/java_client/chromium/options/SupportsLogPathOption.java @@ -0,0 +1,48 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.chromium.options; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +public interface SupportsLogPathOption> extends + Capabilities, CanSetCapability { + String LOG_PATH = "logPath"; + + /** + * If set, the path to use with the --log-path parameter directing + * WebDriver to write its log to that path. + * + * @param logPath where to write the logs. + * @return self instance for chaining. + */ + default T setLogPath(String logPath) { + return amend(LOG_PATH, logPath); + } + + /** + * Get the log path where the WebDrive writes the logs. + * + * @return the log path. + */ + default Optional getLogPath() { + return Optional.ofNullable((String) getCapability(LOG_PATH)); + } +} diff --git a/src/main/java/io/appium/java_client/chromium/options/SupportsUseSystemExecutableOption.java b/src/main/java/io/appium/java_client/chromium/options/SupportsUseSystemExecutableOption.java new file mode 100644 index 000000000..6d51b332b --- /dev/null +++ b/src/main/java/io/appium/java_client/chromium/options/SupportsUseSystemExecutableOption.java @@ -0,0 +1,53 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.chromium.options; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsUseSystemExecutableOption> extends + Capabilities, CanSetCapability { + String USE_SYSTEM_EXECUTABLE = "useSystemExecutable"; + + /** + * Set to true to use the version of WebDriver bundled with this driver, + * rather than attempting to download a new one based on the version of the + * browser under test. + * Unless disable build check preference has been user-set, the capability + * is not present because the default value is false. + * + * @param useSystemExecutable flag. + * @return self instance for chaining. + */ + default T setUseSystemExecutable(boolean useSystemExecutable) { + return amend(USE_SYSTEM_EXECUTABLE, useSystemExecutable); + } + + /** + * Get the use system executable flag. + * + * @return use system executable flag. + */ + default Optional isUseSystemExecutable() { + return Optional.ofNullable(toSafeBoolean(getCapability(USE_SYSTEM_EXECUTABLE))); + } +} diff --git a/src/main/java/io/appium/java_client/chromium/options/SupportsVerboseOption.java b/src/main/java/io/appium/java_client/chromium/options/SupportsVerboseOption.java new file mode 100644 index 000000000..c62e78f14 --- /dev/null +++ b/src/main/java/io/appium/java_client/chromium/options/SupportsVerboseOption.java @@ -0,0 +1,51 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appium.java_client.chromium.options; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toSafeBoolean; + +public interface SupportsVerboseOption> extends + Capabilities, CanSetCapability { + String VERBOSE = "verbose"; + + /** + * Set to true to add the --verbose flag when starting WebDriver. + * Unless the verbose preference has been user-set, the capability + * is not present because the default value is false. + * + * @param verbose flag for --verbose + * @return self instance for chaining. + */ + default T setVerbose(boolean verbose) { + return amend(VERBOSE, verbose); + } + + /** + * Get the verbose flag + * + * @return verbose flag. + */ + default Optional isVerbose() { + return Optional.ofNullable(toSafeBoolean(getCapability(VERBOSE))); + } +} From 380b4d14ef4a0c6dd358013206738c849432f570 Mon Sep 17 00:00:00 2001 From: Alessandro Miccoli Date: Wed, 6 Sep 2023 09:32:01 +0100 Subject: [PATCH 4/7] ISSUE_1995 fix: change javadoc br tag --- .../java/io/appium/java_client/chromium/ChromiumDriver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/appium/java_client/chromium/ChromiumDriver.java b/src/main/java/io/appium/java_client/chromium/ChromiumDriver.java index e340557c4..e6366f708 100644 --- a/src/main/java/io/appium/java_client/chromium/ChromiumDriver.java +++ b/src/main/java/io/appium/java_client/chromium/ChromiumDriver.java @@ -32,7 +32,7 @@ *

ChromiumDriver is an officially supported Appium driver created to automate Mobile browsers * and web views based on the Chromium engine. The driver uses W3CWebDriver protocol and is built * on top of chromium driver server.

- *
+ *
*

Read appium-chromium-driver * for more details on how to configure and use it.

*/ From cb9bf0e1299b8481745a2112f73bf79e9dc66d3f Mon Sep 17 00:00:00 2001 From: Alessandro Miccoli Date: Wed, 6 Sep 2023 09:43:01 +0100 Subject: [PATCH 5/7] ISSUE_1995 style: amend imports, curly brace position and javadoc. --- .../java_client/chromium/options/ChromiumOptions.java | 11 ++++++----- .../chromium/options/SupportsExecutableOption.java | 2 -- .../chromium/options/SupportsVerboseOption.java | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/appium/java_client/chromium/options/ChromiumOptions.java b/src/main/java/io/appium/java_client/chromium/options/ChromiumOptions.java index 7d925456c..dfc5d7d02 100644 --- a/src/main/java/io/appium/java_client/chromium/options/ChromiumOptions.java +++ b/src/main/java/io/appium/java_client/chromium/options/ChromiumOptions.java @@ -17,13 +17,16 @@ package io.appium.java_client.chromium.options; import io.appium.java_client.remote.AutomationName; -import io.appium.java_client.remote.options.*; +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.SupportsBrowserNameOption; import org.openqa.selenium.Capabilities; import java.util.Map; /** - * appium-chromium-driver usage section + *

Options class that sets options for Chromium when testing websites.

+ *
+ * @see appium-chromium-driver usage section */ public class ChromiumOptions extends BaseOptions implements SupportsBrowserNameOption, @@ -34,9 +37,7 @@ public class ChromiumOptions extends BaseOptions implements SupportsLogPathOption, SupportsBuildCheckOption, SupportsAutodownloadOption, - SupportsUseSystemExecutableOption -{ - + SupportsUseSystemExecutableOption { public ChromiumOptions() { setCommonOptions(); } diff --git a/src/main/java/io/appium/java_client/chromium/options/SupportsExecutableOption.java b/src/main/java/io/appium/java_client/chromium/options/SupportsExecutableOption.java index 1683e67c5..84e730e62 100644 --- a/src/main/java/io/appium/java_client/chromium/options/SupportsExecutableOption.java +++ b/src/main/java/io/appium/java_client/chromium/options/SupportsExecutableOption.java @@ -22,8 +22,6 @@ import java.util.Optional; -import static io.appium.java_client.internal.CapabilityHelpers.toInteger; - public interface SupportsExecutableOption> extends Capabilities, CanSetCapability { String EXECUTABLE = "executable"; diff --git a/src/main/java/io/appium/java_client/chromium/options/SupportsVerboseOption.java b/src/main/java/io/appium/java_client/chromium/options/SupportsVerboseOption.java index c62e78f14..14aa571d2 100644 --- a/src/main/java/io/appium/java_client/chromium/options/SupportsVerboseOption.java +++ b/src/main/java/io/appium/java_client/chromium/options/SupportsVerboseOption.java @@ -33,7 +33,7 @@ public interface SupportsVerboseOption> extends * Unless the verbose preference has been user-set, the capability * is not present because the default value is false. * - * @param verbose flag for --verbose + * @param verbose flag for --verbose. * @return self instance for chaining. */ default T setVerbose(boolean verbose) { @@ -41,7 +41,7 @@ default T setVerbose(boolean verbose) { } /** - * Get the verbose flag + * Get the verbose flag. * * @return verbose flag. */ From 60531fcf89322b24e0daa7be0c1217ebf3ef7289 Mon Sep 17 00:00:00 2001 From: Alessandro Miccoli Date: Thu, 7 Sep 2023 17:22:39 +0100 Subject: [PATCH 6/7] ISSUE_1995 test: add test for ChromiumOptions --- .../drivers/options/OptionsBuildingTest.java | 43 +++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java b/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java index 908ff709e..f2a3e1dcd 100644 --- a/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java +++ b/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java @@ -23,6 +23,7 @@ import io.appium.java_client.android.options.localization.AppLocale; import io.appium.java_client.android.options.server.EspressoBuildConfig; import io.appium.java_client.android.options.signing.KeystoreConfig; +import io.appium.java_client.chromium.options.ChromiumOptions; import io.appium.java_client.gecko.options.GeckoOptions; import io.appium.java_client.gecko.options.Verbosity; import io.appium.java_client.ios.options.XCUITestOptions; @@ -42,10 +43,7 @@ import java.net.URL; import java.time.Duration; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; @SuppressWarnings("ConstantConditions") public class OptionsBuildingTest { @@ -108,11 +106,11 @@ public void canBuildEspressoOptions() { "com.dep1:1.2.3", "com.dep2:1.2.3" )) - ); + ); assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null)); assertEquals("CN", options.getAppLocale().orElse(null).getCountry().orElse(null)); assertEquals(2, options.getEspressoBuildConfig().orElse(null) - .left().getAdditionalAppDependencies().orElse(null).size()); + .left().getAdditionalAppDependencies().orElse(null).size()); assertTrue(options.doesForceEspressoRebuild().orElse(false)); } @@ -154,7 +152,7 @@ public void canBuildGeckoOptions() { options.setNewCommandTimeout(Duration.ofSeconds(10)) .setVerbosity(Verbosity.TRACE) .setMozFirefoxOptions(ImmutableMap.of( - "profile", "yolo" + "profile", "yolo" )); assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null)); assertEquals(Verbosity.TRACE, options.getVerbosity().orElse(null)); @@ -172,7 +170,7 @@ public void canBuildSafariOptions() { .setWebkitWebrtc(new WebrtcData() .withDisableIceCandidateFiltering(true) .withDisableInsecureMediaCapture(true) - ); + ); assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null)); assertTrue(options.doesSafariUseSimulator().orElse(false)); assertTrue(options.getWebkitWebrtc().orElse(null) @@ -180,4 +178,33 @@ public void canBuildSafariOptions() { assertTrue(options.getWebkitWebrtc().orElse(null) .doesDisableInsecureMediaCapture().orElse(false)); } + + @Test + public void canBuildChromiumOptions() { + // Given + // When + ChromiumOptions options = new ChromiumOptions(); + + options.setNewCommandTimeout(Duration.ofSeconds(10)) + .setPlatformName(Platform.MAC.name()) + .withBrowserName("Chrome") + .setAutodownloadEnabled(true) + .setBuildCheckDisabled(true) + .setChromeDriverPort(5485) + .setExecutable("/absolute/executable/path") + .setLogPath("/wonderful/log/path") + .setVerbose(true); + + // Then + assertEquals(AutomationName.CHROMIUM, options.getAutomationName().orElse(null)); + assertEquals("Chrome", options.getBrowserName()); + assertTrue(options.isAutodownloadEnabled().orElse(null)); + assertTrue(options.isBuildCheckDisabled().orElse(null)); + assertEquals(5485, options.getChromeDriverPort().orElse(null)); + assertNull(options.getExecutableDir().orElse(null)); + assertEquals("/absolute/executable/path", options.getExecutable().orElse(null)); + assertEquals("/wonderful/log/path", options.getLogPath().orElse(null)); + assertNull(options.isUseSystemExecutable().orElse(null)); + assertTrue(options.isVerbose().orElse(null)); + } } From d460b27cc511690049006bd8dac27c9beea70a41 Mon Sep 17 00:00:00 2001 From: Alessandro Miccoli Date: Thu, 7 Sep 2023 21:12:18 +0100 Subject: [PATCH 7/7] ISSUE_1995 refactor/fix: amend canBuildChromiumOptions test. Fix build errors, such as indentation. --- .../drivers/options/OptionsBuildingTest.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java b/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java index f2a3e1dcd..04574448c 100644 --- a/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java +++ b/src/test/java/io/appium/java_client/drivers/options/OptionsBuildingTest.java @@ -43,7 +43,10 @@ import java.net.URL; import java.time.Duration; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; @SuppressWarnings("ConstantConditions") public class OptionsBuildingTest { @@ -106,7 +109,7 @@ public void canBuildEspressoOptions() { "com.dep1:1.2.3", "com.dep2:1.2.3" )) - ); + ); assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null)); assertEquals("CN", options.getAppLocale().orElse(null).getCountry().orElse(null)); assertEquals(2, options.getEspressoBuildConfig().orElse(null) @@ -170,7 +173,7 @@ public void canBuildSafariOptions() { .setWebkitWebrtc(new WebrtcData() .withDisableIceCandidateFiltering(true) .withDisableInsecureMediaCapture(true) - ); + ); assertEquals(Duration.ofSeconds(10), options.getNewCommandTimeout().orElse(null)); assertTrue(options.doesSafariUseSimulator().orElse(false)); assertTrue(options.getWebkitWebrtc().orElse(null) @@ -201,10 +204,10 @@ public void canBuildChromiumOptions() { assertTrue(options.isAutodownloadEnabled().orElse(null)); assertTrue(options.isBuildCheckDisabled().orElse(null)); assertEquals(5485, options.getChromeDriverPort().orElse(null)); - assertNull(options.getExecutableDir().orElse(null)); + assertFalse(options.getExecutableDir().isPresent()); assertEquals("/absolute/executable/path", options.getExecutable().orElse(null)); assertEquals("/wonderful/log/path", options.getLogPath().orElse(null)); - assertNull(options.isUseSystemExecutable().orElse(null)); + assertFalse(options.isUseSystemExecutable().isPresent()); assertTrue(options.isVerbose().orElse(null)); } }