我试图使我的显式等待工作从页面模型类到测试用例类。我试图将我的显式等待对象放入方法中,并从似乎无法正常工作的测试用例中调用它。当然,如果我做了Thread.sleep
,我的代码就可以正常工作。我该如何解决?
这是我的页面对象模型类:
package pageObjects;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class TTPCartPage {
WebDriver driver;
public TTPCartPage(WebDriver driver) {
this.driver = driver;
}
By delete = By.cssSelector("a.remove");
By shipping_calculator = By.className("shipping-calculator-button");
By state_button = By.id("select2-calc_shipping_state-container");
By shipping_state = By.className("select2-search__field");
By shipping_city = By.id("calc_shipping_city");
By shipping_zip = By.id("calc_shipping_postcode");
By update_button = By.cssSelector("button[name='calc_shipping']");
By checkout = By.cssSelector("a.checkout-button");
public WebElement removeItem() {
return driver.findElement(delete);
}
public WebElement calculateShipping() {
return driver.findElement(shipping_calculator);
}
public WebElement stateButton() {
return driver.findElement(state_button);
}
public WebElement stateInput() {
return driver.findElement(shipping_state);
}
public WebElement cityInput() {
return driver.findElement(shipping_city);
}
public WebElement zipInput() {
return driver.findElement(shipping_zip);
}
public WebElement updateShipping() {
return driver.findElement(update_button);
}
public WebElement checkoutItem() {
return driver.findElement(checkout);
}
// The problem child.
public WebElement explicitWait() {
WebDriverWait w=new WebDriverWait(driver,3);
return w.until(ExpectedConditions.visibilityOfElementLocated(checkout));
}
}
我在这里存储测试用例:
package SimpleProgrammer;
import java.io.IOException;
import org.openqa.selenium.Keys;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import resources.Base;
import pageObjects.TTPCartPage;
import pageObjects.TTPProductPage;
import pageObjects.TTPStorePage;
public class PurchaseApplication extends Base {
@Test(dataProvider="getData")
public void BuyItem(String Size, String Amount) throws IOException {
driver=initializeDriver();
driver.get("https://simpleprogrammer.com/store/products/trust-the-process-t-shirt/");
TTPProductPage pp= new TTPProductPage(driver);
pp.TTPButton().click();
TTPStorePage sp = new TTPStorePage(driver);
sp.selectSize(Size);
sp.quantityItem().clear();
sp.quantityItem().sendKeys(Amount);
sp.submitButton().click();
sp.cartContents().click();
TTPCartPage cp = new TTPCartPage(driver);
cp.calculateShipping().click();
cp.stateButton().click();
cp.stateInput().sendKeys("Colorado");
cp.stateInput().sendKeys(Keys.ENTER);
cp.cityInput().sendKeys("Lakewood");
cp.zipInput().sendKeys("80214");
cp.updateShipping().click();
// Right here.
cp.explicitWait();
cp.checkoutItem().click();
}
@DataProvider
public Object[][] getData() {
Object[][] data = new Object[1][2];
data[0][0] = "M";
data[0][1] = "2";
return data;
}
}
这是我收到的错误消息:
FAILED: BuyItem("M", "2")
org.openqa.selenium.WebDriverException: unknown error: Element <a href="https://simpleprogrammer.com/store/checkout/" class="checkout-button button alt wc-forward">...</a> is not clickable at point (728, 544). Other element would receive the click: <div class="blockUI blockOverlay" style="z-index: 1000; border: none; margin: 0px; padding: 0px; width: 100%; height: 100%; top: 0px; left: 0px; background: rgb(255, 255, 255); opacity: 0.6; cursor: wait; position: absolute;"></div>
(Session info: chrome=73.0.3683.103)