I am writing test codes with Selenium, TestNG, JUnit. I am trying to set some elements on the @BeforeClass section as I am repeating those actions on the same page. But I am getting null pointer exception. Is there a way to fix this issue?
@BeforeClass
public static void driveraBaglan() {
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
//Wait for an object appear on the web site. And also page load time
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
//Visit the web site
driver.get("http://webmail.likya.net");
//Set web elements
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)
//Checks error message on both user name and password left empty
public void loginNoInfo() {
//Clearing the username and password area in case we use it in another scenario
user.clear();
pass.clear();
//Clicking Log In button and check if error message appears on the page
login.click();
Assert.assertEquals(statusMessage, "Oturum açmak için bir kullanıcı adı belirtmelisiniz.", "Kullanıcı adı ve şifre boş kontrolü hatalı");
}
I get the null pointer error on user.clear() , pass.clear() and login.click() functions
Aucun commentaire:
Enregistrer un commentaire