Last active
October 18, 2017 15:22
-
-
Save sauceaaron/95c1a804dede7fb4195cd1d467617c9f to your computer and use it in GitHub Desktop.
Cross device test example using interface and factory
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 AndroidCalculator implements Calculator { //... } |
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(); | |
| //... | |
| } |
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 CalculatorFactory { | |
| public static Calculator getInstance(WebDriver driver) { ... } | |
| } |
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 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(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))} | |
| } | |
| }; | |
| } |
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 IOSCalcuator implements Calculator { //... } |
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 WebCalcuator implements Calculator { //... } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment