Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Espresso options #1563

Merged
merged 5 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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.android.options;

import com.google.gson.GsonBuilder;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public abstract class BaseMapOptionData<T extends BaseMapOptionData<T>> {
protected Map<String, Object> options;

public BaseMapOptionData() {
}

public BaseMapOptionData(Map<String, Object> options) {
this.options = options;
}

/**
* Sets the given value on the data object.
*
* @param key Key name.
* @param value The actual value to set.
* @return self instance for chaining.
*/
public T assignOptionValue(String key, Object value) {
if (options == null) {
options = new HashMap<>();
}
options.put(key, value);
//noinspection unchecked
return (T) this;
}

/**
* Retrieves a value with the given name from a data object.
* This method does not perform any type transformation, but rather
* just tries to cast the received value to the given type, so
* be careful while providing a very specific result type value to
* not get a type cast error.
*
* @param name Key name.
* @param <R> The expected value type.
* @return The actual value.
*/
public <R> Optional<R> getOptionValue(String name) {
//noinspection unchecked
return options == null
? Optional.empty()
: Optional.ofNullable((R) options.getOrDefault(name, null));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return options == null
? Optional.empty()
: Optional.ofNullable((R) options.getOrDefault(name, null));
return Optional.ofNullable(options).map(opts -> (R) opts.getOrDefault(name, null));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

}

public Map<String, Object> toMap() {
return options == null ? Collections.emptyMap() : options;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return options == null ? Collections.emptyMap() : options;
return Optional.ofNullable(options).orElseGet(Collections::emptyMap);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

}

@Override
public String toString() {
return new GsonBuilder().create().toJson(toMap());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
/*
* 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.android.options;

import io.appium.java_client.android.options.adb.SupportsAdbExecTimeoutOption;
import io.appium.java_client.android.options.adb.SupportsAdbPortOption;
import io.appium.java_client.android.options.adb.SupportsAllowDelayAdbOption;
import io.appium.java_client.android.options.adb.SupportsBuildToolsVersionOption;
import io.appium.java_client.android.options.adb.SupportsClearDeviceLogsOnStartOption;
import io.appium.java_client.android.options.adb.SupportsIgnoreHiddenApiPolicyErrorOption;
import io.appium.java_client.android.options.adb.SupportsLogcatFilterSpecsOption;
import io.appium.java_client.android.options.adb.SupportsLogcatFormatOption;
import io.appium.java_client.android.options.adb.SupportsMockLocationAppOption;
import io.appium.java_client.android.options.adb.SupportsRemoteAdbHostOption;
import io.appium.java_client.android.options.adb.SupportsSkipLogcatCaptureOption;
import io.appium.java_client.android.options.adb.SupportsSuppressKillServerOption;
import io.appium.java_client.android.options.app.SupportsActivityOptionsOption;
import io.appium.java_client.android.options.app.SupportsAllowTestPackagesOption;
import io.appium.java_client.android.options.app.SupportsAndroidInstallTimeoutOption;
import io.appium.java_client.android.options.app.SupportsAppActivityOption;
import io.appium.java_client.android.options.app.SupportsIntentOptionsOption;
import io.appium.java_client.android.options.app.SupportsAppWaitDurationOption;
import io.appium.java_client.android.options.app.SupportsAppPackageOption;
import io.appium.java_client.android.options.app.SupportsAppWaitActivityOption;
import io.appium.java_client.android.options.app.SupportsAppWaitPackageOption;
import io.appium.java_client.android.options.app.SupportsAutoGrantPermissionsOption;
import io.appium.java_client.android.options.app.SupportsEnforceAppInstallOption;
import io.appium.java_client.android.options.app.SupportsRemoteAppsCacheLimitOption;
import io.appium.java_client.android.options.app.SupportsUninstallOtherPackagesOption;
import io.appium.java_client.android.options.avd.SupportsAvdArgsOption;
import io.appium.java_client.android.options.avd.SupportsAvdEnvOption;
import io.appium.java_client.android.options.avd.SupportsAvdLaunchTimeoutOption;
import io.appium.java_client.android.options.avd.SupportsAvdOption;
import io.appium.java_client.android.options.avd.SupportsAvdReadyTimeoutOption;
import io.appium.java_client.android.options.avd.SupportsGpsEnabledOption;
import io.appium.java_client.android.options.avd.SupportsNetworkSpeedOption;
import io.appium.java_client.android.options.context.SupportsAutoWebviewTimeoutOption;
import io.appium.java_client.android.options.context.SupportsChromeLoggingPrefsOption;
import io.appium.java_client.android.options.context.SupportsChromeOptionsOption;
import io.appium.java_client.android.options.context.SupportsChromedriverArgsOption;
import io.appium.java_client.android.options.context.SupportsChromedriverChromeMappingFileOption;
import io.appium.java_client.android.options.context.SupportsChromedriverDisableBuildCheckOption;
import io.appium.java_client.android.options.context.SupportsChromedriverExecutableDirOption;
import io.appium.java_client.android.options.context.SupportsChromedriverExecutableOption;
import io.appium.java_client.android.options.context.SupportsChromedriverPortOption;
import io.appium.java_client.android.options.context.SupportsChromedriverPortsOption;
import io.appium.java_client.android.options.context.SupportsChromedriverUseSystemExecutableOption;
import io.appium.java_client.android.options.context.SupportsEnsureWebviewsHavePagesOption;
import io.appium.java_client.android.options.context.SupportsExtractChromeAndroidPackageFromContextNameOption;
import io.appium.java_client.android.options.context.SupportsNativeWebScreenshotOption;
import io.appium.java_client.android.options.context.SupportsRecreateChromeDriverSessionsOption;
import io.appium.java_client.android.options.context.SupportsShowChromedriverLogOption;
import io.appium.java_client.android.options.context.SupportsWebviewDevtoolsPortOption;
import io.appium.java_client.android.options.localization.SupportsAppLocaleOption;
import io.appium.java_client.android.options.localization.SupportsLocaleScriptOption;
import io.appium.java_client.android.options.locking.SupportsSkipUnlockOption;
import io.appium.java_client.android.options.locking.SupportsUnlockKeyOption;
import io.appium.java_client.android.options.locking.SupportsUnlockStrategyOption;
import io.appium.java_client.android.options.locking.SupportsUnlockSuccessTimeoutOption;
import io.appium.java_client.android.options.locking.SupportsUnlockTypeOption;
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.server.SupportsEspressoServerLaunchTimeoutOption;
import io.appium.java_client.android.options.server.SupportsForceEspressoRebuildOption;
import io.appium.java_client.android.options.server.SupportsShowGradleLogOption;
import io.appium.java_client.android.options.server.SupportsSkipServerInstallationOption;
import io.appium.java_client.android.options.server.SupportsSystemPortOption;
import io.appium.java_client.android.options.signing.SupportsKeystoreOptions;
import io.appium.java_client.android.options.signing.SupportsNoSignOption;
import io.appium.java_client.remote.AutomationName;
import io.appium.java_client.remote.MobilePlatform;
import io.appium.java_client.remote.options.BaseOptions;
import io.appium.java_client.remote.options.SupportsAppOption;
import io.appium.java_client.remote.options.SupportsAutoWebViewOption;
import io.appium.java_client.remote.options.SupportsDeviceNameOption;
import io.appium.java_client.remote.options.SupportsIsHeadlessOption;
import io.appium.java_client.remote.options.SupportsLanguageOption;
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-espresso-driver#capabilities
*/
public class EspressoOptions extends BaseOptions<EspressoOptions> implements
// General options: https://github.com/appium/appium-uiautomator2-driver#general
SupportsDeviceNameOption<EspressoOptions>,
SupportsUdidOption<EspressoOptions>,
// Driver/Server options: https://github.com/appium/appium-uiautomator2-driver#driverserver
SupportsSystemPortOption<EspressoOptions>,
SupportsSkipServerInstallationOption<EspressoOptions>,
SupportsEspressoServerLaunchTimeoutOption<EspressoOptions>,
SupportsForceEspressoRebuildOption<EspressoOptions>,
SupportsShowGradleLogOption<EspressoOptions>,
SupportsOrientationOption<EspressoOptions>,
// App options: https://github.com/appium/appium-uiautomator2-driver#app
SupportsAppOption<EspressoOptions>,
SupportsAppPackageOption<EspressoOptions>,
SupportsAppActivityOption<EspressoOptions>,
SupportsAppWaitActivityOption<EspressoOptions>,
SupportsAppWaitPackageOption<EspressoOptions>,
SupportsAppWaitDurationOption<EspressoOptions>,
SupportsAndroidInstallTimeoutOption<EspressoOptions>,
SupportsIntentOptionsOption<EspressoOptions>,
SupportsActivityOptionsOption<EspressoOptions>,
SupportsAutoGrantPermissionsOption<EspressoOptions>,
SupportsOtherAppsOption<EspressoOptions>,
SupportsUninstallOtherPackagesOption<EspressoOptions>,
SupportsAllowTestPackagesOption<EspressoOptions>,
SupportsRemoteAppsCacheLimitOption<EspressoOptions>,
SupportsEnforceAppInstallOption<EspressoOptions>,
// App localization options: https://github.com/appium/appium-uiautomator2-driver#app-localization
SupportsLocaleScriptOption<EspressoOptions>,
SupportsLanguageOption<EspressoOptions>,
SupportsLocaleOption<EspressoOptions>,
SupportsAppLocaleOption<EspressoOptions>,
// ADB options: https://github.com/appium/appium-uiautomator2-driver#adb
SupportsAdbPortOption<EspressoOptions>,
SupportsRemoteAdbHostOption<EspressoOptions>,
SupportsAdbExecTimeoutOption<EspressoOptions>,
SupportsClearDeviceLogsOnStartOption<EspressoOptions>,
SupportsBuildToolsVersionOption<EspressoOptions>,
SupportsSkipLogcatCaptureOption<EspressoOptions>,
SupportsSuppressKillServerOption<EspressoOptions>,
SupportsIgnoreHiddenApiPolicyErrorOption<EspressoOptions>,
SupportsMockLocationAppOption<EspressoOptions>,
SupportsLogcatFormatOption<EspressoOptions>,
SupportsLogcatFilterSpecsOption<EspressoOptions>,
SupportsAllowDelayAdbOption<EspressoOptions>,
// AVD options: https://github.com/appium/appium-uiautomator2-driver#emulator-android-virtual-device
SupportsAvdOption<EspressoOptions>,
SupportsAvdLaunchTimeoutOption<EspressoOptions>,
SupportsAvdReadyTimeoutOption<EspressoOptions>,
SupportsAvdArgsOption<EspressoOptions>,
SupportsAvdEnvOption<EspressoOptions>,
SupportsNetworkSpeedOption<EspressoOptions>,
SupportsGpsEnabledOption<EspressoOptions>,
SupportsIsHeadlessOption<EspressoOptions>,
// App signing options: https://github.com/appium/appium-uiautomator2-driver#app-signing
SupportsKeystoreOptions<EspressoOptions>,
SupportsNoSignOption<EspressoOptions>,
// Device locking options: https://github.com/appium/appium-uiautomator2-driver#device-locking
SupportsSkipUnlockOption<EspressoOptions>,
SupportsUnlockTypeOption<EspressoOptions>,
SupportsUnlockKeyOption<EspressoOptions>,
SupportsUnlockStrategyOption<EspressoOptions>,
SupportsUnlockSuccessTimeoutOption<EspressoOptions>,
// MJPEG options: https://github.com/appium/appium-uiautomator2-driver#mjpeg
SupportsMjpegServerPortOption<EspressoOptions>,
SupportsMjpegScreenshotUrlOption<EspressoOptions>,
// Web Context options: https://github.com/appium/appium-uiautomator2-driver#web-context
SupportsAutoWebViewOption<EspressoOptions>,
SupportsWebviewDevtoolsPortOption<EspressoOptions>,
SupportsEnsureWebviewsHavePagesOption<EspressoOptions>,
SupportsChromedriverPortOption<EspressoOptions>,
SupportsChromedriverPortsOption<EspressoOptions>,
SupportsChromedriverArgsOption<EspressoOptions>,
SupportsChromedriverExecutableOption<EspressoOptions>,
SupportsChromedriverExecutableDirOption<EspressoOptions>,
SupportsChromedriverChromeMappingFileOption<EspressoOptions>,
SupportsChromedriverUseSystemExecutableOption<EspressoOptions>,
SupportsChromedriverDisableBuildCheckOption<EspressoOptions>,
SupportsAutoWebviewTimeoutOption<EspressoOptions>,
SupportsRecreateChromeDriverSessionsOption<EspressoOptions>,
SupportsNativeWebScreenshotOption<EspressoOptions>,
SupportsExtractChromeAndroidPackageFromContextNameOption<EspressoOptions>,
SupportsShowChromedriverLogOption<EspressoOptions>,
SupportsChromeOptionsOption<EspressoOptions>,
SupportsChromeLoggingPrefsOption<EspressoOptions>,
// Other options: https://github.com/appium/appium-uiautomator2-driver#other
SupportsDisableSuppressAccessibilityServiceOption<EspressoOptions>,
SupportsSkipLogCaptureOption<EspressoOptions> {
public EspressoOptions() {
setCommonOptions();
}

public EspressoOptions(Capabilities source) {
super(source);
setCommonOptions();
}

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

private void setCommonOptions() {
setPlatformName(MobilePlatform.ANDROID);
setAutomationName(AutomationName.ESPRESSO);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import io.appium.java_client.android.options.app.SupportsAllowTestPackagesOption;
import io.appium.java_client.android.options.app.SupportsAndroidInstallTimeoutOption;
import io.appium.java_client.android.options.app.SupportsAppActivityOption;
import io.appium.java_client.android.options.app.SupportsAppDurationOption;
import io.appium.java_client.android.options.app.SupportsAppWaitDurationOption;
import io.appium.java_client.android.options.app.SupportsAppPackageOption;
import io.appium.java_client.android.options.app.SupportsAppWaitActivityOption;
import io.appium.java_client.android.options.app.SupportsAppWaitForLaunchOption;
Expand Down Expand Up @@ -130,7 +130,7 @@ public class UiAutomator2Options extends BaseOptions<UiAutomator2Options> implem
SupportsAppActivityOption<UiAutomator2Options>,
SupportsAppWaitActivityOption<UiAutomator2Options>,
SupportsAppWaitPackageOption<UiAutomator2Options>,
SupportsAppDurationOption<UiAutomator2Options>,
SupportsAppWaitDurationOption<UiAutomator2Options>,
SupportsAndroidInstallTimeoutOption<UiAutomator2Options>,
SupportsAppWaitForLaunchOption<UiAutomator2Options>,
SupportsIntentCategoryOption<UiAutomator2Options>,
Expand Down
Original file line number Diff line number Diff line change
@@ -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.android.options.app;

import io.appium.java_client.android.options.BaseMapOptionData;

import java.util.Map;
import java.util.Optional;

public class ActivityOptions extends BaseMapOptionData<ActivityOptions> {
public ActivityOptions() {
super();
}

public ActivityOptions(Map<String, Object> options) {
super(options);
}

/**
* Display id which you want to assign to launch the main app activity on.
* This might be useful if the device under test supports multiple displays.
*
* @param id Display identifier.
* @return self instance for chaining.
*/
public ActivityOptions withLaunchDisplayId(int id) {
return assignOptionValue("launchDisplayId", id);
}

/**
* Get display id which you want to assign to launch the main app activity on.
*
* @return Display identifier.
*/
public Optional<Integer> getLaunchDisplayId() {
Optional<Object> result = getOptionValue("launchDisplayId");
return result.map((v) -> Integer.parseInt(String.valueOf(v)));
}
}