Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
marcel-veselka committed Jan 5, 2022
2 parents 91a3d0b + 2d2cddc commit e23fc88
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 47 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,10 @@ jobs:
- name: Run headless test
uses: GabrielBB/[email protected]
with:
run: python3 -m robot tests/unit_test.robot
run: python3 -m robot --outputdir reports tests/unit_test.robot
- name: Upload test results
if: always()
uses: actions/upload-artifact@v2
with:
name: test-result-report
path: reports/*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
### Basic Info

Robot Framework visual testing library for visual difference testing as well as image content testing (including PDF documents).
Runs on Selenium or Playwright to generate screenshots, PyMuPDF to process PDFs and Tesseract OCR to recognize text.
Runs on Selenium or Playwright to generate screenshots, PyMuPDF (supported version `1.19+`) to process PDFs and Tesseract OCR to recognize text.

### Project structure

Expand Down
18 changes: 9 additions & 9 deletions WatchUI/WatchUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import imutils


__version__ = "1.0.11"
__version__ = "1.0.12"


class WatchUI:
Expand Down Expand Up @@ -804,15 +804,15 @@ def pdf_to_image(
if number_page == "-1":
page_count = doc.pageCount
for x in range(0, page_count):
page = doc.loadPage(x) # load all pages one by one
pix = page.getPixmap(matrix=mat)
page = doc.load_page(x) # load all pages one by one
pix = page.get_pixmap(matrix=mat)
output = save_folder + "/" + name + "_" + str(x) + ".png"
pix.writePNG(output)
pix.save(output)
else:
page = doc.loadPage(int(number_page)) # number of page
pix = page.getPixmap(matrix=mat)
page = doc.load_page(int(number_page)) # number of page
pix = page.get_pixmap(matrix=mat)
output = save_folder + "/" + name + ".png"
pix.writePNG(output)
pix.save(output)
else:
raise AssertionError("Path " + path1 + " doesn't exists")

Expand Down Expand Up @@ -869,7 +869,7 @@ def return_text_from_area(
if os.path.exists(path):
doc = fitz.open(path)
page = doc[page_number]
words_list = page.getTextWords()
words_list = page.get_text_words()
text = ""
xy_numbers = 1
for xy in words_list:
Expand Down Expand Up @@ -900,7 +900,7 @@ def should_exist_this_text(path: str, page_number: int, text: str):
if os.path.exists(path):
doc = fitz.open(path)
page = doc[page_number]
text_instances = page.searchFor(text)
text_instances = page.search_for(text)
if len(text_instances) > 0:
return True
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/keywords/CS.robot
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Create screen from actual webpage
Compare image with created screen
Create screen from actual webpage
compare screen ${screen800x600}
compare screen ${screen800x600} save_folder=${CS_SFOUTPUTS}
Compare image full set up
Create screen from actual webpage
Expand Down
2 changes: 1 addition & 1 deletion tests/keywords/CS_2SavedImage.robot
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Documentation Keywords for compare two saved image in pc
*** Keywords ***
Compare 2 same images
compare images ${1IMAGE} ${1IMAGE}
compare images ${1IMAGE} ${1IMAGE} save_folder=${CS2_SFTESENA}
Compare images SSIM 0.5
compare images ${1IMAGE} ${2IMAGE} save_folder=${CS2_SFTESENA} ssim=${SSIM0.5}
Expand Down
4 changes: 2 additions & 2 deletions tests/keywords/CS_region.robot
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Documentation Keyword for comparing screen without some region
Comparing screen without some area: PNG Format
Go to ${CSWA_NEWURL}
create screens 800 600 save_folder=${SF_OOUTPUTS}
compare screen without areas ${screen800x600} @{CSWA_BLACKSQUARE} ssim=${SSIM0.95}
compare screen without areas ${screen800x600} @{CSWA_BLACKSQUARE} save_folder=${SF_OOUTPUTS} ssim=${SSIM0.95}
Comparing screen without some area: JPG Format
Go to ${CSWA_NEWURL}
create screens 800 600 save_folder=${SF_OOUTPUTS}
compare screen without areas ${screen800x600} @{CSWA_BLACKSQUARE} ssim=${SSIM0.95} image_format=jpg
compare screen without areas ${screen800x600} @{CSWA_BLACKSQUARE} save_folder=${SF_OOUTPUTS} ssim=${SSIM0.95} image_format=jpg
20 changes: 9 additions & 11 deletions tests/keywords/Text_testing.robot
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Documentation Keywords for testing text in image
*** Keywords ***
Convert PDF to IMG
pdf to image ${TT_path_to_pdf} name=${TT_name_img} save_folder=../Outputs/
pdf to image ${TT_path_to_pdf} name=${TT_name_img} save_folder=${TT_path}

From IMG to string
${Text_from_area} Image area on text ${TT_path_to_img} @{TT_text_area_coo} psm=10
Expand All @@ -27,15 +27,15 @@ Create and compare vysvetlivky
Check Vysvetlivky

Convert OK PDF to IMG
pdf to image ${OK_PDF} name=${NAME_OK_PDF}
pdf to image ${OK_PDF} name=${NAME_OK_PDF} save_folder=${TT_path}

Convert NOK PDF to IMG
pdf to image ${NOK_PDF} name=${NAME_NOK_PDF}
pdf to image ${NOK_PDF} name=${NAME_NOK_PDF} save_folder=${TT_path}

Find diff in PDF
[Documentation] Test to check that keyword will fail when pictures are different.
... Status of test modified even the kw failed as we are testing it catch difference.
${status}= Run Keyword And Return Status Compare Images ${PATH_TO_OK_IMG} ${PATH_TO_NOK_IMG}
${status}= Run Keyword And Return Status Compare Images ${PATH_TO_OK_IMG} ${PATH_TO_NOK_IMG} save_folder=${PATH_TO_PDF_BASELINE_IMG}
Should Be True '${status}'=='False'

Check words
Expand All @@ -44,17 +44,15 @@ Check words
should be true '''${Text_from_pdf}''' == '''${WHAT_WE_SEARCH} '''

Create Area from Vysvetlivky
pdf to image ${OK_PDF} name=${NAME_VYSVĚTLIVKY_OK_PDF} number_page=7
create area from image @{COO_VYSVĚTLIVEK} ${PATH_TO_VOK_IMG} screen_name=${AREA_VYSVĚTLIVKY_OK_PDF}
pdf to image ${NOK_PDF} name=${NAME_VYSVĚTLIVKY_NOK_PDF} number_page=7
create area from image @{COO_VYSVĚTLIVEK} ${PATH_TO_VNOK_IMG} screen_name=${AREA_VYSVĚTLIVKY_NOK_PDF}
pdf to image ${OK_PDF} name=${NAME_VYSVĚTLIVKY_OK_PDF} save_folder=${TT_path} number_page=7
create area from image @{COO_VYSVĚTLIVEK} ${PATH_TO_VOK_IMG} screen_name=${AREA_VYSVĚTLIVKY_OK_PDF} save_folder=${TT_path}
pdf to image ${NOK_PDF} name=${NAME_VYSVĚTLIVKY_NOK_PDF} save_folder=${TT_path} number_page=7
create area from image @{COO_VYSVĚTLIVEK} ${PATH_TO_VNOK_IMG} screen_name=${AREA_VYSVĚTLIVKY_NOK_PDF} save_folder=${TT_path}

Check Vysvetlivky
Compare Images ${PATH_TO_VOK_AREA} ${PATH_TO_VNOK_AREA}
Compare Images ${PATH_TO_VOK_AREA} ${PATH_TO_VNOK_AREA} save_folder=${PATH_TO_PDF_BASELINE_IMG}

Read text from image
${Text_from_area} Image area on text ${PATH_TO_NOK_IMG} @{TEXT_COO_FOR_TESS} language=ces
should be true '''${Text_from_area}''' == '''${CONTROLL_TEXT_FOR_TESS}'''



26 changes: 14 additions & 12 deletions tests/keywords/Variable.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
# ---------------------------------------- Basic set up ----------------------------------------------------------------
${URL} https://www.tesena.com/contact-us/ # 404 page, but good enough to present image comparison functionality
${BROWSER} Chrome
${SF_OOUTPUTS} Outputs
${SF_OOUTPUTS} ${OUTPUT DIR}/outputs
${SSIM1.0} 1.0
${SSIM0.95} 0.95
${SSIM0.5} 0.5
@{reso} 800 600
${screen800x600} Outputs/screen.png
${screen800x600} ${SF_OOUTPUTS}/screen.png
${FALSE} False
# ---------------------------------------- Compare 2 saved image ------------------------------------------------------
${1IMAGE} Img/forpres.png
${2IMAGE} Img/forpres1.png
${CS2_SFTESENA} Outputs/Tesena
${CS2_SFTESENA} ${OUTPUT DIR}/outputs
# ---------------------------------------- Creating screens ------------------------------------------------------------
${SF_NEWSCREEN} Outputs/Newscreens
${SF_NEWSCREEN} ${OUTPUT DIR}/outputs/Newscreens
${CS_SCREENNAME} resolution_is_
# ---------------------------------------- Comparing screen ------------------------------------------------------------
${CS_SFOUTPUTS} Outputs
${CS_SFOUTPUTS} ${OUTPUT DIR}/outputs
${CS_NEWURL} https://www.tesena.com/career/
# ---------------------------------------- Comparing screen without Area ------------------------------------------------------------
Expand All @@ -30,17 +30,19 @@ ${CSWA_NEWURL} https://www.alza.cz/
# ---------------------------------------- Text testing ------------------------------------------------------------
${TT_path_to_pdf} Img/dummy.pdf
${TT_name_img} pdfInPng
${TT_path_to_img} Outputs/${TT_name_img}.png
${TT_path} ${OUTPUT DIR}/outputs
${TT_path_to_img} ${TT_path}/${TT_name_img}.png
@{TT_text_area_coo} 0 0 179 83
${TT_Should_be_text} Dummy PDF file
#------------------------------------------ New PDF file --------------------------------------------------------------
${OK_PDF} Img/ok.pdf
${NOK_PDF} Img/nok.pdf
${PATH_TO_PDF_BASELINE_IMG} ${OUTPUT DIR}/outputs
${NAME_OK_PDF} Ok
${PATH_TO_OK_IMG} Outputs/${NAME_OK_PDF}_0.png
${PATH_TO_OK_IMG} ${PATH_TO_PDF_BASELINE_IMG}/${NAME_OK_PDF}_0.png
${NAME_NOK_PDF} nok
${PATH_TO_NOK_IMG} Outputs/${NAME_NOK_PDF}_0.png
${PATH_TO_NOK_IMG} ${PATH_TO_PDF_BASELINE_IMG}/${NAME_NOK_PDF}_0.png
@{TEXT_COO} 0 240 290 393 318 # First is number page, after x1,y1,x2,y2
${CONTROLL_TEXT} P Ř I Z N Á N Í
Expand All @@ -50,12 +52,12 @@ ${CONTROLL_TEXT_FOR_TESS} PŘIZNÁNÍ
${NAME_VYSVĚTLIVKY_OK_PDF} vOk
${NAME_VYSVĚTLIVKY_NOK_PDF} vNok
${PATH_TO_VOK_IMG} Outputs/${NAME_VYSVĚTLIVKY_OK_PDF}.png
${PATH_TO_VNOK_IMG} Outputs/${NAME_VYSVĚTLIVKY_NOK_PDF}.png
${PATH_TO_VOK_IMG} ${OUTPUT DIR}/outputs/${NAME_VYSVĚTLIVKY_OK_PDF}.png
${PATH_TO_VNOK_IMG} ${OUTPUT DIR}/outputs/${NAME_VYSVĚTLIVKY_NOK_PDF}.png
@{COO_VYSVĚTLIVEK} 60 1930 1580 2431
${AREA_VYSVĚTLIVKY_OK_PDF} vysOk
${AREA_VYSVĚTLIVKY_NOK_PDF} vysNok
${PATH_TO_VOK_AREA} Outputs/${AREA_VYSVĚTLIVKY_OK_PDF}.png
${PATH_TO_VNOK_AREA} Outputs/${AREA_VYSVĚTLIVKY_NOK_PDF}.png
${PATH_TO_VOK_AREA} ${OUTPUT DIR}/outputs/${AREA_VYSVĚTLIVKY_OK_PDF}.png
${PATH_TO_VNOK_AREA} ${OUTPUT DIR}/outputs/${AREA_VYSVĚTLIVKY_NOK_PDF}.png
39 changes: 30 additions & 9 deletions tests/unit_test.robot
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*** Settings ***
Documentation Suite description
Library SeleniumLibrary
Library Screenshot
Library OperatingSystem
Expand All @@ -15,24 +14,25 @@ Resource keywords/Variable.robot
Test Setup Start web-browser
Test Teardown Close web-browser


*** Test Cases ***
TC01 - Compare two saved images
[Tags] compare_save_screen tc01 VT
[Tags] tc01 compare_save_screen VT
[Setup]
Compare 2 same images
Compare images SSIM 0.5
Compare images SSIM 0.5: JPG Format
[Teardown]

TC02 - Creating screens in differen resolutions
[Tags] resolution tc02 VT
TC02 - Creating screens in different resolutions
[Tags] tc02 resolution VT
Create screens in 800 x 600 reso
Create screens in 3 resolutions
Create screens with full set up
Create screens with full set up: Format JPG

TC03 - Compare screen
[Tags] compare_screen tc03 VT
[Tags] tc03 compare_screen VT
Compare image with created screen
Compare image without full set up
Compare image full set up
Expand All @@ -42,24 +42,45 @@ TC03 - Compare screen
Compare diff image image format JPG

TC04 - Compare screen without some region
[Tags] cs_outregion VT demo
[Tags] tc04 cs_outregion VT demo
Comparing screen without some area: PNG Format

TC05 - Create Area
[Tags] create_area tc05 VT
[Tags] tc05 create_area VT
Create area 200 x 500: basic
Create area 200 x 500: full set up

TC06 - PDF and Tesseract
[Tags] tc06 TT demo
[Tags] tc06 TT demo
[Setup]
Create IMG
Create and compare vysvetlivky
Check words ${CONTROLL_TEXT} @{TEXT_COO}
Read text from image
Read text from image # Require: Tesseract
Find diff in PDF
[Teardown]

TC07 - Check text existence in PDF
[Tags] tc07 should_exist_this_text
[Setup]
${Text_from_pdf} Should exist this text ${TT_path_to_pdf} 0 Dummy
Should be true ${Text_from_pdf} == True
[Teardown]

TC08 - Check text existence in PDF
[Tags] tc08 return_text_from_area
[Setup]
${Text_from_pdf} Return text from area ${TT_path_to_pdf} 0 50 60 190 90
Should be true '''${Text_from_pdf}''' == '''${TT_Should_be_text}'''
[Teardown]

TC09 - Convert PDF to IMG
[Tags] tc09 pdf_to_img
[Setup]
Pdf to image ${OK_PDF} name=${NAME_OK_PDF} save_folder=${PATH_TO_PDF_BASELINE_IMG}
[Teardown]


*** Keywords ***
Start web-browser
Open Browser ${URL} ${BROWSER}
Expand Down

0 comments on commit e23fc88

Please sign in to comment.