Pir*_*aba 0 java selenium selenium-webdriver
新的硒
我有一个基类,它将启动webdriver.以下页面可用于创建合同.
登录 - >选择计划 - >添加房屋 - >添加详细信息
public class BaseClass {
public WebDriver driver;
public WebDriverWait wait;
public WebDriver getDriver() {
return driver;
}
@BeforeClass(description = "Class Level Setup!")
public void setup() {
// Create a Chrome driver. All test classes use this.
System.setProperty("webdriver.chrome.driver", "/Selenium/chromedriver");
driver = new ChromeDriver();
// Create a wait. All test classes use this.
wait = new WebDriverWait(driver, 15);
// Maximize Window
driver.manage().window().maximize();
}
}
Run Code Online (Sandbox Code Playgroud)
和Login.Test
public class LoginTest extends BaseClass {
@Test(priority = 0, description="This TC is for Senoko login")
void validateLogin() {
driver.get("https://url domain/index");
WebElement email = driver.findElement(By.id("userid_txt"));
WebElement password = driver.findElement(By.id("password_txt"));
WebElement login = driver.findElement(By.id("submitBtn"));
email.sendKeys("a01");
password.sendKeys("test123");
login.click();
HouseholdCheck house=new HouseholdCheck();
house.houseCheck();
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止工作.在validateLogin()方法中,调用houseCheck方法,我在这里得到NullPointerException.
public class HouseholdCheck extends BaseClass {
@Test
void houseCheck() {
System.out.println("=====" + driver);
driver.get("https://a-sit.aspx?source=CSP&key=1");
WebElement radio1 = driver.findElement(By.xpath("//input[@name='resbiz' and @value='households']"));
WebElement radio2 = driver.findElement(By.xpath("//input[@name='resbiz' and @value='business']"));
radio1.click();
WebElement radbutton = driver.findElement(By.xpath("//button[contains(.,'Continue')]"));
radbutton.click();
PlanSelect plnslct = new PlanSelect();
plnslct.planSelect(driver);
}
Run Code Online (Sandbox Code Playgroud)
}
在HouseholdCheck课堂上,无法访问driver.给予NullPointerException.请指导我,如何将驱动程序传递给后续课程?如果一个类扩展BaseClass,为什么该类无法获取驱动对象?
在HouseholdCheck house = new HouseholdCheck();你创建新的实例BaseClass,driver从未初始化.您调用houseCheck()方法而不是将其作为测试运行,因此setup()未执行.
一种解决方案是制造driver静电
private static WebDriver driver;
public static WebDriver getDriver() {
return driver;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
51 次 |
| 最近记录: |