它運行第一個測試OK,但是當運行「Edit Profile」測試時,我得到一個空指針異常,我不知道爲什麼。我全球宣佈公共車手。TestNG.java.lang.NullPointerException當運行第二個@Test
public class TestLogin
{
public WebDriver driver;// = new FirefoxDriver();
public String baseURL = "mytestsite.com";
@BeforeTest
public void setBaseURL()
{
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20L, TimeUnit.SECONDS);
driver.get(baseURL);
}
// Login test
@Test
public void testLogin() throws InterruptedException{
driver.manage().timeouts().implicitlyWait(20L, TimeUnit.SECONDS);
analyticsLoginPage mylogin = PageFactory.initElements(driver, ` ` analyticsLoginPage.class);
analyticsLandingPage landingpage = mylogin.login("username", "password");
Thread.sleep(3000);
}
// Edit Profile test
@Test // (dependsOnMethods = { "testLogin" })
public void verifyProfile()
throws InterruptedException
{
// driver = new FirefoxDriver();
Thread.sleep(3000);
analyticsLandingPage landingpage = new analyticsLandingPage(driver);
Thread.sleep(3000);
landingpage.gotoProfile();
// Thread.sleep(5000);
analyticsEditProfilePage editprofile = PageFactory.initElements(driver, analyticsEditProfilePage.class);
editprofile.verifyEditFirstName();
editprofile.verifyEditLastName();
editprofile.verifyCompanyName();
editprofile.verifyReportingProfile();
editprofile.verifyUsageStatistics();
}
着陸頁類
package com.tapanalytics.pom.domain;
import java.util.concurrent.TimeUnit;
import javax.security.auth.login.Configuration;
import org.junit.Test;
public class analyticsLandingPage
{
WebDriver driver;
public analyticsLandingPage(WebDriver driver)
{
this.driver = driver;
}
@FindBy(xpath = Configuration.manage_dashboard)
public WebElement manage_dashboard;
@FindBy(xpath = Configuration.manage_services)
public WebElement manage_services;
@FindBy(xpath = Configuration.profile)
public WebElement profile;
@FindBy(xpath = Configuration.support)
public WebElement support;
@FindBy(xpath = Configuration.logout)
public WebElement logout;
public void gotoMangeDashboards()
{
manage_dashboard.click();
}
public void gotoServices()
{
manage_services.click();
}
public void gotoProfile()
{
profile.click();
}
public void gotoSupport()
{
support.click();
}
public void Logout()
{
logout.click();
}
}
n位於何處? – juherr