Can somebody, please, help me to figure out what is wrong with my test? I'm getting that NullPointerException error in Eclipse all the time.
MyTestcase:
public class ExampleTest extends Basetest {
private LoginPage loginPage;
private DashboardPage homePage;
@Before
public void setUp() throws Exception {
loginPage =new LoginPage(driver);
homePage = new DashboardPage (driver);
}
@After
public void tearDown() throws Exception {
}
@Test
public void test() {
loginPage.load();
loginPage.login();
homePage.getWelcomeMessage();
String actualWelcome=homePage.getWelcomeMessage();
assertEquals("Welcome Admin",actualWelcome);
homePage.logout();
}
}
BasPage: public class BasePage {
public WebDriver driver;
public WebDriverWait wait;
public String pageUrl= "http:/hrm.seleniumminutes.com";
public BasePage(WebDriver driver) {
this.driver=driver;
wait = new WebDriverWait(driver, 5);
}
public void load () {
driver.get(pageUrl);
}
}
LoginPage:
public class LoginPage extends BasePage {
public LoginPage(WebDriver driver) {
super(driver);
}
public void login() {
// TODO Auto-generated method stub
driver.findElement(By.id("txtUsername")).sendKeys("admin");;
driver.findElement(By.id("txtPassword")).sendKeys("Password");;
driver.findElement(By.id("btnLogin")).click();;
}
}
DashBoardPage:
public class DashboardPage extends BasePage {
public DashboardPage(WebDriver driver) {
super(driver);
// TODO Auto-generated constructor stub
}
public String getWelcomeMessage() {
return wait.until(ExpectedConditions.presenceOfElementLocated(
By.id("welcome"))).getText();
}
public void logout() {
wait.until(ExpectedConditions.visibilityOfElementLocated(
By.linkText("Logout"))).click();
}
}
BaseTest:
public class Basetest {
protected WebDriver driver;
protected WebDriverWait wait;
@Before
public void setUp() throws Exception {
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
driver = new FirefoxDriver();
wait=new WebDriverWait(driver, 5);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@After
public void basetearDown() throws Exception {
driver.quit();
}}