Last active
October 18, 2017 15:32
-
-
Save sauceaaron/4e5cfc80e23694973f02114fd1a8f91a to your computer and use it in GitHub Desktop.
Example cross platform test that can use IOSDriver or AndroidDriver
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
| public interface Calculator { | |
| WebElement getNumberKey(); | |
| WebElement getPlusKey(); | |
| WebElement getEqualsKey(); | |
| void pressNumber(int number); | |
| void pressPlusKey(); | |
| void pressEqualsKey(); | |
| //... | |
| } | |
| public class AndroidCalculator implements Calculator { //... } | |
| public class IOSCalcluator implements Calculator { //... } | |
| public class WebCalculator implements Calculator { //... } | |
| public class CalculatorFactory { | |
| public static Calculator getInstance(WebDriver driver) { //... } | |
| } | |
| androidCalculator = CalculatorFactory.getInstance(androidDriver); | |
| iphoneCalculator = CalculatorFactory.getInstance(iosDriver); | |
| webCalculator = CalculatorFactory.getInstance(webDriver); | |
| public class CalculatorTests { | |
| Calculator calculator; | |
| public CalculatorTests(Calculator calculator) { | |
| this.calculator = calculator; | |
| } | |
| @Test | |
| public void add_two_numbers() { | |
| calculator.pressNumber(1); | |
| calculator.pressPlus(); | |
| calculator.pressNumber(2); | |
| calculator.pressEquals(); | |
| int total = Integer.valueOf(calculator.readDisplay()); | |
| assertEquals(1+2, total) | |
| } | |
| @DataProvider(Method method, parallel = true) | |
| public static Object[][] calculatorProvider() { | |
| URL sauceUrl = new URL("https://SAUCE_USERNAME:[email protected]:443/wd/hub"); | |
| DesiredCapabilities androidCapabilities = new DesiredCapabilities(); | |
| androidCapabilitlies.put("platformName", "Android"); | |
| //... | |
| DesiredCapabilities iphoneCapabilities = new DesiredCapabilities(); | |
| iphoneCapabilitlies.put("platformName", "iOS"); | |
| //... | |
| return new Object[][] { | |
| new Object[] { new AndroidCalculator(new AndroidDriver(sauceURL, androidCapabilities))}, | |
| new Object[] { new IOSCalculator(new IOSDriver(sauceURL, iphoneCapabilities))} | |
| } | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment