Skip to content

Commit

Permalink
test submission
Browse files Browse the repository at this point in the history
  • Loading branch information
jmargutt committed Aug 16, 2024
1 parent 7c7bbea commit ab36af8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/test-submission.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: test Kobo submission

on:
workflow_dispatch:

jobs:
build:
runs-on: 'ubuntu-latest'
defaults:
run:
working-directory: ./app

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
architecture: 'x64'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install selenium click
- name: Run tests
run: |
python test_submission.py --form ${{ secrets.KOBO_TEST_FORM }} --url ${{ secrets.KOBO_TEST_URL }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ coverage.xml
.hypothesis/
.pytest_cache/
cover/
logs/

# Translations
*.mo
Expand Down
38 changes: 38 additions & 0 deletions test_submission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
import time
import click
import random
import string


@click.command()
@click.option("--form", help="Kobo form ID")
@click.option("--url", help="Kobo form URL")
def test(form, url):
options = Options()
options.add_argument("-headless")
driver = webdriver.Firefox(options=options)
driver.get(url)
time.sleep(5)

questions = {
"firstname": "".join(random.choices(string.ascii_uppercase, k=6)),
"lastname": "".join(random.choices(string.ascii_uppercase, k=6)),
}

for question, answer in questions.items():
text_input = driver.find_element(
By.XPATH, f"//input[@name='/{form}/{question}']"
)
text_input.send_keys(answer)

search_button = driver.find_element(By.ID, "submit-form")
search_button.click()

driver.close()


if __name__ == "__main__":
test()

0 comments on commit ab36af8

Please sign in to comment.