Created
June 20, 2019 19:28
-
-
Save sauceaaron/e2c92ac3f067df4aa160ae5c79053580 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.MobileBy; | |
| import io.appium.java_client.ios.IOSDriver; | |
| import org.junit.After; | |
| import org.junit.Before; | |
| import org.junit.Rule; | |
| import org.junit.Test; | |
| import org.junit.rules.TestName; | |
| import org.openqa.selenium.By; | |
| import org.openqa.selenium.remote.DesiredCapabilities; | |
| import org.openqa.selenium.support.ui.ExpectedConditions; | |
| import org.openqa.selenium.support.ui.WebDriverWait; | |
| import org.testobject.appium.junit.TestObjectTestResultWatcher; | |
| import org.testobject.rest.api.RestClient; | |
| import java.net.MalformedURLException; | |
| import java.net.URL; | |
| import static org.assertj.core.api.Assertions.assertThat; | |
| public class LoginTests | |
| { | |
| private static final String testobject_api_key = System.getenv("TESTOBJECT_API_KEY"); | |
| private static final String testobject_url = "https://us1.appium.testobject.com:443/wd/hub"; | |
| private IOSDriver driver; | |
| private WebDriverWait wait; | |
| protected RestClient api; | |
| @Rule | |
| public TestName testName = new TestName(); | |
| @Rule | |
| public TestObjectTestResultWatcher resultWatcher = new TestObjectTestResultWatcher(); | |
| @Before | |
| public void setUp() throws MalformedURLException { | |
| URL remoteUrl = new URL(testobject_url); | |
| DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); | |
| desiredCapabilities.setCapability("platformName", "iOS"); | |
| desiredCapabilities.setCapability("platformVersion", "12"); | |
| desiredCapabilities.setCapability("deviceName", "iPhone.*"); | |
| desiredCapabilities.setCapability("phoneOnly", "true"); | |
| desiredCapabilities.setCapability("testobject_test_name", "test with invalid email address"); | |
| desiredCapabilities.setCapability("testobject_api_key", testobject_api_key); | |
| driver = new IOSDriver(remoteUrl, desiredCapabilities); | |
| wait = new WebDriverWait(driver, 30); | |
| resultWatcher.setRemoteWebDriver(driver); | |
| } | |
| @Test | |
| public void test_with_invalid_email_address() throws MalformedURLException | |
| { | |
| // Select Environment | |
| By environment = MobileBy.AccessibilityId("production"); | |
| driver.findElement(environment).click(); | |
| // Login Screen | |
| By emailField = MobileBy.xpath("//XCUIElementTypeOther[@name=\"signinVC\"]/XCUIElementTypeOther[1]/XCUIElementTypeTextField"); | |
| By passwordField = MobileBy.xpath("//XCUIElementTypeOther[@name=\"signinVC\"]/XCUIElementTypeOther[1]/XCUIElementTypeSecureTextField"); | |
| By signInButton = MobileBy.xpath("(//XCUIElementTypeButton[@name=\"RoundedRectButton.NoTitle\"])[2]"); | |
| wait.until(ExpectedConditions.elementToBeClickable(emailField)).sendKeys("[email protected]"); | |
| wait.until(ExpectedConditions.elementToBeClickable(passwordField)).sendKeys("password"); | |
| wait.until(ExpectedConditions.elementToBeClickable(signInButton)).click(); | |
| By errorMessage = MobileBy.xpath("//XCUIElementTypeApplication[@name=\"Sling TV-9091\"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther[2]/XCUIElementTypeOther[2]/XCUIElementTypeTextView"); | |
| String error = wait.until(ExpectedConditions.presenceOfElementLocated(errorMessage)).getText(); | |
| System.out.println(error); | |
| assertThat(error).contains("Incorrect username or password"); | |
| } | |
| @After | |
| public void teardown() | |
| { | |
| if (driver != null) | |
| { | |
| driver.quit(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment