Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support playwright based robot tests via robotframework-browser extension #149

Merged
merged 8 commits into from
Jul 9, 2023
2 changes: 2 additions & 0 deletions news/3813.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add support for `playwright`-based tests via `robotframework-browser`.
[datakurre]
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def read(filename):
"robotframework",
"robotframework-selenium2library",
"robotframework-seleniumtestability",
"robotframework-browser",
"robotsuite", # not a direct dependency, but required for convenience
"selenium",
"setuptools",
Expand Down
95 changes: 95 additions & 0 deletions src/plone/app/robotframework/browser.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
*** Settings ***

# This browser.robot setups Robot tests with Playwright via robotframework-browser.
# This browser.robot cannot be used with selenium.robot, saucelabs.robot or keywords.robot.

# Requires initialization::
#
# $ bin/rfbrowser init
#
# 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
#
# Keywords: https://marketsquare.github.io/robotframework-browser/Browser.html

Library Browser run_on_failure=${BROWSER_RUN_ON_FAILURE}

Resource variables.robot
Resource ${CMFPLONE_SELECTORS}

*** Variables ***

${BROWSER_RUN_ON_FAILURE} Take Screenshot

${BROWSER} headlesschromium

${DEBUG} false
${HEADLESS} false
${TRACE} false
${TRACING} ${OUTPUT_DIR}/tracing

*** Keywords ***

# ----------------------------------------------------------------------------
# Browser
# ----------------------------------------------------------------------------

# 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}
${BROWSER}= Set Variable if "${BROWSER}" == "chrome" chromium ${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
Configure Test Browser
Run Keyword If ${DEBUG}
... Open browser
... url=${START_URL}
... browser=${BROWSER}
... ELSE IF ${TRACE}
... New persistent context
... url=${START_URL}
... browser=${BROWSER}
... tracing=${TRACING}
... 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} Sleep 1s
Close browser

Capture page screenshot
Take screenshot

Capture page screenshot and log source
Take screenshot
${source}= Get page source
Log ${source}
19 changes: 19 additions & 0 deletions src/plone/app/robotframework/tests/test_browser_library.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*** Settings ***

Resource plone/app/robotframework/browser.robot

Library Remote ${PLONE_URL}/RobotRemote

Test Setup Run keywords Plone test setup
Test Teardown Run keywords Plone test teardown

*** Test Cases ***

Test create content
Enable autologin as Contributor
Create content type=Document id=example-document title=Example document
Go to ${PLONE_URL}/example-document
Get text h1 Should be Example document

# https://marketsquare.github.io/robotframework-browser/Browser.html#Assertions

4 changes: 4 additions & 0 deletions src/plone/app/robotframework/tests/test_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def test_suite():
suite = unittest.TestSuite()
suite.addTests(
[
layered(
robotsuite.RobotTestSuite("test_browser_library.robot"),
layer=SIMPLE_PUBLICATION_ROBOT_TESTING,
),
layered(
robotsuite.RobotTestSuite("test_autologin_library.robot"),
layer=SIMPLE_PUBLICATION_ROBOT_TESTING,
Expand Down