【发布时间】:2019-08-23 23:04:09
【问题描述】:
我尝试在 Java + Selenium WebDriver 上编写自动化测试,这个特定的测试现在可以正常工作,但在我看来,代码质量存在问题 - 最奇怪的行是在这里为每个测试调用超类的对象.
我尝试通过删除测试方法中的所有对象调用并在类中添加一个对象调用来重构它,但得到了 NullPointerException。
@BeforeTest
public void initialize() throws IOException{
driver = initializeDriver();
}
@Test
public void sendRecoverEmailValid() {
ForgotPasswordPage fp = new ForgotPasswordPage(driver);
fp.AssertForgotPasswordPage();
fp.setRecoverEmail(validRecoveryEmail);
fp.pressSendButton();
RecoverPasswordValidationPage rpvp = new RecoverPasswordValidationPage(driver);
rpvp.AssertRecoverPasswordValidationPage();
}
@Test
public void sendRecoverEmailInvalid() {
ForgotPasswordPage fp = new ForgotPasswordPage(driver);
fp.AssertForgotPasswordPage();
fp.setRecoverEmail(invalidRecoveryEmail);
fp.pressSendButton();
fp.AssertRecoverEmailErrorPresece();
}
@AfterTest
public void shutdown() {
shutdownDriver();
}
那么,我该如何解决呢? 也许您对 java/selenium 的清晰代码有任何其他建议,请写信。我会很感激的。
非常感谢!
【问题讨论】:
-
你从哪里得到 NullPointerException?
标签: java selenium oop selenium-webdriver