0

首先我上传了一张图片,然后我断言检查我的图片是否在同一个程序中被上传。对于该断言,我定义了以下编码,但它抛出以下错误消息作为失败测试:10 后超时等待元素存在的秒数:By.id:brand.How 我可以动态上传并检查上传的图像是否存在。

WebDriverWait wdw = new WebDriverWait(driver, 40);
ExpectedCondition<Boolean> condition = new ExpectedCondition<Boolean>() {
    public Boolean apply(WebDriver d) {
        WebElement imageIcon = d.findElement(By.id("brand"));
        return "Image".equals(imageIcon.isDisplayed());
    }
};
wdw.until(condition);

//Check if Image has been uploaded
WebElement imageIcon = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("brand")));
Assert.assertTrue(imageIcon.isDisplayed());
4

1 回答 1

0

您可以启动一个新线程并在其中运行一个计时器。这很容易制作,但可能不是最好的解决方案。

long timestamp = System.currentTimeMillis();
new Thread(new Runnable() {
    public void run() {
    if(System.currentTimeMillis()-timestamp > 10000){
        //The 10 seconds passed. You can have some message in here.
        //Also a boolean to keep track if it was successful.
        return;//stops the thread
    }
}).start();
于 2015-01-12T13:11:39.190 回答