A NullPointerException means that one of the variables you are passing is null, but the code tries to use it like it is not.
[quote:1xwv71oi]If I don't use annotations then I am not getting error.
[/quote:1xwv71oi]
which annotations?
paste entire exception i could not understand the problem and also upload the screen shot.
Here is the whole code :
package com.testing;
import org.testng.annotations.Test;
import com.util.Constants;
import org.testng.annotations.DataProvider;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.BeforeSuite;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.AfterSuite;
public class Connection {
public String appURL = "http://eqtestapp01.ecc.com/";
WebDriver driver = null;
@FindBy(id="loginText")
public WebElement username;
@FindBy(id="pwdText")
public WebElement password;
@FindBy(xpath=Constants.login)
public WebElement Login;
@FindBy(xpath=Constants.Cont)
public WebElement Continue;
@FindBy(xpath=Constants.region)
public WebElement Region;
private String browser;
@Test(dataProvider = "dologin")
public void LoginAs(String nUser, String nPass) {
username.sendKeys(nUser);
password.sendKeys(nPass);
System.out.println(nPass);
Login.click();
//PrePay pp = PageFactory.initElements(driver, PrePay.class );
//pp.getPrePayment();
}
@DataProvider
public Object[][] dologin() {
return new Object[][]{
new Object[]{"rjunnarkar", "abcd"}
};
}
@BeforeTest
public void beforeTest() {
System.out.println("Inside the BeforeTest");
}
@BeforeSuite
public void beforeSuite() {
browser = "Mozilla";
System.out.println(browser);
if(browser.equals("Mozilla"))
driver = new FirefoxDriver();
else if(browser.equals("IE"))
driver = new InternetExplorerDriver();
else if(browser.equals("Chrome")){
driver= new ChromeDriver();
}
System.out.println("Dont give error");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get(appURL);
}
@AfterSuite
public void afterSuite() {
if(driver!=null){
driver.quit();
System.out.println("Bye Bye");
//driver=null;
}
}
}
Getting error in following lines.
username.sendKeys(nUser);
password.sendKeys(nPass);
nuser and npass are empty.
that is why it is giving a null pointer exception.
they're not getting the data from data provider please check them.