Search code examples
seleniumautomated-testskatalon-studionoty

Catching jQuery noty with Katalon Studio


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?


Solution

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