I am trying to set some elements on the @BeforeClass section but. But I am getting null pointer exception.
public class Error: TestNG @BeforeClass initialization code not running before Test
RunTest {
private static WebElement user;
private static WebElement pass;
private static WebElement login;
@BeforeClass
public static void driveraBaglan() {
//Driver is declared here. I removed it to give the simple code.
user = driver.findElement(By.id("user"));
pass = driver.findElement(By.id("pass"));
login = driver.findElement(By.xpath("//button[contains(.,'Log In')]"));
statusMessage = driver.findElement(By.id("login-status-message")).getText();
}
@Test(priority=1)
public void loginNoInfo() {
user.clear();
pass.clear();
}
I get the null pointer error on user.clear() , pass.clear() and login.click() functions. Please help to resolve it.