Reputation: 23
Please help me in this, @BeforeClass
runs successfully, but going into the @Test
method it throws the below exception. The code in the `@Test' doesn't run properly.
I was able to run the code successfully before few months but now it is not working. I'm using selenium-server-standalone-2.39.0.jar
.
The exception:
java.lang.NullPointerException
at scripts.IRS_TP_3_Contribution.test990TP2(IRS_TP_3_Contribution.java:51)
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:84)
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:127)
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:335)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
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:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
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)
Here is the Code:
@BeforeClass
public void launchBrowser() throws IOException, InterruptedException
{
System.setProperty("webdriver.chrome.driver","E://FELIX//Automation Testing//Jar files//chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("Link Hided");
driver.findElement(By.id("LEmailAddress")).clear();
driver.findElement(By.id("LEmailAddress")).sendKeys("[email protected]");
driver.findElement(By.id("Password")).clear();
driver.findElement(By.id("Password")).sendKeys("123456");
driver.findElement(By.id("btnSubmit")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("//body/div[2]/div[3]/div[3]/div/div[1]/table/tbody/tr/td[1]/form/div/div[3]/table/tbody/tr[9]/td[3]/a")).click();
//driver.findElement(By.xpath("(//a[contains(text(),'Edit')])[5]")).click();
driver.findElement(By.id("btnContributionRevenueStart")).click();
driver.findElement(By.id("btnContributionGiftsStart")).click();
driver.findElement(By.linkText("Add Contributions and Grants")).click();
//driver.findElement(By.id("ContributorName")).clear();
// Need Iteration for 992
//driver.findElement(By.id("Line1_IsGrantsEquivalentYes")).click();
//driver.findElement(By.xpath("//input[@value='Go to Express990']")).click();
/*for (int second = 0;; second++) {
if (second >= 20) fail("timeout");
try { if (isElementPresent(By.xpath("//input[@value='Go to Express990']"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.xpath("//input[@value='Go to Express990']")).click();*/
}
@Test (dataProvider = "DP1")
public void test990TP2(String contributorName, String contributorType, String add1, String city, String state, String zip, String amount) throws Exception {
driver.manage().timeouts().implicitlyWait(05, TimeUnit.SECONDS);
//driver.findElement(By.id("btnAddAnother")).click();
// Orgnaization Info
// ERROR: Caught exception [ERROR: Unsupported command [typeKeys | id=EIN | 00-9000004]]
/*driver.findElement(By.linkText("Add Contributions and Grants")).click();
//driver.findElement(By.id("ContributorName")).clear();
driver.findElement(By.id("ContributorName")).sendKeys(contributorName);*/
driver.findElement(By.id("ContributorName")).sendKeys(contributorName);
new Select(driver.findElement(By.id("ContributorType"))).selectByVisibleText(contributorType);
driver.findElement(By.id("Address1")).clear();
driver.findElement(By.id("Address1")).sendKeys(add1);
driver.findElement(By.id("City")).clear();
driver.findElement(By.id("City")).sendKeys(city);
new Select(driver.findElement(By.id("USStates"))).selectByVisibleText(state);
driver.findElement(By.id("ZipCode")).clear();
driver.findElement(By.id("ZipCode")).sendKeys(zip);
driver.findElement(By.xpath("//div[@id='codeRefer']/table/tbody/tr[16]/td[2]/p/label/span")).click();
driver.findElement(By.id("IsContributionNonCashYes")).click();
driver.findElement(By.id("GrantTotalContribution")).clear();
driver.findElement(By.id("GrantTotalContribution")).sendKeys(amount);
driver.findElement(By.id("btnAddAnother")).click();
// Ends
}
Upvotes: 0
Views: 2417
Reputation: 3625
You get NullPointerException
because your pointer - driver
is created in method launchBrowser()
.
If you want to use pointer driver
in both methods, you have to set it as instance variable.
Example:
public class Example {
Webdriver driver; //instance variable - available for all methods in this class
@BeforeTest
public void launchBrowser() {
driver = new Chromedriver();
}
}
Hope it helps!
Upvotes: 2