安装程序方法调用前的Appium错误



运行测试时出现错误:

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

一切都设置好了,除了问题在这段代码的某个地方。

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

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上运行测试

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

相关内容

  • 没有找到相关文章

最新更新