我编写了两个功能文件,每个功能文件打开不同的浏览器url,例如一个是open google.com,另一个是open amazon.com,但事实并非如此。
两种浏览器都会打开google.com。此外,它不能与浏览器交互,任何编码到浏览器的操作都不会执行。此外,关闭第一个浏览器会导致第二个浏览器出现空指针异常。
CucumberVersion6我从abstractcucumbertesng继承开始。然后我创建login.feature,然后是addproduct.feature。
预期的行为应该是一个浏览器打开phptravels.net网站,另一个浏览器打开http://sellerceter.lazada.my.
我目前的情况并非如此,在关闭一个浏览器后,它用phptravels.net打开了两个浏览器,然后打开了seller.lazada网站。
public class AddProduct {
private WebDriverWait timeWait;
private AddProductPageObject page;
private ChromeDriver driver;
private Logger log = LogManager.getLogger(AddProduct.class);
// ======================================================================
public AddProduct() {
}
@Given("navigate to manage product")
public void navigateToManageProduct() {
log.info("Start Login");
try {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
this.timeWait = new WebDriverWait(driver, 30);
page = PageFactory.initElements(driver, AddProductPageObject.class);
driver.navigate().to("https://sellercenter.lazada.com.my/apps/seller/login");
timeWait.until(ExpectedConditions.visibilityOfElementLocated(page.getLazadaSellerLogo()));
// Input username
driver.findElement(page.getUsername()).click();
driver.findElement(page.getUsername()).clear();
driver.findElement(page.getUsername()).sendKeys("nicholaswkc34@gmail.com");
// Input password
driver.findElement(page.getPassword()).click();
driver.findElement(page.getPassword()).clear();
driver.findElement(page.getPassword()).sendKeys("wlx_+279295");
// Click submit btn
driver.findElement(page.getSignInButton()).click();
//assertThat(page.getPageTitle())
Wait wait = new Wait();
wait.implicitWait(driver, 5);
} catch (Exception e) {
log.error(e);
}
}
}
公共类登录{
private WebDriverWait timeWait;
private LoginPageObject page;
private ChromeDriver driver;
private Logger log = LogManager.getLogger(Login_FE.class);
// ======================================================================
public Login_FE() {
}
@Given("Launch the homepage and login")
public void launchTheHomepageAndLogin() {
log.info("Start Login");
try {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
timeWait = new WebDriverWait(driver, 30);
// Instantiate LoginPageObject
page = PageFactory.initElements(driver, LoginPageObject.class);
log.info("Navigate to phptravels homepage");
driver.navigate().to("https://www.phptravels.net/admin");
timeWait.until(ExpectedConditions.visibilityOfElementLocated(page.getPhpLogo()));
Actions inputAct = new Actions(driver);
inputAct.sendKeys("admin@phptravels.com").perform();
driver.findElement(page.getUsername()).sendKeys("admin@phptravels.com");
Wait wait = new Wait();
wait.implicitWait(driver, 3);
}catch(Exception e) {
log.error(e);
}
log.info("Login Successfully");
}
}
暂无答案!
目前还没有任何答案,快来回答吧!