Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sauceaaron/d769db1eb38260fed7bbb0dce432b53f to your computer and use it in GitHub Desktop.
Save sauceaaron/d769db1eb38260fed7bbb0dce432b53f to your computer and use it in GitHub Desktop.
Use separate Selenium and Appium sessions together to test web and mobile app interaction.
public void testCustomerDeviceAndBaristaTerminalTogether()
{
// Create two sessions in one test -- one on a browser for the barista and one on a mobile device for the customer
browser = new RemoteWebDriver(seleniumServerURL, browserCapabilites);
phone = new AppiumDriver(appiumServerURL, deviceCapabilities);
// Barista logs into terminal app in browser
browser.get(baristaApp.loginPage.url);
browser.findElement(baristaApp.loginPage.usernameField).sendKeys(barista.username);
browser.findElement(baristaApp.loginPage.passwordField).sendKeys(barista.password);
browser.findElement(baristaApp.loginPage.loginButton).click();
// Customer logs into mobile app on mobile device
phone.findElement(mobileApp.loginScreen.usernameField).sendKeys(customer.username);
phone.findElement(mobileApp.loginScreen.passwordField).sendKeys(customer.password);
phone.findElement(mobileApp.loginScreen.loginButton).click();
// Customer selects a coffee -- after login succeeded
coffeeButton = phoneWait.until(ExpectedConditions.elementToBeClickable(mobileApp.menuScreen.coffeeButton));
coffeeButton.click();
// Barista receives the order and marks it out of stock
browserWait.until(ExpectedConditions.visibilityOfElementLocated(baristaApp.orderDialog));
browser.findElement(baristaApp.orderDialog.outOfStockButton).click();
// Customer is prompted to cancel or place new order
orderConfirmationDialog = phoneWait.until(ExpectedConditions.visibilityOfElementLocated(mobileApp.orderConfirmationDialog));
// User receives out of stock notification and can cancel or place new order
assertThat(orderConfirmationDialog.getText()).contains("Out of Stock");
assertThat(orderConfirmationDialog.findElement(By.accessibilityId("Cancel Order"))).exists();
assertThat(orderConfirmationDialog.findElement(By.accessibilityId("Place New Order"))).exists();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment