简体   繁体   中英

How can I use wait condition?

First I have uploaded one image and then i made assertion to check my image get uplaoded or not in the same program itself.For that assertion ,I have defined following coding,but it throws the following error message as Failed tests:Timed out after 10 seconds waiting for presence of element located by: By.id: brand.How can i dynamically upload and check that the uploaded image has been present or not.

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());

You can start a new thread and run a timer in it. It would be easy to make but probably not the best solution.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM