Я новичок на форуме. Извините, если вопрос слишком длинный. Я вставил четыре файла. Два файла класса являются файлами PageObject. Один файл является тестовым, а другой предназначен для инициализации WebDriver.
Я получаю исключение нулевого указателя при запуске файла проверки входа.
//Первая страница
package com.base.pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.testng.Reporter;
public class ActitimeLoginPage {
protected WebDriver driver;
public ActitimeLoginPage(WebDriver driver){
PageFactory.initElements(driver, this);
}
@FindBy(xpath="//input [@ name = 'username']")
public WebElement txtusername;
@FindBy(xpath="//input[@type='password']")
public WebElement txtpassword;
@FindBy(xpath="//input[@type='submit']")
public WebElement btnLogin;
@FindBy(xpath="//table[1]/tbody/tr[7]/td[3]")
public WebElement versionnumber;
@FindBy(xpath="//a[@href='http://www.actimind.com']")
public WebElement actimindlink;
public Opentaskpage login(String username, String password){
txtusername.sendKeys(username);
Reporter.log("Entered Username",true);
txtpassword.sendKeys(password);
Reporter.log("Entered password",true);
btnLogin.click();
Reporter.log("clicked on login",true);
return new Opentaskpage(driver);
}
}
//Вторая страница
package com.base.pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.testng.Reporter;
public class Opentaskpage {
protected WebDriver driver;
public Opentaskpage(WebDriver driver){
PageFactory.initElements(driver, this);
}
@FindBy(xpath="//td[contains(text(),'Open Tasks')]")
public WebElement Heading;
@FindBy(xpath="/login.do?logout=1")
public WebElement btnLogout;
public void Logout(){
btnLogout.click();
Reporter.log("Clicked on logout",true);
//return new ActitimeLoginPage(this.driver);
}
}
//Файл предварительного условия
package com.base.generic;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
public class SuperTestNg {
public WebDriver driver = new FirefoxDriver();
@BeforeMethod
public void precondtion(){
driver.get("http://indbrnb0033/login.do");
driver.manage().window().maximize();
}
@AfterMethod
public void postcondtion(){
driver.close();
}
}
// Тестовый файл
package com.Acti.Tests;
import org.testng.annotations.Test;
import com.base.generic.SuperTestNg;
import com.base.pages.ActitimeLoginPage;
import com.base.pages.Opentaskpage;
public class Login extends SuperTestNg {
@Test
public void Test_Login(){
ActitimeLoginPage page = new ActitimeLoginPage(driver);
Opentaskpage page2 = page.login("admin", "manager");
page2.Logout();
}
}
Я не знаю, как именно сформулировать вопрос. Метод первой страницы возвращает конструктор, и я не могу инициализировать вторую страницу.
Пожалуйста, помогите, если я делаю что-то не так, или покажите мне лучший способ следовать. Заранее спасибо.
Я получаю сообщение об ошибке:
Exception in thread "main" java.lang.NullPointerException
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at com.sun.proxy.$Proxy2.click(Unknown Source)
at com.actitime.OpentaskPage.clicklogout(OpentaskPage.java:20)
at com.actitime.ActitileLogin_Test.main(ActitileLogin_Test.java:27)