我正在尝试为我的测试使用抽象概念时遇到这个问题。
我的SignIn页面类:
public class SigninPage {
protected AndroidDriver driver;
String app_package_name = "com.xyz.abc:id/";
By signInBtn = By.id(app_package_name + "btn_sign_in");
By enterEmail = By.id(app_package_name + "et_email");
By enterPassword = By.id(app_package_name + "et_password");
public void signInProcess(String username, String password) {
System.out.println("Clicking on Sign in button");
driver.findElement(signInBtn).click();
System.out.println("Enter valid Email");
driver.findElement(enterEmail).sendKeys(username);
System.out.println("Enter password");
driver.findElement(enterPassword).sendKeys(password);
System.out.println("SignIn");
driver.findElement(signInBtn).click();
}
}
我的测试班:
public class SignIn extends LaunchEmulatorAndDeployAPK {
SigninPage sp = new SigninPage();
@Test
public void signInByRegisteredUser() throws Exception {
sp.signInProcess("xyz@test.com", "testpassword");
//Launch Page
Thread.sleep(3000);
By successMessage = By.id("testpath");
Thread.sleep(3000);
boolean result = driver.findElement(successMessage).isDisplayed();
System.out.println("The success message is displayed: " + result);
String text = driver.findElement(successMessage).getText();
System.out.println("The success message text is : " + text);
}
}
我的基类:
public class LaunchEmulatorAndDeployAPK {
protected AndroidDriver driver;
@BeforeTest
protected void prepareAndroidForAppium() throws MalformedURLException {
File appDir = new File("E://path");
File app = new File(appDir, "test.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device", "emulator-5554");
// mandatory capabilities
capabilities.setCapability("deviceName", "emulator-5554");
capabilities.setCapability("platformName", "Android");
// other caps
capabilities.setCapability("app", app.getAbsolutePath());
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@AfterTest
public void teardown() {
driver.quit();
}
}
我在运行测试类时遇到了nullpointer异常
Clicking on Sign in button
FAILED: signInByRegisteredUser
java.lang.NullPointerException
at com.xyz.abc.pages.SigninPage.signInProcess(SigninPage.java:20)
at com.xyz.abc.scenarios.SignIn.signInByRegisteredUser(SignIn.java:17)