Created
May 16, 2018 00:43
-
-
Save sauceaaron/10a8eb10d7e194d83f6623d8952cb5a8 to your computer and use it in GitHub Desktop.
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
| import io.appium.java_client.AppiumDriver; | |
| import org.junit.After; | |
| import org.junit.Before; | |
| import org.junit.Test; | |
| import org.openqa.selenium.By; | |
| import org.openqa.selenium.WebElement; | |
| import org.openqa.selenium.remote.DesiredCapabilities; | |
| import org.openqa.selenium.support.ui.ExpectedConditions; | |
| import org.openqa.selenium.support.ui.WebDriverWait; | |
| import java.net.MalformedURLException; | |
| import java.net.URL; | |
| import java.util.Set; | |
| public class SimpleRegistrationTest | |
| { | |
| public static final String TESTOBJECT_API_KEY = System.getenv("TESTOBJECT_API_KEY"); // set environment variable | |
| public static final String TESTOBJECT_ENDPOINT_US = "https://us1.appium.testobject.com/wd/hub"; | |
| private AppiumDriver driver; | |
| private WebDriverWait wait; | |
| @Before | |
| public void setup() throws MalformedURLException | |
| { | |
| URL appiumURL = new URL(TESTOBJECT_ENDPOINT_US); | |
| DesiredCapabilities capabilities = new DesiredCapabilities(); | |
| capabilities.setCapability("testobject_api_key", TESTOBJECT_API_KEY); | |
| capabilities.setCapability("testobject_test_name", "Simple Registration Test"); | |
| capabilities.setCapability("testobject_suite_name", "OptumRx"); | |
| capabilities.setCapability("appiumVersion", "1.7.2"); | |
| capabilities.setCapability("platformName", "Android"); | |
| capabilities.setCapability("platformVersion", "6.0.1"); | |
| capabilities.setCapability("deviceName", "Samsung Galaxy S6"); | |
| capabilities.setCapability("appPackage", "com.optum.rx"); | |
| capabilities.setCapability("appActivity", "com.optum.rx.OptumRx"); | |
| driver = new AppiumDriver(appiumURL, capabilities); | |
| // driver.manage().timeouts().implicitlyWait(60, SECONDS); | |
| wait = new WebDriverWait(driver, 60); | |
| } | |
| @Test | |
| public void navigateToRegistration() | |
| { | |
| switchToWebView(); | |
| wait.until(ExpectedConditions.elementToBeClickable(updateButton)).click(); | |
| wait.until(ExpectedConditions.elementToBeClickable(registerButton)).click(); | |
| System.out.println("version: " + driver.findElement(appVersion).getText()); | |
| switchWindows(); | |
| WebElement registration = wait.until(ExpectedConditions.visibilityOfElementLocated(registrationHeading)); | |
| System.out.println(registration.getText()); | |
| } | |
| @After | |
| public void teardown() | |
| { | |
| driver.quit(); | |
| } | |
| // HELPER FUNCTIONS | |
| private String switchToWebView() | |
| { | |
| Set<String> contextHandles = driver.getContextHandles(); | |
| System.out.println("contextHandles: " + contextHandles); | |
| for (String contextHandle : contextHandles) | |
| { | |
| if (contextHandle.startsWith("WEBVIEW")) | |
| { | |
| driver.context(contextHandle); | |
| } | |
| } | |
| return driver.getContext(); | |
| } | |
| private String switchWindows() | |
| { | |
| Set<String> windowHandles = driver.getWindowHandles(); | |
| System.out.println("windowHandles: " + windowHandles); | |
| for (String windowHandle : windowHandles) | |
| { | |
| if (!windowHandle.equalsIgnoreCase(driver.getWindowHandle())) | |
| { | |
| driver.switchTo().window(windowHandle); | |
| } | |
| } | |
| return driver.getWindowHandle(); | |
| } | |
| // LOCATORS | |
| public static By updateButton = By.xpath("//*[@id='btnStart']"); | |
| public static By signInButton = By.id("hsIdSignInBtn"); | |
| public static By registerButton = By.id("hsIdRegisterBtn"); | |
| public static By appVersion = By.id("versionNbr"); | |
| public static By registrationHeading = By.xpath("//*[@id='header']/h1/strong"); | |
| public static class RegistrationScreen | |
| { | |
| public static By heading = By.xpath("//*[@id='header']/h1/strong"); | |
| public static By firstNameField = By.id("piFirstName"); | |
| public static By lastNameField = By.id("piLastName"); | |
| public static By dateOfBirthField = By.id("piDoB"); | |
| public static By zipCodeField = By.id("piZipCode"); | |
| public static By memberIdField = By.id("piMemberId4Rx"); | |
| public static By continueButton = By.xpath("//*[contains(@content-desc, 'Continue')]"); | |
| public static By errorMessage = By.xpath("//*[contains(@content-desc, 'Error')]"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment