-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
possible idea - single SauceSession class, multiple SauceOption classes
- Loading branch information
1 parent
fa3b39b
commit 4bf7e90
Showing
15 changed files
with
197 additions
and
168 deletions.
There are no files selected for viewing
This file contains 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 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 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 { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
// 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 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); | ||
} | ||
} |
This file contains 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 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 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 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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package com.saucelabs.saucebindings; | ||
|
||
import io.appium.java_client.AppiumDriver; | ||
import io.appium.java_client.android.AndroidDriver; | ||
import io.appium.java_client.ios.IOSDriver; | ||
This comment has been minimized.
Sorry, something went wrong.
titusfortner
Collaborator
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.openqa.selenium.InvalidArgumentException; | ||
|
@@ -11,22 +14,37 @@ | |
|
||
public class SauceSession { | ||
@Getter @Setter protected DataCenter dataCenter = DataCenter.US_LEGACY; | ||
@Getter private final SauceOptions sauceOptions; | ||
@Getter private SauceOptions sauceOptions; | ||
@Setter private URL sauceUrl; | ||
|
||
@Getter private RemoteWebDriver driver; | ||
@Getter private RemoteWebDriver webDriver; | ||
@Getter private AppiumDriver appDriver; | ||
|
||
public SauceSession() { | ||
this(new SauceOptions()); | ||
} | ||
|
||
public SauceSession(SauceOptions options) { | ||
sauceOptions = options; | ||
this.sauceOptions = options; | ||
} | ||
|
||
public RemoteWebDriver start() { | ||
driver = createRemoteWebDriver(getSauceUrl(), sauceOptions.toCapabilities()); | ||
return driver; | ||
String environment = sauceOptions.toCapabilities().getCapability("platformName").toString(); | ||
String browserName = sauceOptions.toCapabilities().getBrowserName(); | ||
|
||
if (browserName.equals("")){ | ||
if (environment.toLowerCase().equals("android")){ | ||
return createAndroidDriver(getSauceUrl(), sauceOptions.toCapabilities()); | ||
} | ||
else if (environment.toLowerCase().equals("ios")) { | ||
return createIOSDriver(getSauceUrl(), sauceOptions.toCapabilities()); | ||
} | ||
else { | ||
throw new InvalidArgumentException("Invalid Sauce Labs capabilities. Please set a browser name or set platformName as \"Android\" or \"IOS\"."); | ||
} | ||
} | ||
else { | ||
return createRemoteWebDriver(getSauceUrl(), sauceOptions.toCapabilities()); | ||
} | ||
} | ||
|
||
public URL getSauceUrl() { | ||
|
@@ -45,6 +63,14 @@ protected RemoteWebDriver createRemoteWebDriver(URL url, MutableCapabilities cap | |
return new RemoteWebDriver(url, capabilities); | ||
} | ||
|
||
protected AppiumDriver createIOSDriver(URL url, MutableCapabilities capabilities) { | ||
return new IOSDriver<>(url, capabilities); | ||
} | ||
|
||
protected AppiumDriver createAndroidDriver(URL url, MutableCapabilities capabilities) { | ||
return new AndroidDriver<>(url, capabilities); | ||
} | ||
|
||
public void stop(Boolean passed) { | ||
String result = passed ? "passed" : "failed"; | ||
stop(result); | ||
|
@@ -56,12 +82,20 @@ public void stop(String result) { | |
} | ||
|
||
private void updateResult(String result) { | ||
getDriver().executeScript("sauce:job-result=" + result); | ||
if (webDriver != null) | ||
getWebDriver().executeScript("sauce:job-result=" + result); | ||
else { | ||
System.out.println("use API for mobile case"); | ||
} | ||
|
||
} | ||
|
||
private void stop() { | ||
if(getDriver() !=null) { | ||
getDriver().quit(); | ||
if(getWebDriver() !=null) { | ||
getWebDriver().quit(); | ||
} | ||
if(getAppDriver() != null){ | ||
getAppDriver().quit(); | ||
} | ||
} | ||
} |
This file contains 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/test/java/com/saucelabs/saucebindings/SauceAndroidOptionsTest.java
This file contains 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 org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class SauceAndroidOptionsTest { | ||
|
||
@Test | ||
public void defaultConstructor() { | ||
SauceAndroidOptions options = new SauceAndroidOptions("Android Emulator", "9.0", DeviceOrientation.PORTRAIT); | ||
|
||
Assert.assertEquals(SaucePlatform.ANDROID, options.getPlatformName()); | ||
Assert.assertEquals("9.0", options.getPlatformVersion()); | ||
Assert.assertEquals("Android Emulator", options.getDeviceName()); | ||
Assert.assertEquals(Browser.NONE, options.getBrowserName()); | ||
Assert.assertEquals("", options.getBrowserVersion()); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
java/src/test/java/com/saucelabs/saucebindings/SauceIOSOptionsTest.java
This file contains 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,19 @@ | ||
package com.saucelabs.saucebindings; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class SauceIOSOptionsTest { | ||
|
||
@Test | ||
public void defaultConstructor() { | ||
SauceIOSOptions options = new SauceIOSOptions("iPhone X Simulator", "13.0", DeviceOrientation.PORTRAIT); | ||
|
||
Assert.assertEquals(SaucePlatform.IOS, options.getPlatformName()); | ||
Assert.assertEquals("13.0", options.getPlatformVersion()); | ||
Assert.assertEquals("iPhone X Simulator", options.getDeviceName()); | ||
Assert.assertEquals(Browser.NONE, options.getBrowserName()); | ||
Assert.assertEquals("", options.getBrowserVersion()); | ||
|
||
} | ||
} |
72 changes: 0 additions & 72 deletions
72
java/src/test/java/com/saucelabs/saucebindings/SauceMobileSessionTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
1 comment
on commit 4bf7e90
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.
So users would need to cast the result of the start method to be able to use mobile methods...
Android driver = (AndroidDriver) sauceSession.start();
Would it make sense to have different methods for different returns?
Android driver = sauceSession.startAndroid();
So, we at the very least shouldn't need distinct Android & iOS options, once we get a release with appium/java-client@2c2141e
We want everything specific to Android/iOS handled by Appium code not Sauce code.