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 b27c414 commit cd995a5
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 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,9 @@
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']"
LOGOUT = "//button[contains(@class, 'btn btn-primary') and text()='Logout']"


@pytest.fixture
Expand Down Expand Up @@ -141,9 +140,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.LOGIN).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 cd995a5

Please sign in to comment.