image comparison fails

Asked by Felix

Hi,

I'm struggling with sikulis image matching possibilities. I'm testing if a website loaded correctly. The test fails if a blank page shows up.

1) First approach:
Look into screen region and test if blank_page.png (1021x672 pixel) exists.

    #screen region // screen size ipad
    screenRegion = Region(1,43,1020,804)

    #create match object
    imageBlank = Pattern("blank_page.png")

    if screenRegion.exists(imageBlank):
        print "debug: blank screen, website failed to load correctly"
    else:
        print "ok"

2) Second approach:
Make a screenshot of the website and test if it's blank.

    screenRegion = Region(1,43,1020,804)

    imageScreenRaw = capture(screenRegion)

    #match object
    imageScreen = exists(imageScreenRaw)

    #region from screenshot
    imageScreenRegion = Region(imageScreen)

    imageBlank = Pattern("blank_page.png")

    if imageScreenRegion.exists(imageBlank):
        print "debug: blank screen, website failed to load correctly"
    else:
        print "ok"

The blank screen differs a 100% from the region or captured sreenshot, but both test approaches fail unfortunately. What's wrong? Does it matter if I test against a 10x10 blank png or a 1021x672 pixel?

Any help on this issue is highly appreciated. Thanks in advance for sharing your experience.

regards

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
TestMechanic (ndinev) said :
#1

I just done simple test on https://launchpad.net/sikuli with to see how recorded image is recognized. it works fine with exception that it is relatively slow on my 21" widescreen.

But in general i think the approach of validating if web site is loaded is not correct. I would suggest following

-- On the site homepage take 2 - 3 major elements that should be present. They may be ones that you will use afterwards anyway. Search for them

-- Copy the whole content of the page by clicking in the middle and doing ctrl-a-c. The using the power of python check that some expected texts are there and some unexpected are not there(like "exception" and "error")

I believe that above approach is more reliable since it will tolerate significant changes in website layout.

Hope this helps

Revision history for this message
RaiMan (raimund-hocke) said :
#2

does blank_page.png mean a totally white (or uni-color) area?

If yes: this is problematic (but should work with latest version r930).

Another thing:

Look into screen region and test if blank_page.png (1021x672 pixel) exists.

    #screen region // screen size ipad
    screenRegion = Region(1,43,1020,804)

Since the image is 1 pixel wider than the region, this will never be found.

Revision history for this message
Felix (felix2stoll) said :
#3

Thanks for your replies,

@dinev
I thought about taking visual elements of the website and validate against them, but I'm looking for a more general approach so I can easily change the tested websites without touching the sikuli script.

@raiman
You're right, by blank page I mean a totally white (uni-color) are, e.g. you type about:blank in your browser's address bar and hit enter. I'm going to give r930 a try.

What do you think? Which approach should I take? Which is one is more stable in terms of correct image comparision results?

thanks in advance

regards

Revision history for this message
RaiMan (raimund-hocke) said :
#4

--- but I'm looking for a more general approach so I can easily change the tested websites without touching the sikuli script.
Generally this is a good idea, but my (and other people's) experiences tell me, that this is usually combined with a huge scripting effort.
I think each Sikuli script will have some specifics about the images used (different browsers, resolutions, systems, ... ) that lead to different versions of the same script.
The only thing one should do: identify often used workflows and turn them in classes/methods/functions, that can be reused.

--- Which is one is more stable in terms of correct image comparision results?
I agree (and usually use) dinev's approach: looking for some key visuals, that should be there, to be sure, the workflow might proceed.
You might put this check in a function or functions, that accept some parameters (list of images, expected regions, combination logic, ...)

examples:

checkAll(images, reg = SCREEN):
    ret = True
    for image in images:
        if not reg.exists(image, 0):
            ret = False
            break
    return ret

checkSome(images, reg = SCREEN):
    ret = False
    for image in images:
        if reg.exists(image, 0):
            ret = True
            break
    return ret

usage:

browser = App("your browser")
if not checkAll( ("image1.png", "image2.png", "image3.png" ), browserApp.window() ):
     print "makes no sense to go on"; exit(1)

Revision history for this message
RaiMan (raimund-hocke) said :
#5

You could even use this approach, to check wether some white area is contained in the browser window.

Can you help with this problem?

Provide an answer of your own, or ask Felix for more information if necessary.

To post a message you must log in.