首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Katalon Studio捕获jQuery noty

使用Katalon Studio捕获jQuery noty
EN

Stack Overflow用户
提问于 2018-02-28 18:45:34
回答 2查看 122关注 0票数 0

我的AUT有一个jQuery "noty“,它在点击一个按钮后出现。("Noty“是一个用于创建消息/通知的jQuery插件。)

消息会在屏幕上停留几秒钟,然后消失。我担心这对于Katalon的'WebUI.verifyElementPresent()'这样的方法来说太快了。有没有其他方法可以用Katalon StudioSelenium捕获它?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-12-19 16:51:03

我找到了一种捕获noty消息的方法,正如here所描述的那样。

下面是我的代码:

代码语言:javascript
运行
复制
import ru.yandex.qatools.ashot.AShot
import ru.yandex.qatools.ashot.Screenshot
import ru.yandex.qatools.ashot.coordinates.*
import ru.yandex.qatools.ashot.cropper.*

public class ScreenshotHelper {

  public void takeWebElementScreenshot(TestObject object) {
        WebElement element = WebUiCommonHelper.findWebElement(object, 20)
        WebDriver driver = DriverFactory.getWebDriver();
        String fileName = new SimpleDateFormat("yyyyMMddHHmmSSS").format(new Date())
        Screenshot screenshot = new AShot().takeScreenshot(driver, element)
        try {
            if (DriverFactory.getExecutedBrowser().getName()=='HEADLESS_DRIVER'){
            ImageIO.write(screenshot.getImage(),'PNG', new File("C:/Users/path_to_working_directory/ErrorScreenshots/HeadlessElementScreenshot"+"_"+fileName+".png"))
            } else {
            ImageIO.write(screenshot.getImage(),'PNG', new File(System.getProperty("user.dir")+"/ErrorScreenshots/ElementScreenshot"+"_"+fileName+".png"))
            }
        } catch (Exception e) {
            e.printStackTrace()
        }
        }
}

此方法从同一类的另一个方法中调用:

代码语言:javascript
运行
复制
public void catchNotyMessage(){

    TestObject noty_warning = new TestObject().addProperty('css', ConditionType.EQUALS, "div.noty_type_warning")
    TestObject noty_error = new TestObject().addProperty('css', ConditionType.EQUALS, "div.noty_type_error")

    if (WebUI.verifyElementPresent(noty_error, 1, FailureHandling.OPTIONAL)){
        this.takeWebElementScreenshot(noty_error)
    }
    else if (WebUI.verifyElementPresent(noty_warning, 1, FailureHandling.OPTIONAL)){
        this.takeWebElementScreenshot(noty_warning)
    }
}
票数 -2
EN

Stack Overflow用户

发布于 2018-03-01 18:34:17

是的,有一种方法可以处理这种情况:

代码语言:javascript
运行
复制
import org.openqa.selenium.support.ui.WebDriverWait as WebDriverWait

WebDriverWait wait = new WebDriverWait(driver, 20)

wait.until(ExpectedConditions.stalenessOf('your noty WebElement that you have to identify before') )
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49027653

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档