-
Notifications
You must be signed in to change notification settings - Fork 16
WIP for mobile support #147
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
Draft
titusfortner
wants to merge
10
commits into
main
Choose a base branch
from
mobile4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0adcde3
[java] move authentication handling into the Options class
titusfortner 2c4a69c
[java] add direct support for headless
titusfortner d1c39cf
[java] do not need JavaScript Executor
titusfortner 0a3c26c
[java] add support for mobile browser on emusim with w3c + Appium
titusfortner 5fe6a3d
[java] add support for mobile browser on emusim with w3c toggle to su…
titusfortner 6e64aad
[java] add support for real devices on test object platforms
titusfortner fb84617
[java] add support for running with native application
titusfortner cc3a8c2
[java] add fields for all supported mobile commands
titusfortner fa3b39b
SQUASH - fix codacy issues
titusfortner 4bf7e90
possible idea - single SauceSession class, multiple SauceOption classes
joshmgrant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
java/src/main/java/com/saucelabs/saucebindings/DeviceOrientation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.saucelabs.saucebindings; | ||
|
||
import lombok.Getter; | ||
|
||
public enum DeviceOrientation { | ||
PORTRAIT("portrait"), | ||
LANDSCAPE("landscape"); | ||
|
||
@Getter private final String value; | ||
|
||
DeviceOrientation(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String toString() { | ||
return value; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
java/src/main/java/com/saucelabs/saucebindings/SauceAndroidOptions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.saucelabs.saucebindings; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.experimental.Accessors; | ||
import org.openqa.selenium.MutableCapabilities; | ||
|
||
@Accessors(chain = true) | ||
@Setter @Getter | ||
public class SauceAndroidOptions extends SauceOptions { | ||
|
||
// minimal configuration | ||
private DeviceOrientation deviceOrientation; | ||
private String deviceName; | ||
private String platformVersion; | ||
|
||
public SauceAndroidOptions(String deviceName, String platformVersion, DeviceOrientation deviceOrientation){ | ||
super(); | ||
this.platformName = SaucePlatform.ANDROID; | ||
this.browserName = Browser.NONE; | ||
this.browserVersion = ""; | ||
this.deviceName = deviceName; | ||
this.platformVersion = platformVersion; | ||
this.deviceOrientation = deviceOrientation; | ||
} | ||
|
||
public SauceAndroidOptions(MutableCapabilities capabilities){ | ||
super(capabilities); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
java/src/main/java/com/saucelabs/saucebindings/SauceIOSOptions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.saucelabs.saucebindings; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.experimental.Accessors; | ||
import org.openqa.selenium.MutableCapabilities; | ||
|
||
@Accessors(chain = true) | ||
@Setter @Getter | ||
public class SauceIOSOptions extends SauceOptions { | ||
|
||
// minimal configuration | ||
private DeviceOrientation deviceOrientation; | ||
private String deviceName; | ||
private String platformVersion; | ||
|
||
public SauceIOSOptions(String deviceName, String platformVersion, DeviceOrientation deviceOrientation){ | ||
super(); | ||
this.platformName = SaucePlatform.IOS; | ||
this.browserName = Browser.NONE; | ||
this.platformVersion = ""; | ||
this.deviceName = deviceName; | ||
this.platformVersion = platformVersion; | ||
this.deviceOrientation = deviceOrientation; | ||
} | ||
|
||
public SauceIOSOptions(MutableCapabilities capabilities){ | ||
super(capabilities); | ||
} | ||
} |
175 changes: 175 additions & 0 deletions
175
java/src/main/java/com/saucelabs/saucebindings/SauceMobileOptions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
package com.saucelabs.saucebindings; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.experimental.Accessors; | ||
import org.openqa.selenium.MutableCapabilities; | ||
|
||
import java.util.List; | ||
|
||
@Accessors(chain = true) | ||
@Setter @Getter | ||
public class SauceMobileOptions extends SauceOptions { | ||
@Setter(AccessLevel.NONE) private MutableCapabilities appiumCapabilities; | ||
|
||
// Defined in W3C | ||
private Browser browserName = Browser.CHROME; | ||
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 = "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", | ||
"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()); | ||
} | ||
|
||
public MutableCapabilities toCapabilities(DataCenter dataCenter) { | ||
if (app != null) { | ||
browserName = null; | ||
} | ||
|
||
mobileW3COptions.forEach((capability) -> { | ||
addCapabilityIfDefined(appiumCapabilities, capability); | ||
}); | ||
|
||
if (dataCenter.supportsW3C()) { | ||
useW3cCapabilities(); | ||
} else { | ||
useJwpCapabilities(dataCenter.isTestObject()); | ||
} | ||
return appiumCapabilities; | ||
} | ||
|
||
private void useW3cCapabilities() { | ||
MutableCapabilities sauceCapabilities = new MutableCapabilities(); | ||
useSaucePlatform(sauceCapabilities); | ||
|
||
appiumDefinedOptions.forEach((capability) -> { | ||
addAppiumCapabilityIfDefined(appiumCapabilities, capability); | ||
}); | ||
|
||
mobileSauceDefinedOptions.forEach((capability) -> { | ||
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 2"; | ||
} | ||
} else { | ||
useSaucePlatform(appiumCapabilities); | ||
} | ||
|
||
appiumDefinedOptions.forEach((capability) -> { | ||
addCapabilityIfDefined(appiumCapabilities, capability); | ||
}); | ||
|
||
mobileSauceDefinedOptions.forEach((capability) -> { | ||
addCapabilityIfDefined(appiumCapabilities, capability); | ||
}); | ||
|
||
realDeviceSauceDefinedOptions.forEach((capability) -> { | ||
addCapabilityIfDefined(appiumCapabilities, capability); | ||
}); | ||
} | ||
|
||
private void useSaucePlatform(MutableCapabilities capabilities) { | ||
if (deviceName == null) { | ||
this.deviceName = "Android GoogleAPI Emulator"; | ||
} | ||
addAuthentication(capabilities); | ||
} | ||
|
||
private void addAppiumCapabilityIfDefined(MutableCapabilities capabilities, String capability) { | ||
Object value = getCapability(capability); | ||
if (value != null) { | ||
capabilities.setCapability("appium:" + capability, value); | ||
} | ||
} | ||
|
||
protected String getTestObjectKey() { | ||
if (getSystemProperty("TEST_OBJECT_KEY") != null) { | ||
return getSystemProperty("TEST_OBJECT_KEY"); | ||
} else if (getEnvironmentVariable("TEST_OBJECT_KEY") != null) { | ||
return getEnvironmentVariable("TEST_OBJECT_KEY"); | ||
} else { | ||
throw new SauceEnvironmentVariablesNotSetException("Test Object API Key was not provided"); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
java/src/main/java/com/saucelabs/saucebindings/SauceMobileSession.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.saucelabs.saucebindings; | ||
|
||
import io.appium.java_client.AppiumDriver; | ||
import lombok.Getter; | ||
import org.openqa.selenium.Capabilities; | ||
import org.openqa.selenium.InvalidArgumentException; | ||
import org.openqa.selenium.MutableCapabilities; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
public class SauceMobileSession extends SauceSession { | ||
@Getter private final SauceMobileOptions sauceOptions; | ||
@Getter private AppiumDriver driver; | ||
|
||
public SauceMobileSession() { | ||
this(new SauceMobileOptions()); | ||
} | ||
|
||
public SauceMobileSession(SauceMobileOptions options) { | ||
sauceOptions = options; | ||
} | ||
|
||
public AppiumDriver start() { | ||
MutableCapabilities capabilities = sauceOptions.toCapabilities(getDataCenter()); | ||
|
||
URL url; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (dataCenter.supportsW3C() || dataCenter.isTestObject()) { | ||
url = getSauceUrl(); | ||
} else { | ||
String username = (String) capabilities.getCapability("username"); | ||
String key = (String) capabilities.getCapability("accessKey"); | ||
url = getSauceUrl(username, key); | ||
} | ||
|
||
//driver = createRemoteWebDriver(url, capabilities); | ||
return driver; | ||
} | ||
|
||
public AppiumDriver createAppiumDriver(URL url, Capabilities caps) { | ||
return new AppiumDriver<>(url, caps); | ||
} | ||
|
||
public URL getSauceUrl(String username, String key) { | ||
String url = dataCenter.getValue().replace("://", "://" + username + ":" + key + "@"); | ||
try { | ||
return new URL(url); | ||
} catch (MalformedURLException e) { | ||
throw new InvalidArgumentException("Invalid URL"); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how I feel about Dividing
SauceSession
andSauceMobileSession
. Can we combine the logic here intoSauceSession
and have a singlesession
concept?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need some way of differentiating Appium Driver from Selenium Driver type. I started to look into doing generics and interfaces, but I can't tell if that's actually better for users.