在再次运行driver.get selenium webdriver时获取空指针异常

时间:2017-10-19 11:47:16

标签: java selenium-webdriver

我正在运行测试套件,我的测试用例扩展了以下基类:

public class BaseTestSuite {
    public static final Logger log = LogManager.getLogger(C2630.class.getName());
    public WebDriver driver;
    public String baseURL;
    public LoginPageFactory loginPage;
    public DashboardPageFactory dashboardPage;
    public MerchantsPageFactory merchantsPage;
    public MerchantDashboardPageFactory merchantDashboard;
    public PayPagesPageFactory payPage;
    public LaunchPageFactory launchPage;
    public HubPayPagePageFactory hubPayPage;
    public TransactionCompletePageFactory transactionCompletePage;


    @BeforeSuite
    public void beforeSuite() {
        baseURL = "myWebsite.com";
        System.setProperty("webdriver.chrome.driver", "D:/Automation/chrome driver/chromedriver.exe");
        driver = new ChromeDriver();
        // Maximize the browser's window
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        loginPage = new LoginPageFactory(driver);
        dashboardPage = new DashboardPageFactory(driver);
        merchantsPage = new MerchantsPageFactory(driver);
        merchantDashboard = new MerchantDashboardPageFactory(driver);
        payPage = new PayPagesPageFactory(driver);
        launchPage = new LaunchPageFactory(driver);
        hubPayPage = new HubPayPagePageFactory(driver);
        transactionCompletePage = new TransactionCompletePageFactory(driver);
    }

    @BeforeClass
    public void beforeClass() {
        driver.get(baseURL);
    }

}

第一个测试用例在通过Before Suite和Before Class时运行正常,但是当第二个测试用例开始时,我想将它重定向到MyWebsite.com,以便它从主页开始,但是当它出现时我收到错误运行该行并跳过整个测试。任何想法都会有所帮助,谢谢!

这是例外

java.lang.NullPointerException
    at testClasses.C2631.TestCase(C2631.java:12)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:744)
    at org.testng.TestRunner.run(TestRunner.java:602)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
    at org.testng.SuiteRunner.run(SuiteRunner.java:289)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
    at org.testng.TestNG.runSuites(TestNG.java:1144)
    at org.testng.TestNG.run(TestNG.java:1115)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

0 个答案:

没有答案