我的AUT有一个jQuery" noty"单击按钮后出现。 (" Noty"是一个用于创建消息/通知的jQuery插件。)
消息在屏幕上停留几秒钟然后消失。我担心像Katalon 'WebUI.verifyElementPresent()'
这样的方法会加速。还有另一种方法可以通过Katalon Studio
或Selenium
来抓住它吗?
答案 0 :(得分: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') )
答案 1 :(得分:-2)
我找到了一种捕获noty
消息的方法,也here所述。
这是我的代码:
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)
}
}