我的AUT有一个jQuery "noty“,它在点击一个按钮后出现。("Noty“是一个用于创建消息/通知的jQuery插件。)
消息会在屏幕上停留几秒钟,然后消失。我担心这对于Katalon的'WebUI.verifyElementPresent()'这样的方法来说太快了。有没有其他方法可以用Katalon Studio或Selenium捕获它?
发布于 2018-12-19 16:51:03
我找到了一种捕获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)
}
}发布于 2018-03-01 18:34:17
是的,有一种方法可以处理这种情况:
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') )https://stackoverflow.com/questions/49027653
复制相似问题