Skip to content

Instantly share code, notes, and snippets.

@sauceaaron
Created December 6, 2018 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sauceaaron/5d42af4f9e28650f3bfd96499921b882 to your computer and use it in GitHub Desktop.
Save sauceaaron/5d42af4f9e28650f3bfd96499921b882 to your computer and use it in GitHub Desktop.
Test Appium session interacting with the Barista API
public void testCustomerDeviceWithBaristaApi()
{
// Create a session for the customer app
phone = new AppiumDriver(sauceURL, deviceCapabilities);
// Create an API service that interacts with the mobile app
baristaAPI = new BaristaAPI(barristUsername, baristaPassword);
// 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();
// API finds the customer order and sets it to out of stock
order = baristaApi.findOrdersForCustomer(customer.username).get(0);
baristaApi.markOrderAsOutOfStock(order);
// 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