Skip to content

Commit

Permalink
Debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
aaltat committed Feb 7, 2024
1 parent 0fa55fd commit 574df72
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
31 changes: 29 additions & 2 deletions atest/library/screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,32 @@ def compare_images(img1_path: str, img2_bytes: bytes):
html=True,
)
box = diff.getbbox()
logger.info(box)
assert box is None
if isinstance(box, tuple):
logger.warn(f"box: {box}, type({type(box)}), but no idea why this fails.")
raise ValueError(f"Diff is not correct.")
elif box is None:
logger.info("No diff found, all good")
return True
raise ValueError(f"Diff is not correct.")


def compare_images_2(img1_path: str, img2_path: str):
"""Returns True if the images are the same, False otherwise"""
im1: Image.Image = Image.open(img1_path).convert('RGB')
im2: Image.Image = Image.open(img2_path).convert('RGB')
for im1_pix, im2_pix in zip(im1.getdata(), im2.getdata()):
if im1_pix != im2_pix:
logger.info(im1_pix)
logger.info(im2_pix)
diff: Image.Image = ImageChops.difference(im1, im2)
buffered = BytesIO()
diff.save(buffered, format="PNG")
img_str = base64.b64encode(buffered.getvalue()).decode()
logger.info(
'</td></tr><tr><td colspan="3">'
'<img alt="screenshot" class="robot-seleniumlibrary-screenshot" '
f'src="data:image/png;base64,{img_str}" width="900px">',
html=True,
)
box = diff.getbbox()
assert box is None, f"diff is not None"
13 changes: 9 additions & 4 deletions atest/test/02_Content_Keywords/screenshot.robot
Original file line number Diff line number Diff line change
Expand Up @@ -194,26 +194,31 @@ Screenshot With Omit Background
[Teardown] Remove File ${path}

Screenshot Returns Base64 And Path
New Page ${ELEMENT_STATE_URL}
${path} = Take Screenshot return_as=path
${base64} = Take Screenshot return_as=base64
Type Text id=username_field Hello
${path2} = Take Screenshot return_as=path
Log </td></tr><tr><td colspan="3"><img alt="screenshot" src="data:image/png;base64,${base64}" width="900px"/> html=True
Type Text [name="enabled_input"] Hello
${base64_diff} = Take Screenshot return_as=base64
Should Be True isinstance($path, pathlib.Path)
${bytes} = Evaluate base64.b64decode($base64)
Compare Images 2 ${path.absolute().resolve()} ${path2.absolute().resolve()}
Compare Images ${path.absolute().resolve()} ${bytes}
Should Not Be Equal ${base64} ${base64_diff}
${bytes_diff} = Evaluate base64.b64decode($base64_diff)
TRY
Compare Images ${path} ${bytes_diff}
Fail Should have failed
EXCEPT AssertionError
EXCEPT ValueError* type=glob
Log correct error
END

Screenshot Returns Bytes And Path String
New Page ${ELEMENT_STATE_URL}
${path} = Take Screenshot return_as=path_string
${bytes} = Take Screenshot return_as=bytes
Type Text id=username_field Hello
Type Text [name="enabled_input"] Hello
${bytes_diff} = Take Screenshot return_as=bytes
Should Be True isinstance($path, str)
Should Be True isinstance($bytes, bytes)
Expand All @@ -222,6 +227,6 @@ Screenshot Returns Bytes And Path String
TRY
Compare Images ${path} ${bytes_diff}
Fail Should have failed
EXCEPT AssertionError
EXCEPT ValueError* type=glob
Log correct error
END

0 comments on commit 574df72

Please sign in to comment.