Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/main/java/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@
package io.appium.java_client;

import static io.appium.java_client.remote.MobileCapabilityType.PLATFORM_NAME;
import static org.apache.commons.lang3.StringUtils.isBlank;

import io.appium.java_client.remote.AppiumCommandExecutor;
import io.appium.java_client.remote.AppiumNewSessionCommandPayload;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.options.BaseOptions;
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.ImmutableCapabilities;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.SessionNotCreatedException;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DriverCommand;
import org.openqa.selenium.remote.ErrorHandler;
import org.openqa.selenium.remote.ExecuteMethod;
Expand Down Expand Up @@ -199,7 +202,13 @@ protected void startSession(Capabilities capabilities) {
}

@SuppressWarnings("unchecked") Map<String, Object> rawCapabilities = (Map<String, Object>) responseValue;
MutableCapabilities returnedCapabilities = new MutableCapabilities(rawCapabilities);
// A workaround for Selenium API enforcing some legacy capability values
rawCapabilities.remove(CapabilityType.PLATFORM);
if (rawCapabilities.containsKey(CapabilityType.BROWSER_NAME)
&& isBlank((String) rawCapabilities.get(CapabilityType.BROWSER_NAME))) {
rawCapabilities.remove(CapabilityType.BROWSER_NAME);
}
MutableCapabilities returnedCapabilities = new BaseOptions<>(rawCapabilities);
try {
Field capsField = RemoteWebDriver.class.getDeclaredField("capabilities");
capsField.setAccessible(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
import io.appium.java_client.android.options.mjpeg.SupportsMjpegScreenshotUrlOption;
import io.appium.java_client.android.options.mjpeg.SupportsMjpegServerPortOption;
import io.appium.java_client.android.options.other.SupportsDisableSuppressAccessibilityServiceOption;
import io.appium.java_client.android.options.other.SupportsSkipLogCaptureOption;
import io.appium.java_client.remote.options.SupportsSkipLogCaptureOption;
import io.appium.java_client.android.options.other.SupportsUserProfileOption;
import io.appium.java_client.android.options.server.SupportsDisableWindowAnimationOption;
import io.appium.java_client.android.options.server.SupportsSkipDeviceInitializationOption;
Expand All @@ -104,6 +104,8 @@
import io.appium.java_client.remote.options.SupportsUdidOption;
import org.openqa.selenium.Capabilities;

import java.util.Map;

/**
* https://github.com/appium/appium-uiautomator2-driver#capabilities
*/
Expand Down Expand Up @@ -211,6 +213,11 @@ public UiAutomator2Options(Capabilities source) {
setCommonOptions();
}

public UiAutomator2Options(Map<String, ?> source) {
super(source);
setCommonOptions();
}

private void setCommonOptions() {
setPlatformName(MobilePlatform.ANDROID);
setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
import io.appium.java_client.ios.options.app.SupportsLocalizableStringsDirOption;
import io.appium.java_client.ios.options.general.SupportsIncludeDeviceCapsToSessionInfoOption;
import io.appium.java_client.ios.options.general.SupportsResetLocationServiceOption;
import io.appium.java_client.ios.options.other.SupportsCommandTimeoutsOption;
import io.appium.java_client.ios.options.other.SupportsLaunchWithIdbOption;
import io.appium.java_client.ios.options.other.SupportsResetOnSessionStartOnlyOption;
import io.appium.java_client.ios.options.other.SupportsShowIosLogOption;
import io.appium.java_client.ios.options.other.SupportsUseJsonSourceOption;
import io.appium.java_client.ios.options.simulator.SupportsCalendarAccessAuthorizedOption;
import io.appium.java_client.ios.options.simulator.SupportsCalendarFormatOption;
import io.appium.java_client.ios.options.simulator.SupportsConnectHardwareKeyboardOption;
Expand Down Expand Up @@ -106,9 +111,12 @@
import io.appium.java_client.remote.options.SupportsLocaleOption;
import io.appium.java_client.remote.options.SupportsOrientationOption;
import io.appium.java_client.remote.options.SupportsOtherAppsOption;
import io.appium.java_client.remote.options.SupportsSkipLogCaptureOption;
import io.appium.java_client.remote.options.SupportsUdidOption;
import org.openqa.selenium.Capabilities;

import java.util.Map;

/**
* https://github.com/appium/appium-xcuitest-driver#capabilities
*/
Expand Down Expand Up @@ -205,9 +213,15 @@ public class XCUITestOptions extends BaseOptions<XCUITestOptions> implements
SupportsWebkitResponseTimeoutOption<XCUITestOptions>,
SupportsEnableAsyncExecuteFromHttpsOption<XCUITestOptions>,
SupportsFullContextListOption<XCUITestOptions>,
// TODO: Other options: https://github.com/appium/appium-xcuitest-driver#other
SupportsClearSystemFilesOption<XCUITestOptions>,
SupportsEnablePerformanceLoggingOption<XCUITestOptions> {
SupportsEnablePerformanceLoggingOption<XCUITestOptions>,
// Other options: https://github.com/appium/appium-xcuitest-driver#other
SupportsResetOnSessionStartOnlyOption<XCUITestOptions>,
SupportsCommandTimeoutsOption<XCUITestOptions>,
SupportsUseJsonSourceOption<XCUITestOptions>,
SupportsSkipLogCaptureOption<XCUITestOptions>,
SupportsLaunchWithIdbOption<XCUITestOptions>,
SupportsShowIosLogOption<XCUITestOptions>,
SupportsClearSystemFilesOption<XCUITestOptions> {

public XCUITestOptions() {
setCommonOptions();
Expand All @@ -218,6 +232,11 @@ public XCUITestOptions(Capabilities source) {
setCommonOptions();
}

public XCUITestOptions(Map<String, ?> source) {
super(source);
setCommonOptions();
}

private void setCommonOptions() {
setPlatformName(MobilePlatform.IOS);
setAutomationName(AutomationName.IOS_XCUI_TEST);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.ios.options.other;

import com.google.gson.JsonObject;
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;

public interface SupportsCommandTimeoutsOption<T extends BaseOptions<T>> extends
Capabilities, CanSetCapability<T> {
String COMMAND_TIMEOUTS_OPTION = "commandTimeouts";

/**
* Custom timeout(s) in milliseconds for WDA backend commands execution.
* This might be useful if WDA backend freezes unexpectedly or requires too
* much time to fail and blocks automated test execution. The value is expected
* to be of type string and can either contain max milliseconds to wait for
* each WDA command to be executed before terminating the session forcefully
* or a valid JSON string, where keys are internal Appium command names (you
* can find these in logs, look for "Executing command 'command_name'" records)
* and values are timeouts in milliseconds. You can also set the 'default' key
* to assign the timeout for all other commands not explicitly enumerated as
* JSON keys.
*
* @param timeouts E.g. '{"findElement": 40000, "findElements": 40000}'.
* @return self instance for chaining.
*/
default T setCommandTimeouts(JsonObject timeouts) {
return amend(COMMAND_TIMEOUTS_OPTION, timeouts.toString());
}

/**
* Custom timeout(s) in milliseconds for WDA backend commands execution.
* This might be useful if WDA backend freezes unexpectedly or requires too
* much time to fail and blocks automated test execution. The value is expected
* to be of type string and can either contain max milliseconds to wait for
* each WDA command to be executed before terminating the session forcefully
* or a valid JSON string, where keys are internal Appium command names (you
* can find these in logs, look for "Executing command 'command_name'" records)
* and values are timeouts in milliseconds. You can also set the 'default' key
* to assign the timeout for all other commands not explicitly enumerated as
* JSON keys.
*
* @param timeout The timeout value for all commands.
* @return self instance for chaining.
*/
default T setCommandTimeouts(Duration timeout) {
return amend(COMMAND_TIMEOUTS_OPTION, String.valueOf(timeout.toMillis()));
}

/**
* Get custom timeout(s) in milliseconds for WDA backend commands execution.
*
* @return Command timeouts.
*/
default Optional<String> getCommandTimeouts() {
return Optional.ofNullable(
(String) getCapability(COMMAND_TIMEOUTS_OPTION)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.ios.options.other;

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 SupportsLaunchWithIdbOption<T extends BaseOptions<T>> extends
Capabilities, CanSetCapability<T> {
String LAUNCH_WITH_IDB_OPTION = "launchWithIDB";

/**
* Enforces launching of WebDriverAgentRunner with idb instead of xcodebuild.
*
* @return self instance for chaining.
*/
default T launchWithIdb() {
return amend(LAUNCH_WITH_IDB_OPTION, true);
}

/**
* Launch WebDriverAgentRunner with idb instead of xcodebuild. This could save
* a significant amount of time by skipping the xcodebuild process, although the
* idb might not be very reliable, especially with fresh Xcode SDKs. Check
* the idb repository for more details on possible compatibility issues.
* Defaults to false.
*
* @param value Whether to launch WebDriverAgentRunner with idb instead of xcodebuild.
* @return self instance for chaining.
*/
default T setLaunchWithIdb(boolean value) {
return amend(LAUNCH_WITH_IDB_OPTION, value);
}

/**
* Get whether to launch WebDriverAgentRunner with idb instead of xcodebuild.
*
* @return True or false.
*/
default Optional<Boolean> doesLaunchWithIdb() {
return Optional.ofNullable(toSafeBoolean(getCapability(LAUNCH_WITH_IDB_OPTION)));
}
}
Original file line number Diff line number Diff line change
@@ -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.ios.options.other;

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 SupportsResetOnSessionStartOnlyOption<T extends BaseOptions<T>> extends
Capabilities, CanSetCapability<T> {
String RESET_ON_SESSION_START_ONLY_OPTION = "resetOnSessionStartOnly";

/**
* Whether to perform reset on test session finish (false) or not (true).
* Keeping this variable set to true and Simulator running (the default
* behaviour since version 1.6.4) may significantly shorten the duration of
* test session initialization.
*
* @param value Whether to perform reset on test session finish (false) or not (true)..
* @return self instance for chaining.
*/
default T setResetOnSessionStartOnly(boolean value) {
return amend(RESET_ON_SESSION_START_ONLY_OPTION, value);
}

/**
* Get whether to perform reset on test session finish (false) or not (true).
*
* @return True or false.
*/
default Optional<Boolean> doesResetOnSessionStartOnly() {
return Optional.ofNullable(toSafeBoolean(getCapability(RESET_ON_SESSION_START_ONLY_OPTION)));
}
}
Original file line number Diff line number Diff line change
@@ -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.ios.options.other;

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 SupportsShowIosLogOption<T extends BaseOptions<T>> extends
Capabilities, CanSetCapability<T> {
String SHOW_IOS_LOG_OPTION = "showIOSLog";

/**
* Enforces showing any logs captured from a device in the appium logs.
*
* @return self instance for chaining.
*/
default T showIosLog() {
return amend(SHOW_IOS_LOG_OPTION, true);
}

/**
* Whether to show any logs captured from a device in the appium logs.
* Default false.
*
* @param value Whether to show any logs captured from a device in the appium logs.
* @return self instance for chaining.
*/
default T setShowIosLog(boolean value) {
return amend(SHOW_IOS_LOG_OPTION, value);
}

/**
* Get whether to show any logs captured from a device in the appium logs.
*
* @return True or false.
*/
default Optional<Boolean> doesShowIosLog() {
return Optional.ofNullable(toSafeBoolean(getCapability(SHOW_IOS_LOG_OPTION)));
}
}
Loading