Skip to content
Snippets Groups Projects
Commit 72af8825 authored by Lene Wasskog's avatar Lene Wasskog
Browse files

test: Add selenium tests for application

Update .gitignore
parent 6d0f1f29
No related branches found
No related tags found
1 merge request!154Merge all Wildfly 26 compatible updates into develop
...@@ -8,3 +8,6 @@ classes/ ...@@ -8,3 +8,6 @@ classes/
*.iml *.iml
/.idea/ /.idea/
.vscode/settings.json .vscode/settings.json
selenium/.pytest_cache
selenium/.venv
selenium/tests/__pycache__
venv: venv/touchfile
venv/touchfile: requirements.txt
python3 -m venv .venv
. .venv/bin/activate; python3 -m pip install --upgrade -q pip; pip install -Ur requirements.txt
touch .venv/touchfile
test: venv
@echo 'Running Django application locally'
. .venv/bin/activate \
&& pytest
# Selenium tests
Ensure application is running locally. Tests expect login form to be available on http://localhost/index.html. Run tests like this:
```
$ make test
```
selenium==4.16.0
pytest
trio
pytest-trio
flake8
\ No newline at end of file
from selenium import webdriver
import pytest
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# https://github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk/examples/python/README.md
@pytest.fixture
def browser():
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(options=chrome_options)
driver.get("http://localhost/index.html")
assert driver.title == "Please log in"
driver.implicitly_wait(0.5)
driver.find_element(by=By.NAME, value="username").send_keys("seleniumtest")
driver.find_element(by=By.NAME, value="password").send_keys("seleniumTEST")
driver.find_element(by=By.CSS_SELECTOR, value="button").click()
assert driver.title == "Welcome to VIPSLogic"
yield driver
driver.quit()
def test_name_of_logged_in_user(browser):
link = browser.find_element(By.XPATH, '//a[text()="Selenium Testbruker"]')
assert link is not None
def test_admin_organisms(browser):
browser.find_element(By.XPATH, '//a[text()="Admin"]').click()
link = WebDriverWait(browser, 15).until(
EC.element_to_be_clickable((By.XPATH, '//a[text()="Organisms"]'))
)
assert link.get_attribute("href") == "http://localhost/organism"
link.click()
assert browser.title == "Organisms"
link = WebDriverWait(browser, 15).until(
EC.element_to_be_clickable((By.XPATH, '//a[text()="List all pests"]'))
)
link.click()
assert browser.title == "All pests"
def test_admin_scheduling(browser):
browser.find_element(By.XPATH, '//a[text()="Admin"]').click()
link = WebDriverWait(browser, 10).until(
EC.element_to_be_clickable((By.XPATH, '//a[text()="Scheduling"]'))
)
assert link.get_attribute("href") == "http://localhost/scheduling"
link.click()
assert browser.title == "Scheduling overview"
def test_admin_organization_group(browser):
browser.find_element(By.XPATH, '//a[text()="Admin"]').click()
link = WebDriverWait(browser, 10).until(
EC.element_to_be_clickable((By.XPATH, '//a[text()="Organization groups"]'))
)
assert link.get_attribute("href") == "http://localhost/organizationgroup"
link.click()
assert browser.title == "Organization groups"
def test_admin_apple_fruit_moth(browser):
browser.find_element(By.XPATH, '//a[text()="Admin"]').click()
link = WebDriverWait(browser, 10).until(
EC.element_to_be_clickable((By.XPATH, '//a[text()="Apple fruit moth"]'))
)
assert link.get_attribute("href") == "http://localhost/applefruitmoth"
link.click()
assert browser.title == "Rognebærmøllstasjoner"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment