使用 verifyTrue(boolean) 期间出现 NullPointerException
我将 Selenium 与 Java、TestNG 一起使用。我的java代码如下:
public static SeleneseTestCase seleneseTestCase;
(类级别变量)
@Test(groups = {"All Blank"})
public void a() throws Exception {
selenium.click("btnLogin");
seleneseTestCase.verifyTrue(selenium.isTextPresent("Please enter valid e-mail ID"));
}
运行应用程序时出现异常,
seleneseTestCase.verifyTrue(selenium.isTextPresent("Please enter valid e-mail ID"));
Exception:FAILED: a
java.lang.NullPointerException
at login.Login.a(Login.java:41)
我需要帮助
I am using Selenium with Java, TestNG. My java code is as follows:
public static SeleneseTestCase seleneseTestCase;
(class level variable)
@Test(groups = {"All Blank"})
public void a() throws Exception {
selenium.click("btnLogin");
seleneseTestCase.verifyTrue(selenium.isTextPresent("Please enter valid e-mail ID"));
}
While running the application there was an exception on the line
seleneseTestCase.verifyTrue(selenium.isTextPresent("Please enter valid e-mail ID"));
Exception:FAILED: a
java.lang.NullPointerException
at login.Login.a(Login.java:41)
I need help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯,在类 login.Login 的第 41 行,在方法“a”中,出现了一个 NullPointerException。看起来好像这是按下按钮后调用的代码。不过,从错误消息中可以明显看出这一点,不是吗?您需要查看 Login 第 41 行,找出可能为 null 的内容、原因以及如何更好地处理该情况。
Well, at line 41 in the class login.Login, in the method "a", there was a
NullPointerException
. It looks as though this is the code that gets called then that button is pressed. That much is obvious from the error message, though, isn't it? You need to go look at Login line 41, and figure out what could be null and why and how you can better handle that condition.selenium
或seleneseTestCase
为 null。Either
selenium
orseleneseTestCase
is null.您还可以确保在单击按钮后等待看到“请输入有效的电子邮件 ID”文本。
You can also make sure that you are performing wait to see 'Please enter valid e-mail ID" Text after click on button.