I am in the process of automating a set of manual tests on a website.
As the website is still in the process of being developed and tested, it is constantly under change. Therefore, my idea is to create a standard set of 'master' tests that are used in most (if not all) tests, that I can call from other tests and that can be easily changed where necessary.
I have created a package called 'Master', containing two classes called 'Login' and 'Logout'. I have created another package called 'SmokeTests', containing a class called 'Smoke003'.
The Login script runs successfully when I call it from Smoke003 however, I cannot seem to write/run the Logout script successfully.
Please see below my code for the 3 different classes:
Login:
package Master;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import static junit.framework.TestCase.assertEquals;
public class Login {
static WebDriver driver;
@Test
public void testLogin(){
String loginname1 = "EMAIL HERE";
String password1 = "PASSWORD HERE";
driver = new FirefoxDriver();
driver.get("WEBSITE HERE");
driver.findElement(By.id("LoginButton")).click();
driver.findElement(By.id("loginEmail")).sendKeys(loginname1);
driver.findElement(By.id("loginPassword")).sendKeys(password1);
driver.findElement(By.id("loginOKButton")).click();
new WebDriverWait(driver,5).until(ExpectedConditions.textToBePresentInElementLocated(By.className("underline"),"Events"));
assertEquals("TEXT HERE",driver.findElement(By.className("TEXT HERE")).getText(),"TEXT HERE");
}
}
Logout:
package Master;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class Logout {
static WebDriver driver;
@Test
public void testLogout(){
driver.findElement(By.cssSelector("TEXT HERE")).click();
}
}
SMOKE003:
package SmokeTests;
import Master.Login;
import Master.Logout;
import org.junit.Test;
public class Smoke_003 {
public static void main(String args[]) {
Login Login01 = new Login();
Login01.testLogin();
Logout Logout01 = new Logout();
Logout01.testLogout();
}
Is anybody please able to help with why I keep receiving the error message 'java.lang.NullPointerException' when running/debugging the logout test? I am aware that there is no driver.get website specified in the Logout script. I don't believe I need to do this as by the time I come to logout I will already be logged in?
NOTE: I have edited some information such as email address etc. for confidentiality reasons.
UPDATE: If I run Smoke003, it calls the login script and logs in successfully but fails when trying to call the logout script with the following error message in full:
Exception in thread "main" java.lang.NullPointerException
at Master.Logout.testLogout(Logout.java:14)
at SmokeTests.Smoke_003.main(Smoke_003.java:14)
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:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)