How to Capture Screenshots of Web Elements for Image-based Testing


This is a companion discussion topic for the original entry at https://docs.katalon.com/katalon-studio/docs/web-image-based-object-recognition.html

Looks really interesting but does path have to be absolute? The location shown in the screenshot points to the Dev’s personal folder and will break when anybody else runs it.

@ThanhTo (not sure if you are the right person to tag)

I am also curious on the absolute path question @Dan_Bown posted but with a little twist. How does this function/work for someone who is using TestOps and running on remote devices? Does the file need to be stored somewhere remote? or does it upload with the repo when it goes to TestOps?

Thanks in advanced!

  • Sha

@Dan_Bown @shahin.fard

Yes the path must be absolute, since the underlying mechanism doesn’t assume that the image must be inside your Katalon project.

You can utilize Test Object Parameterization to pass the path to the current project inside the Test Object.

Example:

TestObject to = findTestObject('test', ['screenshot' : RunConfiguration.getProjectDir() ])

println(to.getActiveProperties().get(0).getValue().toString())

Console:

2020-04-15 11:35:38.608 DEBUG testcase.New Test Case                   - 2: println(getValue().toString())
/Users/thanhto/Katalon Studio/Test projects/MyProject/image/yourimage.jpg
Test Cases/New Test Case

The screenshot property will then be used by the image recognition algorithm to retrieve the image.

Please try and let me know if it works, or if your use case demands something more.

3 Likes

Hi all.

We incorporated this to a new Self-healing feature in 7.6.

Specifically relevant to this thread, now you can specify relative path of the image.