0

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?

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77

2 Answers2

2

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') )
JanZ
  • 584
  • 2
  • 13
-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)
    }
}
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77