Catching jQuery noty with Katalon Studio

依然范特西╮ 提交于 2020-01-06 06:18:11

问题


My AUT has a jQuery "noty" that appears after clicking on a button. ("Noty" is a jQuery plugin for message/notification creation.)

The message stays on screen for a couple of seconds and then goes away. I'm afraid that's to fast for methods such as Katalon's 'WebUI.verifyElementPresent()'. Is there another way to catch it with Katalon Studio or Selenium?


回答1:


Yes, there is a way to handle this situation:

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:


I found a way to catch the noty messages, as described also here.

Here's my code:

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

This method gets called from another method of the same class:

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


来源:https://stackoverflow.com/questions/49027653/catching-jquery-noty-with-katalon-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!