0

我在 @Test(dataprovider .. 方法中运行浏览器实例。但我无法将驱动程序实例传递给 Test 方法,

这是我的代码,在最后一条语句中我得到一个空点异常。

我的问题是,如何将驱动程序实例传递给测试方法

@Test (dataProviderClass=GetData.class)

public class createUserPageTest {

private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
private MailCode openMail;

@BeforeMethod
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = “http://demo.mysite.com”;
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(baseUrl + “/pageLink/Home.action”);
}
@Test(dataProvider=”RegisterUserStage1″)
public void NewUsrStage1(String name,String email,String password)
{
CreateUserPage createuser = PageFactory.initElements(driver, CreateUserPage.class);
createuser.CreateUserStage1(driver,name,email,password);
try {
openMail.testValidateEmail(driver);
——-
——-

显示的错误信息是

java.lang.NullPointerException
    at demoname.org.createUserPageTest.NewUsrStage1(createUserPageTest.java:38)
    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:80)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:128)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1203)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)
    at org.testng.TestNG.run(TestNG.java:1036)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

我的 DataProvider 名称如下

@DataProvider(name="RegisterUserStage1")
    public static Object[][] getTestData() throws Exception
    {
        Object retObject[][]=getTableArray("src\\resource\\TestData.xls", 0, "NewUserStage1");
        return retObject;
    }
4

1 回答 1

0

那里有多个代码问题。正如 AJ 正确指出初始化的对象。

于 2013-02-26T10:06:22.573 回答