Skip to content

Commit

Permalink
Refactor Playwright browser configuration to support ROBOT_HEADLESS, …
Browse files Browse the repository at this point in the history
…ROBOT_DEBUG and ROBOT_TRACE flags in a reasonable way
  • Loading branch information
datakurre committed Jun 30, 2023
1 parent e5d98a9 commit aba495b
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions src/plone/app/robotframework/browser.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -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 ***
Expand All @@ -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
Expand All @@ -71,4 +91,4 @@ Capture page screenshot
Capture page screenshot and log source
Take screenshot
${source}= Get page source
Log source ${source}
Log ${source}

0 comments on commit aba495b

Please sign in to comment.