Skip to content

Commit

Permalink
Fix Xpaths for Selenium
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed May 21, 2024
1 parent dee37d4 commit 088b917
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tests/test_webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import shutil
import sys
from enum import StrEnum
from subprocess import DEVNULL

import pytest
Expand All @@ -17,11 +18,10 @@
PASSWORD = "password"
PORT = 8000

XPATH = {
"login": "/html/body/div[1]/div/div[2]/ul/li[2]/form",
"login2": "/html/body/div[2]/form/input[2]",
"logout": "/html/body/div[1]/div/div[2]/ul/li[2]/form",
}
class Xpath(StrEnum):
LOGIN = "//button[contains(@class, 'btn btn-primary') and text()='Login']"
LOGIN2 = "//input[@type='submit' and @value='login']"
LOGOUT = "//button[contains(@class, 'btn btn-primary') and text()='Logout']"


@pytest.fixture
Expand Down Expand Up @@ -141,9 +141,9 @@ def browser(container):

def test_login_logout(random_port, browser): # pylint: disable=redefined-outer-name
browser.get(f"http://127.0.0.1:{random_port}")
browser.find_element(By.XPATH, XPATH["login"]).click()
browser.find_element(By.XPATH, Xpath.LOGIN).click()
browser.find_element(By.NAME, value="username").send_keys(USERNAME)
browser.find_element(By.NAME, value="password").send_keys(PASSWORD)
browser.find_element(By.XPATH, XPATH["login2"]).click()
browser.find_element(By.XPATH, Xpath.LOGIN2).click()
assert "OpenQA-CloudWatch" in browser.title
browser.find_element(By.XPATH, XPATH["logout"]).click()
browser.find_element(By.XPATH, Xpath.LOGOUT).click()

0 comments on commit 088b917

Please sign in to comment.