It runs first test, but then I'm getting null pointer exception when running Edit Profile test.
Not sure why.
I globally declared public driver.
Please help. Thanks
package test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.tapanalytics.config.Configuration;
import com.tapanalytics.pom.domain.analyticsEditProfilePage;
import com.tapanalytics.pom.domain.analyticsLandingPage;
import com.tapanalytics.pom.domain.analyticsLoginPage;
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();
Thread.sleep(3000);
landingpage.gotoProfile();
//driver.findElement(By.xpath(".//*[@id='left-frame']/div/div[2]/a[3]/span")).click();
//Thread.sleep(5000);
analyticsEditProfilePage editprofile = PageFactory.initElements(driver, analyticsEditProfilePage.class);
editprofile.verifyEditFirstName();
editprofile.verifyEditLastName();
editprofile.verifyCompanyName();
editprofile.verifyReportingProfile();
editprofile.verifyUsageStatistics();
}
@AfterTest
public static void quitDriver(){
driver.quit();
}
PASSED: testLogin
FAILED: verifyProfile
> java.lang.NullPointerException at
> com.tapanalytics.pom.domain.analyticsLandingPage.gotoProfile(analyticsLandingPage.java:42)
> at test.TestLogin.verifyProfile(TestLogin.java:64) at
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:497) at
> org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
> at org.testng.internal.Invoker.invokeMethod(Invoker.java:639) at
> org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816) at
> org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124) at
> org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
> at
> org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
> at org.testng.TestRunner.privateRun(TestRunner.java:774) at
> org.testng.TestRunner.run(TestRunner.java:624) at
> org.testng.SuiteRunner.runTest(SuiteRunner.java:359) at
> org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354) at
> org.testng.SuiteRunner.privateRun(SuiteRunner.java:312) at
> org.testng.SuiteRunner.run(SuiteRunner.java:261) at
> org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at
> org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at
> org.testng.TestNG.runSuitesSequentially(TestNG.java:1215) at
> org.testng.TestNG.runSuitesLocally(TestNG.java:1140) at
> org.testng.TestNG.run(TestNG.java:1048) at
> org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:112) at
> org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205) at
> org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:176)