TestNG配置失败@AfterTest

时间:2017-09-13 11:04:48

标签: selenium-webdriver testng

@After方法失败配置错误在我运行此代码时出现。

 package automationFramework;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    import org.openqa.selenium.support.PageFactory;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.Test;

    import pageobjects.LoginPageObj;

    public class TestCase_POF {

        WebDriver driver;
        LoginPageObj lpo;

        @BeforeMethod
        public void beforeMethod() {

            System.setProperty("webdriver.chrome.driver", "h:\\chromedriver.exe");
            ChromeOptions options = new ChromeOptions();
            options.addArguments("disable-infobars");
            options.addArguments("--start-maximized");
            WebDriver driver = new ChromeDriver(options);
            driver.get("https://slingshotinsights.com/");

        }

        @Test
        public void test() {
            lpo = PageFactory.initElements(driver, LoginPageObj.class);
            lpo.LoginAction("johnmc", "k12345678");
            System.out.println("User has been Logged-in Successfully");

        }

        @AfterMethod
        public void afterMethod() {

            driver.quit();

        }
    }

以下是eclipse控制台的输出 FAILED CONFIGURATION:@AfterMethod afterMethod 显示java.lang.NullPointerException

1 个答案:

答案 0 :(得分:1)

是的,驱动程序为空。

<property>
<name>yarn.scheduler.maximum-allocation-vcores</name>
<value>4</value>
<source>yarn-site.xml</source>
</property>

<property>
<name>yarn.app.mapreduce.am.resource.cpu-vcores</name>
<value>1</value>
<source>mapred-default.xml</source>
</property>

<property>
<name>mapreduce.reduce.cpu.vcores</name>
<value>1</value>
<source>mapred-default.xml</source>
</property>

<property>
<name>yarn.nodemanager.resource.cpu-vcores</name>
<value>8</value>
<source>yarn-default.xml</source>
</property>

<property>
<name>mapreduce.map.cpu.vcores</name>
<value>1</value>
<source>mapred-default.xml</source>
</property>

<property>
<name>yarn.scheduler.minimum-allocation-vcores</name>
<value>1</value>
<source>yarn-site.xml</source>
</property>

<property>
<name>yarn.scheduler.increment-allocation-vcores</name>
<value>1</value>
<source>yarn-site.xml</source>
</property>

已经声明了类级WebDriver驱动程序;