diff --git a/.github/workflows/test-submission.yml b/.github/workflows/test-submission.yml new file mode 100644 index 0000000..a51af9d --- /dev/null +++ b/.github/workflows/test-submission.yml @@ -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 }} diff --git a/.gitignore b/.gitignore index 7e1132c..61d70dc 100644 --- a/.gitignore +++ b/.gitignore @@ -55,6 +55,7 @@ coverage.xml .hypothesis/ .pytest_cache/ cover/ +logs/ # Translations *.mo diff --git a/test_submission.py b/test_submission.py new file mode 100644 index 0000000..c17048f --- /dev/null +++ b/test_submission.py @@ -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()