Skip to content

Commit

Permalink
[java] add fields for all supported mobile commands
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Apr 13, 2020
1 parent fb84617 commit cc3a8c2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,74 @@ public class SauceMobileOptions extends SauceOptions {
private SaucePlatform platformName = SaucePlatform.ANDROID;

// Defined in Appium
// These are the only values that are handled by Sauce Labs by default
// Additional values will be populated by Appium's IOSOptions & AndroidOptions class instances
private String app;
private String deviceName;
private String deviceOrientation = "portrait";
private String platformVersion = "9";
private String platformVersion = "10";
private String automationName;

// Supported by Sauce
private String appiumVersion = "1.15.0";
private String deviceType; // "table" or "phone"

// Supported by Sauce for Real Devices
private String testobject_app_id;
private String privateDeviceOnly;
private String tabletOnly;
private String phoneOnly;
private String carrierConnectivityOnly;
private String recordDeviceVitals;
private String cacheId;
private String testobject_test_live_view_url;
private String testobject_test_report_url;
private String testobject_test_report_api_url;
private String testobject_session_creation_timeout;
private String commandTimeouts;
private String crosswalkApplication;
private String autoGrantPermissions;
private String enableAnimations;
private String name;

public static final List<String> mobileW3COptions = List.of(
"browserName",
"platformName");

public static final List<String> mobileSauceDefinedOptions = List.of(
"appiumVersion");
"appiumVersion",
"deviceType");

public static final List<String> appiumDefinedOptions = List.of(
"app",
"automationName",
"deviceName",
"platformVersion",
"deviceOrientation");

public static final List<String> realDeviceSauceDefinedOptions = List.of(
"testobject_app_id",
"privateDeviceOnly",
"tabletOnly",
"phoneOnly",
"carrierConnectivityOnly",
"recordDeviceVitals",
"cacheId",
"testobject_test_live_view_url",
"testobject_test_report_url",
"testobject_test_report_api_url",
"testobject_session_creation_timeout",
"commandTimeouts",
"crosswalkApplication",
"autoGrantPermissions",
"enableAnimations",
"name");

public SauceMobileOptions() {
this(new MutableCapabilities());
}

// TODO: require users to work with Appium's MobileOptions class similar to Selenium
public SauceMobileOptions(MutableCapabilities options) {
appiumCapabilities = new MutableCapabilities(options.asMap());
}
Expand Down Expand Up @@ -76,14 +119,18 @@ private void useW3cCapabilities() {
addCapabilityIfDefined(sauceCapabilities, capability);
});

sauceDefinedOptions.forEach((capability) -> {
addCapabilityIfDefined(appiumCapabilities, capability);
});

appiumCapabilities.setCapability("sauce:options", sauceCapabilities);
}

private void useJwpCapabilities(boolean to) {
if (to) {
appiumCapabilities.setCapability("testobject_api_key", getTestObjectKey());
if (deviceName == null) {
this.deviceName = "Google Pixel XL";
this.deviceName = "Google Pixel 2";
}
} else {
useSaucePlatform(appiumCapabilities);
Expand All @@ -96,6 +143,10 @@ private void useJwpCapabilities(boolean to) {
mobileSauceDefinedOptions.forEach((capability) -> {
addCapabilityIfDefined(appiumCapabilities, capability);
});

realDeviceSauceDefinedOptions.forEach((capability) -> {
addCapabilityIfDefined(appiumCapabilities, capability);
});
}

private void useSaucePlatform(MutableCapabilities capabilities) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.saucelabs.saucebindings.SauceMobileSession;
import io.appium.java_client.AppiumDriver;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertTrue;
Expand All @@ -19,7 +18,7 @@ public void tearDown() {
session.stop(true);
}

@Ignore
@Test
public void runsUSMobile() {
session.setDataCenter(DataCenter.US_MOBILE);
webDriver = session.start();
Expand All @@ -35,7 +34,7 @@ public void runsEUMobile() {
assertTrue(webDriver.getRemoteAddress().toString().contains("eu1.appium.testobject"));
}

@Ignore
@Test
public void runsUSTestObject() {
session.setDataCenter(DataCenter.US_TEST_OBJECT);
webDriver = session.start();
Expand All @@ -51,7 +50,7 @@ public void runsEUTestObject() {
assertTrue(webDriver.getRemoteAddress().toString().contains("//appium.testobject"));
}

@Ignore
@Test
public void runsUnifiedPlatform() {
SauceMobileOptions sauceMobileOptions = new SauceMobileOptions();
sauceMobileOptions.setDeviceName("Google Pixel XL Real");
Expand Down

0 comments on commit cc3a8c2

Please sign in to comment.