From aba495b61c8e229704855dcca7454ddf3692b9ed Mon Sep 17 00:00:00 2001 From: Asko Soukka Date: Fri, 30 Jun 2023 10:56:39 +0300 Subject: [PATCH] Refactor Playwright browser configuration to support ROBOT_HEADLESS, ROBOT_DEBUG and ROBOT_TRACE flags in a reasonable way --- src/plone/app/robotframework/browser.robot | 46 ++++++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/plone/app/robotframework/browser.robot b/src/plone/app/robotframework/browser.robot index f732d22..dd226a0 100644 --- a/src/plone/app/robotframework/browser.robot +++ b/src/plone/app/robotframework/browser.robot @@ -7,15 +7,16 @@ # # $ bin/rfbrowser init # -# Pauses execution on error with ROBOT_DEBUG=true # Creates video and trace with ROBOT_TRACE=true -# +# Pauses execution on error with ROBOT_DEBUG=true +# Run browser as headless with ROBOT_HEADLESS=true +# Is backwards compatible with ROBOT_BROWESR=headless[browsername] +# # Traces can be viewed with # # $ bin/rfbrowser -F parts/test/*/*/tracing show-trace # - -# https://marketsquare.github.io/robotframework-browser/Browser.html#Importing +# Keywords: https://marketsquare.github.io/robotframework-browser/Browser.html Library Browser run_on_failure=${BROWSER_RUN_ON_FAILURE} @@ -26,10 +27,11 @@ Resource ${CMFPLONE_SELECTORS} ${BROWSER_RUN_ON_FAILURE} Take Screenshot -${BROWSER} chromium +${BROWSER} headlesschromium -${TRACE} -${DEBUG} +${DEBUG} false +${HEADLESS} false +${TRACE} false ${TRACING} ${OUTPUT_DIR}/tracing *** Keywords *** @@ -40,29 +42,47 @@ ${TRACING} ${OUTPUT_DIR}/tracing # https://marketsquare.github.io/robotframework-browser/Browser.html#New%20Persistent%20Context +Configure Test Browser + ${DEBUG}= Set Variable If "${DEBUG}".lower() in ["1", "on", "true", "yes"] ${TRUE} ${FALSE} + ${TRACE}= Set Variable If "${TRACE}".lower() in ["1", "on", "true", "yes"] ${TRUE} ${FALSE} + ${HEADLESS}= Set Variable If "${HEADLESS}".lower() in ["1", "on", "true", "yes"] ${TRUE} ${FALSE} + ${HEADLESS}= Set Variable if "${BROWSER}".startswith("headless") ${TRUE} ${HEADLESS} + ${HEADLESS}= Set Variable If ${TRACE} ${FALSE} ${HEADLESS} + ${HEADLESS}= Set Variable If ${DEBUG} ${FALSE} ${HEADLESS} + ${BROWSER}= Set Variable if "${BROWSER}".startswith("headless") ${BROWSER[len("headless"):]} ${BROWSER} + ${VIDEO}= Create dictionary dir ${OUTPUT_DIR}/video + + Set Suite Variable ${BROWSER} ${BROWSER} + Set Suite Variable ${DEBUG} ${DEBUG} + Set Suite Variable ${HEADLESS} ${HEADLESS} + Set Suite Variable ${TRACE} ${TRACE} + Set Suite Variable ${VIDEO} ${VIDEO} + Open Test Browser - ${record_video} Create dictionary dir ${OUTPUT_DIR}/video - Run Keyword If "${DEBUG}".lower() == "true" + Configure Test Browser + Run Keyword If ${DEBUG} ... Open browser ... url=${START_URL} ... browser=${BROWSER} - ... ELSE IF "${TRACE}".lower() == "true" + ... ELSE IF ${TRACE} ... New persistent context ... url=${START_URL} ... browser=${BROWSER} ... tracing=${TRACING} - ... recordVideo=${record_video} + ... headless=${HEADLESS} + ... recordVideo=${VIDEO} ... ELSE ... New persistent context ... url=${START_URL} ... browser=${BROWSER} + ... headless=${HEADLESS} Plone Test Setup Open Test Browser Plone Test Teardown Run Keyword If Test Failed ${BROWSER_RUN_ON_FAILURE} - Run Keyword If "${TRACE}".lower() == "true" Sleep 1s + Run Keyword If ${TRACE} Sleep 1s Close browser Capture page screenshot @@ -71,4 +91,4 @@ Capture page screenshot Capture page screenshot and log source Take screenshot ${source}= Get page source - Log source ${source} + Log ${source}