From 7013e5620cc80421837397da39e40891ca83caa7 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 29 Oct 2021 18:21:49 +0200 Subject: [PATCH] feat: Add Mac2 driver options (#1565) --- .../java_client/mac/options/Mac2Options.java | 60 ++++++++++++++++ .../java_client/mac/options/RunScript.java | 69 +++++++++++++++++++ .../mac/options/SupportsArgumentsOption.java | 50 ++++++++++++++ .../options/SupportsBootstrapRootOption.java | 50 ++++++++++++++ .../mac/options/SupportsBundleIdOption.java | 53 ++++++++++++++ .../options/SupportsEnvironmentOption.java | 52 ++++++++++++++ .../mac/options/SupportsPostrunOption.java | 54 +++++++++++++++ .../mac/options/SupportsPrerunOption.java | 54 +++++++++++++++ .../SupportsServerStartupTimeoutOption.java | 54 +++++++++++++++ .../options/SupportsShowServerLogsOption.java | 59 ++++++++++++++++ .../options/SupportsSkipAppKillOption.java | 61 ++++++++++++++++ .../mac/options/SupportsSystemHostOption.java | 51 ++++++++++++++ .../mac/options/SupportsSystemPortOption.java | 50 ++++++++++++++ .../SupportsWebDriverAgentMacUrlOption.java | 63 +++++++++++++++++ 14 files changed, 780 insertions(+) create mode 100644 src/main/java/io/appium/java_client/mac/options/Mac2Options.java create mode 100644 src/main/java/io/appium/java_client/mac/options/RunScript.java create mode 100644 src/main/java/io/appium/java_client/mac/options/SupportsArgumentsOption.java create mode 100644 src/main/java/io/appium/java_client/mac/options/SupportsBootstrapRootOption.java create mode 100644 src/main/java/io/appium/java_client/mac/options/SupportsBundleIdOption.java create mode 100644 src/main/java/io/appium/java_client/mac/options/SupportsEnvironmentOption.java create mode 100644 src/main/java/io/appium/java_client/mac/options/SupportsPostrunOption.java create mode 100644 src/main/java/io/appium/java_client/mac/options/SupportsPrerunOption.java create mode 100644 src/main/java/io/appium/java_client/mac/options/SupportsServerStartupTimeoutOption.java create mode 100644 src/main/java/io/appium/java_client/mac/options/SupportsShowServerLogsOption.java create mode 100644 src/main/java/io/appium/java_client/mac/options/SupportsSkipAppKillOption.java create mode 100644 src/main/java/io/appium/java_client/mac/options/SupportsSystemHostOption.java create mode 100644 src/main/java/io/appium/java_client/mac/options/SupportsSystemPortOption.java create mode 100644 src/main/java/io/appium/java_client/mac/options/SupportsWebDriverAgentMacUrlOption.java diff --git a/src/main/java/io/appium/java_client/mac/options/Mac2Options.java b/src/main/java/io/appium/java_client/mac/options/Mac2Options.java new file mode 100644 index 000000000..47214f677 --- /dev/null +++ b/src/main/java/io/appium/java_client/mac/options/Mac2Options.java @@ -0,0 +1,60 @@ +/* + * 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.mac.options; + +import io.appium.java_client.remote.AutomationName; +import io.appium.java_client.remote.MobilePlatform; +import io.appium.java_client.remote.options.BaseOptions; +import org.openqa.selenium.Capabilities; + +import java.util.Map; + +/** + * https://github.com/appium/appium-mac2-driver#capabilities + */ +public class Mac2Options extends BaseOptions implements + SupportsSystemPortOption, + SupportsSystemHostOption, + SupportsWebDriverAgentMacUrlOption, + SupportsBootstrapRootOption, + SupportsBundleIdOption, + SupportsArgumentsOption, + SupportsEnvironmentOption, + SupportsServerStartupTimeoutOption, + SupportsSkipAppKillOption, + SupportsShowServerLogsOption, + SupportsPrerunOption, + SupportsPostrunOption { + public Mac2Options() { + setCommonOptions(); + } + + public Mac2Options(Capabilities source) { + super(source); + setCommonOptions(); + } + + public Mac2Options(Map source) { + super(source); + setCommonOptions(); + } + + private void setCommonOptions() { + setPlatformName(MobilePlatform.MAC); + setAutomationName(AutomationName.MAC2); + } +} diff --git a/src/main/java/io/appium/java_client/mac/options/RunScript.java b/src/main/java/io/appium/java_client/mac/options/RunScript.java new file mode 100644 index 000000000..4960d7e86 --- /dev/null +++ b/src/main/java/io/appium/java_client/mac/options/RunScript.java @@ -0,0 +1,69 @@ +/* + * 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.mac.options; + +import io.appium.java_client.remote.options.BaseMapOptionData; + +import java.util.Map; +import java.util.Optional; + +public class RunScript extends BaseMapOptionData { + public RunScript() { + } + + public RunScript(Map options) { + super(options); + } + + /** + * Allows to provide a multiline AppleScript. + * + * @param script A valid AppleScript. + * @return self instance for chaining. + */ + public RunScript withScript(String script) { + return assignOptionValue("script", script); + } + + /** + * Get a multiline AppleScript. + * + * @return AppleScript snippet. + */ + public Optional getScript() { + return getOptionValue("script"); + } + + /** + * Allows to provide a single-line AppleScript. + * + * @param command A valid AppleScript. + * @return self instance for chaining. + */ + public RunScript withCommand(String command) { + return assignOptionValue("command", command); + } + + /** + * Get a single-line AppleScript. + * + * @return AppleScript snippet. + */ + public Optional getCommand() { + return getOptionValue("command"); + } +} diff --git a/src/main/java/io/appium/java_client/mac/options/SupportsArgumentsOption.java b/src/main/java/io/appium/java_client/mac/options/SupportsArgumentsOption.java new file mode 100644 index 000000000..8d8c427f5 --- /dev/null +++ b/src/main/java/io/appium/java_client/mac/options/SupportsArgumentsOption.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.mac.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.List; +import java.util.Optional; + +public interface SupportsArgumentsOption> extends + Capabilities, CanSetCapability { + String ARGUMENTS_OPTION = "arguments"; + + /** + * Array of application command line arguments. This capability is + * only going to be applied if the application is not running on session startup. + * + * @param arguments E.g. ["--help"]. + * @return self instance for chaining. + */ + default T setArguments(List arguments) { + return amend(ARGUMENTS_OPTION, arguments); + } + + /** + * Get the array of application command line arguments. + * + * @return Application arguments. + */ + default Optional> getArguments() { + //noinspection unchecked + return Optional.ofNullable((List) getCapability(ARGUMENTS_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/mac/options/SupportsBootstrapRootOption.java b/src/main/java/io/appium/java_client/mac/options/SupportsBootstrapRootOption.java new file mode 100644 index 000000000..cb3245148 --- /dev/null +++ b/src/main/java/io/appium/java_client/mac/options/SupportsBootstrapRootOption.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.mac.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 SupportsBootstrapRootOption> extends + Capabilities, CanSetCapability { + String BOOTSTRAP_ROOT_OPTION = "bootstrapRoot"; + + /** + * The full path to WebDriverAgentMac root folder where Xcode project + * of the server sources lives. By default, this project is located in + * the same folder where the corresponding driver Node.js module lives. + * + * @param path The full path to WebDriverAgentMac root folder. + * @return self instance for chaining. + */ + default T setBootstrapRoot(String path) { + return amend(BOOTSTRAP_ROOT_OPTION, path); + } + + /** + * Get the full path to WebDriverAgentMac root folder where Xcode project + * of the server sources lives. + * + * @return The full path to WebDriverAgentMac root folder. + */ + default Optional getBootstrapRoot() { + return Optional.ofNullable((String) getCapability(BOOTSTRAP_ROOT_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/mac/options/SupportsBundleIdOption.java b/src/main/java/io/appium/java_client/mac/options/SupportsBundleIdOption.java new file mode 100644 index 000000000..d19420c8f --- /dev/null +++ b/src/main/java/io/appium/java_client/mac/options/SupportsBundleIdOption.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.mac.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 SupportsBundleIdOption> extends + Capabilities, CanSetCapability { + String BUNDLE_ID_OPTION = "bundleId"; + + /** + * The bundle identifier of the application to automate, for example + * com.apple.TextEdit. This is an optional capability. If it is not provided + * then the session will be started without an application under test + * (actually, it will be Finder). If the application with the given + * identifier is not installed then an error will be thrown on session + * startup. If the application is already running then it will be moved to + * the foreground. + * + * @param identifier A valid application bundle identifier. + * @return self instance for chaining. + */ + default T setBundleId(String identifier) { + return amend(BUNDLE_ID_OPTION, identifier); + } + + /** + * Get the bundle identifier of the application to automate. + * + * @return Application bundle identifier. + */ + default Optional getBundleId() { + return Optional.ofNullable((String) getCapability(BUNDLE_ID_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/mac/options/SupportsEnvironmentOption.java b/src/main/java/io/appium/java_client/mac/options/SupportsEnvironmentOption.java new file mode 100644 index 000000000..17a2d05f9 --- /dev/null +++ b/src/main/java/io/appium/java_client/mac/options/SupportsEnvironmentOption.java @@ -0,0 +1,52 @@ +/* + * 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.mac.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.List; +import java.util.Optional; + +public interface SupportsEnvironmentOption> extends + Capabilities, CanSetCapability { + String ENVIRONMENT_OPTION = "environment"; + + /** + * A dictionary of environment variables (name->value) that are going to be passed + * to the application under test on top of environment variables inherited from + * the parent process. This capability is only going to be applied if the application + * is not running on session startup. + * + * @param arguments E.g. ["--help"]. + * @return self instance for chaining. + */ + default T setEnvironment(List arguments) { + return amend(ENVIRONMENT_OPTION, arguments); + } + + /** + * Get the application environment variables mapping. + * + * @return Application environment mapping. + */ + default Optional> getEnvironment() { + //noinspection unchecked + return Optional.ofNullable((List) getCapability(ENVIRONMENT_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/mac/options/SupportsPostrunOption.java b/src/main/java/io/appium/java_client/mac/options/SupportsPostrunOption.java new file mode 100644 index 000000000..69430019b --- /dev/null +++ b/src/main/java/io/appium/java_client/mac/options/SupportsPostrunOption.java @@ -0,0 +1,54 @@ +/* + * 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.mac.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.Map; +import java.util.Optional; + +public interface SupportsPostrunOption> extends + Capabilities, CanSetCapability { + String POSTRUN_OPTION = "postrun"; + + /** + * An object containing either script or command key. The value of + * each key must be a valid AppleScript script or command to be + * executed after Mac2Driver session is stopped. See + * https://github.com/appium/appium-mac2-driver#applescript-commands-execution + * for more details. + * + * @param script A valid AppleScript snippet. + * @return self instance for chaining. + */ + default T setPostrun(RunScript script) { + return amend(POSTRUN_OPTION, script.toMap()); + } + + /** + * Get the postrun script. + * + * @return Postrun script. + */ + default Optional getPostrun() { + //noinspection unchecked + return Optional.ofNullable(getCapability(POSTRUN_OPTION)) + .map((v) -> new RunScript((Map) v)); + } +} diff --git a/src/main/java/io/appium/java_client/mac/options/SupportsPrerunOption.java b/src/main/java/io/appium/java_client/mac/options/SupportsPrerunOption.java new file mode 100644 index 000000000..61b8d0897 --- /dev/null +++ b/src/main/java/io/appium/java_client/mac/options/SupportsPrerunOption.java @@ -0,0 +1,54 @@ +/* + * 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.mac.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.Map; +import java.util.Optional; + +public interface SupportsPrerunOption> extends + Capabilities, CanSetCapability { + String PRERUN_OPTION = "prerun"; + + /** + * An object containing either script or command key. The value of + * each key must be a valid AppleScript script or command to be + * executed after before Mac2Driver session is started. See + * https://github.com/appium/appium-mac2-driver#applescript-commands-execution + * for more details. + * + * @param script A valid AppleScript snippet. + * @return self instance for chaining. + */ + default T setPrerun(RunScript script) { + return amend(PRERUN_OPTION, script.toMap()); + } + + /** + * Get the prerun script. + * + * @return Prerun script. + */ + default Optional getPrerun() { + //noinspection unchecked + return Optional.ofNullable(getCapability(PRERUN_OPTION)) + .map((v) -> new RunScript((Map) v)); + } +} diff --git a/src/main/java/io/appium/java_client/mac/options/SupportsServerStartupTimeoutOption.java b/src/main/java/io/appium/java_client/mac/options/SupportsServerStartupTimeoutOption.java new file mode 100644 index 000000000..97d052928 --- /dev/null +++ b/src/main/java/io/appium/java_client/mac/options/SupportsServerStartupTimeoutOption.java @@ -0,0 +1,54 @@ +/* + * 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.mac.options; + +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.time.Duration; +import java.util.Optional; + +import static io.appium.java_client.internal.CapabilityHelpers.toDuration; + +public interface SupportsServerStartupTimeoutOption> extends + Capabilities, CanSetCapability { + String SERVER_STARTUP_TIMEOUT_OPTION = "serverStartupTimeout"; + + /** + * The timeout to wait util the WebDriverAgentMac + * project is built and started. 120000ms by default + * + * @param timeout The timeout value. + * @return self instance for chaining. + */ + default T setServerStartupTimeout(Duration timeout) { + return amend(SERVER_STARTUP_TIMEOUT_OPTION, timeout.toMillis()); + } + + /** + * Get the timeout to wait util the WebDriverAgentMac + * project is built and started. + * + * @return The timeout value. + */ + default Optional getServerStartupTimeout() { + return Optional.ofNullable( + toDuration(getCapability(SERVER_STARTUP_TIMEOUT_OPTION)) + ); + } +} diff --git a/src/main/java/io/appium/java_client/mac/options/SupportsShowServerLogsOption.java b/src/main/java/io/appium/java_client/mac/options/SupportsShowServerLogsOption.java new file mode 100644 index 000000000..f91a32d97 --- /dev/null +++ b/src/main/java/io/appium/java_client/mac/options/SupportsShowServerLogsOption.java @@ -0,0 +1,59 @@ +/* + * 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.mac.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 SupportsShowServerLogsOption> extends + Capabilities, CanSetCapability { + String SHOW_SERVER_LOGS_OPTION = "showServerLogs"; + + /** + * Enforce showing of WDA server logs in the Appium log.. + * + * @return self instance for chaining. + */ + default T showServerLogs() { + return amend(SHOW_SERVER_LOGS_OPTION, true); + } + + /** + * Set it to true in order to include xcodebuild output to the Appium + * server log. false by default. + * + * @param value Whether to show WDA server logs in the Appium log. + * @return self instance for chaining. + */ + default T setShowServerLogs(boolean value) { + return amend(SHOW_SERVER_LOGS_OPTION, value); + } + + /** + * Get whether to show WDA server logs in the Appium log. + * + * @return True or false. + */ + default Optional doesShowServerLogs() { + return Optional.ofNullable(toSafeBoolean(getCapability(SHOW_SERVER_LOGS_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/mac/options/SupportsSkipAppKillOption.java b/src/main/java/io/appium/java_client/mac/options/SupportsSkipAppKillOption.java new file mode 100644 index 000000000..5c166b80a --- /dev/null +++ b/src/main/java/io/appium/java_client/mac/options/SupportsSkipAppKillOption.java @@ -0,0 +1,61 @@ +/* + * 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.mac.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 SupportsSkipAppKillOption> extends + Capabilities, CanSetCapability { + String SKIP_APP_KILL_OPTION = "skipAppKill"; + + /** + * Enforces skipping the termination of the application under test + * when the testing session quits. + * + * @return self instance for chaining. + */ + default T skipAppKill() { + return amend(SKIP_APP_KILL_OPTION, true); + } + + /** + * Set whether to skip the termination of the application under test + * when the testing session quits. false by default. This capability + * is only going to be applied if bundleId is set. + * + * @param value True to skip the termination of the application under test. + * @return self instance for chaining. + */ + default T setSkipAppKill(boolean value) { + return amend(SKIP_APP_KILL_OPTION, value); + } + + /** + * Get whether to skip the termination of the application under test. + * + * @return True or false. + */ + default Optional doesSkipAppKill() { + return Optional.ofNullable(toSafeBoolean(getCapability(SKIP_APP_KILL_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/mac/options/SupportsSystemHostOption.java b/src/main/java/io/appium/java_client/mac/options/SupportsSystemHostOption.java new file mode 100644 index 000000000..8f6a92cc1 --- /dev/null +++ b/src/main/java/io/appium/java_client/mac/options/SupportsSystemHostOption.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.mac.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 SupportsSystemHostOption> extends + Capabilities, CanSetCapability { + String SYSTEM_HOST_OPTION = "systemHost"; + + /** + * The name of the host for the internal server to listen on. + * If not provided then Mac2Driver will use the default host + * address 127.0.0.1. You could set it to 0.0.0.0 to make the + * server listening on all available network interfaces. + * It is also possible to set the particular interface name, for example en1. + * + * @param host Host name. + * @return self instance for chaining. + */ + default T setSystemHost(String host) { + return amend(SYSTEM_HOST_OPTION, host); + } + + /** + * Get the name of the host for the internal server to listen on. + * + * @return System host value. + */ + default Optional getSystemHost() { + return Optional.ofNullable((String) getCapability(SYSTEM_HOST_OPTION)); + } +} diff --git a/src/main/java/io/appium/java_client/mac/options/SupportsSystemPortOption.java b/src/main/java/io/appium/java_client/mac/options/SupportsSystemPortOption.java new file mode 100644 index 000000000..bf648a7bb --- /dev/null +++ b/src/main/java/io/appium/java_client/mac/options/SupportsSystemPortOption.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.mac.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 SupportsSystemPortOption> extends + Capabilities, CanSetCapability { + String SYSTEM_PORT_OPTION = "systemPort"; + + /** + * The number of the port for the internal server to listen on. + * If not provided then Mac2Driver will use the default port 10100. + * + * @param port port number in range 0..65535 + * @return self instance for chaining. + */ + default T setSystemPort(int port) { + return amend(SYSTEM_PORT_OPTION, port); + } + + /** + * Get the number of the port for the internal server to listen on. + * + * @return System port value. + */ + default Optional getSystemPort() { + return Optional.ofNullable(toInteger(getCapability(SYSTEM_PORT_OPTION))); + } +} diff --git a/src/main/java/io/appium/java_client/mac/options/SupportsWebDriverAgentMacUrlOption.java b/src/main/java/io/appium/java_client/mac/options/SupportsWebDriverAgentMacUrlOption.java new file mode 100644 index 000000000..9f968c9c0 --- /dev/null +++ b/src/main/java/io/appium/java_client/mac/options/SupportsWebDriverAgentMacUrlOption.java @@ -0,0 +1,63 @@ +/* + * 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.mac.options; + +import io.appium.java_client.internal.CapabilityHelpers; +import io.appium.java_client.remote.options.BaseOptions; +import io.appium.java_client.remote.options.CanSetCapability; +import org.openqa.selenium.Capabilities; + +import java.net.URL; +import java.util.Optional; + +public interface SupportsWebDriverAgentMacUrlOption> extends + Capabilities, CanSetCapability { + String WEB_DRIVER_AGENT_MAC_URL_OPTION = "webDriverAgentMacUrl"; + + /** + * Set the URL Appium will connect to an existing WebDriverAgentMac + * instance at this URL instead of starting a new one. + * + * @param url E.g. "http://192.168.10.1:10101" + * @return self instance for chaining. + */ + default T setWebDriverAgentMacUrl(URL url) { + return amend(WEB_DRIVER_AGENT_MAC_URL_OPTION, url.toString()); + } + + /** + * Set the URL Appium will connect to an existing WebDriverAgentMac + * instance at this URL instead of starting a new one. + * + * @param url E.g. "http://192.168.10.1:10101" + * @return self instance for chaining. + */ + default T setWebDriverAgentMacUrl(String url) { + return amend(WEB_DRIVER_AGENT_MAC_URL_OPTION, url); + } + + /** + * Get the URL Appium will connect to an existing WebDriverAgentMac + * instance. + * + * @return Server URL. + */ + default Optional getWebDriverAgentMacUrl() { + return Optional.ofNullable(getCapability(WEB_DRIVER_AGENT_MAC_URL_OPTION)) + .map(CapabilityHelpers::toUrl); + } +}