0

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

消息在屏幕上停留几秒钟,然后消失。恐怕这对于 Katalon 之类的方法来说太快了'WebUI.verifyElementPresent()'。还有其他方法可以用Katalon Studioor捕捉它Selenium吗?

4

2 回答 2

2

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

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') )
于 2018-03-01T10:34:17.250 回答
-2

我找到了一种捕获noty消息的方法,也如此所述。

这是我的代码:

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

这个方法被同一个类的另一个方法调用:

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)
    }
}
于 2018-12-19T08:51:02.903 回答