Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

selenium - Created new class Edit profile. Login works fine, but getting null pointer on verifyEditProfile()

public class EditProfile {
// public static WebDriver driver;

 //public TestLogin login;
// public static String baseURL = Configuration.testsite;
 TestLogin login = new TestLogin();
 public static WebDriver driver; 

@BeforeClass 
@Parameters("browser")
public void LoginToAnalytics() throws Exception{
    //WebDriver driver = new FirefoxDriver();
    login.setup("Firefox");
    login.testLogin();
}

analyticsLoginPage mylogin = PageFactory.initElements(driver, analyticsLoginPage.class);

********//Edit Progile test that fails******

@Test//(dependsOnMethods = { "testLogin" })

///******** Edit profile code

public void verifyEditProfile() throws InterruptedException {

*******//Getting null pointer here. Please help me understand why.///////

    analyticsLandingPage landingpage = PageFactory.initElements(driver, analyticsLandingPage.class);

*******///This will work fine once it gets to this part

    analyticsEditProfilePage editprofile = PageFactory.initElements(driver, analyticsEditProfilePage.class);

*******waiting for page to load ///////////

    Thread.sleep(3000L);
    landingpage.gotoProfile();

    /////This part is not running because of the error***////

    editprofile.verifyEditFirstName();

}
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are not initiated driver, it is null

 public static WebDriver driver; 

you may think starting firefox driver as below, but is it returning the driver?

  login.setup("Firefox");

Change this setup method to return driver and assign this to above static webdriver driver;

   driver= login.setup("Firefox");

Thank you, Murali


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...