Skip to content

Robot Framework Tests #256

Robot Framework Tests

Robot Framework Tests #256

Workflow file for this run

name: Robot Framework Tests
on:
push:
branches:
- master
schedule:
- cron: '0 0 * * 2'
workflow_dispatch: # Enable the run worklfow button on the Action
jobs:
setup-and-run-tests:
name: Setup the environment and run the tests
runs-on: ubuntu-latest
steps:
- name: Project checkout
uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v3
with:
python-version: 3.8
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 14
- name: Cache pip packages
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('config/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install selenium==4.9.1
pip install -r config/requirements.txt
npm install xml-js
- name: Run Robot Framework Tests # Run tests with arguments, I'm removing visual tests because free Applitools has a run quota
run: |
robot --variable HEADLESS:headless --exclude visual --outputdir test-reports tests || true
- name: Convert XML Results to JSON
run: |
node -e "const fs = require('fs'); const xml2js = require('xml-js'); const xmlData = fs.readFileSync('./test-reports/output.xml', 'utf8'); const jsonData = xml2js.xml2json(xmlData, { compact: true, spaces: 2 }); fs.writeFileSync('./test-reports/output.json', jsonData);"
- name: Read output.json and set test results into env variables
run: |
passedTests=$(jq -r '.robot.statistics.total.stat._attributes.pass' ./test-reports/output.json)
failedTests=$(jq -r '.robot.statistics.total.stat._attributes.fail' ./test-reports/output.json)
totalTests=$(expr $passedTests + $failedTests)
echo "PASSED_TESTS=$passedTests" >> $GITHUB_ENV
echo "FAILED_TESTS=$failedTests" >> $GITHUB_ENV
echo "TOTAL_TESTS=$totalTests" >> $GITHUB_ENV
- name: Upload Test Results
id: upload_results
uses: actions/upload-artifact@v2
with:
name: test-results
path: test-reports
- name: Publish Test Report
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./test-reports/
cname: ${{ env.CNAME }}
commit_message: Update test report for ${{ github.sha }}
- name: Display Test Report URL
run: |
echo "Test report: https://${{ github.actor }}.github.io/gen-ai-robot-test/report.html"
- name: Send Slack Notification
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
run: |
if [[ ${{ env.FAILED_TESTS }} -gt 0 ]]; then
color="#FF0000"
else
color="#00FF00"
fi
curl -X POST -H 'Content-type: application/json' --data '{
"channel": "'"${SLACK_CHANNEL}"'",
"attachments": [
{
"title": "Test Results",
"text": ":page_with_curl: *Total Tests:* ${{ env.TOTAL_TESTS }}\n:white_check_mark: *Passed Tests:* ${{ env.PASSED_TESTS }}\n:x: *Failed Tests:* ${{ env.FAILED_TESTS }}\n\n<https://${{ github.actor }}.github.io/gen-ai-robot-test/report.html|Click here to see the last test run in details>",
"color": "'"${color}"'"
}
]
}' "${SLACK_WEBHOOK_URL}"