Skip to content

Commit

Permalink
Add GH actions for Robot Framework tests
Browse files Browse the repository at this point in the history
  • Loading branch information
msabramo committed Apr 8, 2024
1 parent 72f65b7 commit 1cd4914
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/robot-framework.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Robot Framework CI

# Borrowed code from:
# https://piyathida-sanaoun01.medium.com/how-to-setup-ci-github-action-to-run-robot-framework-49028a404fee
# https://github.com/laojala/robot_docker_demo/blob/master/.github/workflows/run_robot_framework_tests.yml

on:
push:
branches:
- main
# Do not run tests if file README.md changes
paths-ignore:
- '**.md'
pull_request:
# Do not run tests if file README.md changes
paths-ignore:
- '**.md'
schedule:
# Run tests nightly at 2am
- cron: '0 2 * * *'
jobs:
Run-Test:
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/cache@v4
id: cache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
- name: Install pip dependencies
run: |
pip install --upgrade pip certifi urllib3
pip install -r requirements.txt -r requirements-test.txt
- name: Run Robot tests
run: ADDITIONAL_ROBOT_ARGS="--variable=additional_chrome_options:--headless" ./run-robot-tests
- name: Publish test results
if: always()
uses: actions/upload-artifact@v4
with:
name: robot-test-results
path: tests/robot/output/
6 changes: 5 additions & 1 deletion run-robot-tests
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#!/bin/sh

robot --outputdir=tests/robot/output --variable=app_url:http://localhost:8501 tests/robot/
robot \
--outputdir=tests/robot/output \
--variable=app_url:http://localhost:8501 \
${ADDITIONAL_ROBOT_ARGS} \
tests/robot/
36 changes: 36 additions & 0 deletions tests/robot/resources/app_keywords.robot
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,48 @@ Library SeleniumLibrary
*** Variables ***

${st_keyup_iframe_locator} css:iframe[title="st_keyup.st_keyup"]
${additional_chrome_options} ""

*** Keywords ***

Do Suite Setup
${process} = Start Process
... streamlit run streamlit_app.py
... --server.port 8501
... --server.headless true
... --browser.gatherUsageStats false
Log PID: ${process.pid}
VAR ${PROCESS} ${process} scope=SUITE

Do Suite Teardown
Log PID: ${PROCESS.pid}
${result} = Terminate Process ${PROCESS}
Log Terminate process result: ${result}

Input text into st_keyup
[Arguments] ${text}
Wait until element is visible ${st_keyup_iframe_locator}
Select frame ${st_keyup_iframe_locator}
Input text css:input[type="text"] ${text}
Unselect frame

Open URL
[Arguments] ${url}
Create Chrome WebDriver
Maximize Browser Window
Go To ${url}
Wait For Condition return document.readyState == "complete"
Wait Until Page Does Not Contain Running...
Sleep 1 second
${result}= Run Keyword And Return Status Page Should Not Contain Traceback
# Log To Console ${result}
IF ${result} != True
${error_text}= Get Text css:.message
Fail Page should not contain "Traceback". Error: ${error_text}
END

Create Chrome WebDriver
${chrome_options} = Evaluate selenium.webdriver.ChromeOptions()
# Call Method ${chrome_options} add_argument --no-sandbox
Call Method ${chrome_options} add_argument ${additional_chrome_options}
Create WebDriver Chrome options=${chrome_options}
10 changes: 7 additions & 3 deletions tests/robot/test_cases.robot
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
*** Settings ***

Resource resources/app_keywords.robot
Resource resources/app_keywords.robot
Library Process
Suite Setup Do Suite Setup
Suite Teardown Do Suite Teardown

*** Variables ***

${app_url} http://localhost:8501
${app_url} http://localhost:8501

*** Test Cases ***

Interact with st_keyup
Open browser ${app_url} Chrome
Sleep 2s
Open URL ${app_url}
Input text into st_keyup adjunta
Wait until page contains URB San Joaquin
Wait until page contains Jard De Adjuntas
Expand Down

0 comments on commit 1cd4914

Please sign in to comment.