我有3个类如下,但是当我尝试运行测试时,我得到NullPointer(TestPage-> input1)。在调试时我发现我有第二个驱动程序,它是null。任何人都可以帮助我做错了什么以及如何解决它?它不应该正常工作吗?
public class BaseScenario {
protected WebDriver driver;
@BeforeMethod
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Ed\\Desktop\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://toolsqa.com/automation-practice-form/");
}
@AfterMethod
public void TearDown() {
driver.quit();
}
}
public class TestsPage {
WebDriver driver;
public TestsPage(WebDriver driver)
{
this.driver=driver;
}
public void input1(){
driver.findElement(By.xpath("//*[@id='content']/form/fieldset/div[1]/input[1]")).sendKeys("Kuba");;
}
public WebElement input2(){
WebElement input2 = driver.findElement(By.xpath("//*[@id='content']/form/fieldset/div[1]/input[2]"));
return input2;
}
}
public class Tests extends BaseScenario{
TestsPage pagee = new TestsPage(driver);
@Test
public void TC1() throws Exception {
pagee.input1();
pagee.input2().sendKeys("Chudy");
}
}