如何解决从另一个类调用方法时-抛出Selenium java中的Java空指针异常
当我尝试从同一程序包中的另一个Java类调用方法时,出现以下错误:
通过:validateLogin
失败:测试 java.lang.NullPointerException 在assembly.SlackInviteFlowValidation.selectManageSideNavbar(SlackInviteFlowValidation.java:130)处 在assembly.SlackUpgradeEditViewFlow.test(SlackUpgradeEditViewFlow.java:28) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处 在sun.reflect.NativeMethodAccessorImpl.invoke(未知来源) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源) 在java.lang.reflect.Method.invoke(未知来源) 在org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) 在org.testng.internal.Invoker.invokeMethod(Invoker.java:583) 在org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719) 在org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989) 在org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) 在org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) 在org.testng.TestRunner.privateRun(TestRunner.java:648) 在org.testng.TestRunner.run(TestRunner.java:505) 在org.testng.SuiteRunner.runTest(SuiteRunner.java:455) 在org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) 在org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) 在org.testng.SuiteRunner.run(SuiteRunner.java:364) 在org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 在org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) 在org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) 在org.testng.TestNG.runSuitesLocally(TestNG.java:1137) 在org.testng.TestNG.runSuites(TestNG.java:1049) 在org.testng.TestNG.run(TestNG.java:1017) 在org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115) 在org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) 在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
我正在使用Selenium Webdriver和TestNG框架。这是我的代码,其中SlackInviteFlowValidation和SlackUpgradeEditViewFlow来自同一包,并且扩展了Base类,其中Base类中仅具有Chrome驱动程序的初始化和登录功能。
//类SlackInviteFlowValidation
//验证管理登录页面的功能
public void selectManageSideNavbar() throws InterruptedException {
slackobject.avatarIcon().click();
slackobject.AdminText().click();
slackobject.UsersText().click();
slackobject.ManageText().click();
}
// SlackUpgradeEditViewFlow类
//为类SlackInviteFlowValidation创建对象 SlackInviteFlowValidation slackinvite = new SlackInviteFlowValidation();
公共类SlackUpgradeEditViewFlow扩展了Base {
public static Logger log = LogManager.getLogger(SlackInviteFlowValidation.class.getName());
public SlackIdentityObjects slackobject;
SlackInviteFlowValidation slackinvite = new SlackInviteFlowValidation();
@BeforeTest
public void init() throws FileNotFoundException,IOException {
driver = initializeDriver();
slackobject = new SlackIdentityObjects(driver);
}
@Test
public void test() {
try {
slackinvite.selectManageSideNavbar();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。