调用setUp方法之前的Appium错误

时间:2015-08-19 11:30:33

标签: java nullpointerexception appium

运行测试时出错:

java.lang.NullPointerException
at loginTest.loginWithInvalidEmail(loginTest.java:47)

一切都设置得很好,除了问题出在这段代码中。

当我在setWithInvalidEmail()方法中放置setUp()方法代码时,测试正在运行并成功通过。但最好不要在测试方法中包含此方法。或者也许我应该创建抽象类呢?

public class loginTest {

AppiumDriver driver;

@Before
public AppiumDriver setUp() {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName", "AndroidTestDevice");

    try {
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return driver;

}

@After
public void tearDown() throws Exception {
    driver.quit();
}

@Test
public void loginWithInvalidEmail() throws Exception {

    WebElement emailLoginButton = driver.findElement(By.id("signupButton"));
    emailLoginButton.click();

    WebElement phoneNumberField = driver.findElement(By.id("phoneInput"));
    phoneNumberField.sendKeys("+33340954");

    WebElement firstNameField = driver.findElement(By.id("firstName"));
    firstNameField.sendKeys("Name");

    WebElement lastNameField = driver.findElement(By.id("lastName"));
    lastNameField.sendKeys("Name2");

    WebElement loginButton = driver.findElement(By.id("loginButton"));
    loginButton.click();

    WebElement invalidPhoneNumberErrorMessage = (new WebDriverWait(driver, 60))
            .until(ExpectedConditions.presenceOfElementLocated(By.id("message")));
    assertEquals(invalidPhoneNumberErrorMessage.getText(), "The phone number is incorrect, country code is required");



}

} 眼镜: 在真正的Android Nexus 7,MAC OSX Yosemite,Appium v​​ 1.4.8上运行测试,在IntelliJ上运行测试

1 个答案:

答案 0 :(得分:0)

所以我在每个测试中调用setUp()和tearDown()方法,这样就可以了。