diff --git a/pages/Employees.py b/pages/Employees.py index f4275100..8519ceb2 100644 --- a/pages/Employees.py +++ b/pages/Employees.py @@ -1,5 +1,7 @@ """page objects.""" from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC class Login: @@ -8,19 +10,38 @@ class Login: password = (By.XPATH, '//*[@type="password"]') login_button = (By.XPATH, '//button[text()="Login"]') undefined_message = (By.XPATH, '//*[@id="liveToast"]/div[2]') + my_email = "A@test.cs" + + def __init__(self, browser): + self.browser = browser + + def enter_email(self, email): + email_input = self.browser.find_element(*self.email) + email_input.clear() + email_input.send_keys(email) + + def enter_password(self, password): + password_input = self.browser.find_element(*self.password) + password_input.clear() + password_input.send_keys(password) + + def click_login_button(self): + return self.browser.find_element(*self.login_button) class Employees: """Employees class.""" - xpath1 = "//*[name()='svg' and contains(@class, 'bi-microsoft-teams')]" - employees_button = (By.XPATH, xpath1) + xpath1 = 'svg.bi.bi-microsoft-teams.nav_icon' + employees_button = (By.CSS_SELECTOR, xpath1) parent_element = (By.CLASS_NAME, "row.justify-content-between") profile_links = (By.TAG_NAME, "a") profile_text_element = (By.CLASS_NAME, "user-profile-image") profile_names = ["AD", "MR", "AW", "TB"] xpath_random_profile1 = '//*[@id="body-pd"]/div[2]/div/div/div' xpath_random_profile2 = '/div/div/div[1]/a/div/p' - random_profile = (By.XPATH, xpath_random_profile1+xpath_random_profile2) + random_profile_xpath = xpath_random_profile1+xpath_random_profile2 + random_profile = (By.XPATH, random_profile_xpath) + random_prfile_email = (By.XPATH, random_profile_xpath + '/small[2]/cite') xpath_email_profile1 = '//*[@id="body-pd"]/div[2]/section/div/div' xpath_email_profile2 = '/div[2]/div[1]/div/div[2]/div[2]/p' email_profile = (By.XPATH, xpath_email_profile1+xpath_email_profile2) @@ -28,3 +49,59 @@ class Employees: my_profile = (By.XPATH, xpath_my_profile1 + '/a/div') xpath_pr_email = '//*[@id="body-pd"]/div[2]/section/div/div/div[2]/div[1]' my_profile_email = (By.XPATH, xpath_pr_email + '/div/div[2]/div[2]/p') + + def __init__(self, browser): + self.browser = browser + + def click_dashboard_button(self): + wait = WebDriverWait(self.browser, 30) + wait.until(EC.visibility_of_element_located(self.employees_button)) + dashboard_button = self.browser.find_element(*self.employees_button) + dashboard_button.click() + + def get_parent_element(self): + wait = WebDriverWait(self.browser, 30) + wait.until(EC.visibility_of_element_located(self.parent_element)) + return self.browser.find_element(*Employees.parent_element) + + def get_profile_links(self): + parent_element = self.get_parent_element() + return parent_element.find_elements(*Employees.profile_links) + + def is_profile_present(self, profile_text): + profile_presence = {} + for name in Employees.profile_names: + profile_presence[name] = False + + profile_links = self.get_profile_links() + for link in profile_links: + profil_element = link.find_element(*Employees.profile_text_element) + profile_text = profil_element.text + profile_presence[profile_text] = True + + return all(value for value in profile_presence.values()) + + def click_random_profile(self): + wait = WebDriverWait(self.browser, 30) + wait.until(EC.visibility_of_element_located(self.random_profile)) + self.browser.find_element(*Employees.random_profile).click() + + def get_random_prfile_email(self): + wait = WebDriverWait(self.browser, 30) + wait.until(EC.visibility_of_element_located(self.random_prfile_email)) + return self.browser.find_element(*Employees.random_prfile_email) + + def get_profile_email(self): + wait = WebDriverWait(self.browser, 30) + wait.until(EC.visibility_of_element_located(self.email_profile)) + return self.browser.find_element(*Employees.email_profile) + + def click_my_profile(self): + wait = WebDriverWait(self.browser, 30) + wait.until(EC.visibility_of_element_located(self.my_profile)) + self.browser.find_element(*Employees.my_profile).click() + + def get_my_profile_email(self): + wait = WebDriverWait(self.browser, 30) + wait.until(EC.visibility_of_element_located(self.my_profile_email)) + return self.browser.find_element(*Employees.my_profile_email) diff --git a/tests/contest.py b/tests/contest.py index e69de29b..b043c731 100644 --- a/tests/contest.py +++ b/tests/contest.py @@ -0,0 +1,12 @@ +from selenium import webdriver +import pytest +from utils.base import BASEURL + + +@pytest.fixture(name="browse", scope="function") +def browsee(): + """Function to save driver fixture.""" + driver = webdriver.Edge() + driver.get(BASEURL) + yield driver + driver.quit() diff --git a/tests/test_employees.py b/tests/test_employees.py index fb11a9a5..b686b755 100644 --- a/tests/test_employees.py +++ b/tests/test_employees.py @@ -1,75 +1,43 @@ """Module to test meeting page.""" -import time -from selenium import webdriver -import pytest from pages.Employees import Login, Employees -from utils.base import BASEURL -@pytest.fixture(name="driver1") -def driver1_fixture(): - """Function to save driver fixture.""" - driver = webdriver.Edge() - driver.get(BASEURL) - yield driver - driver.quit() - - -def to_login(driver1): - """Function to login then go to employees page in tests.""" - email_input = driver1.find_element(*Login.email) - email_input.send_keys("A@test.cs") - password_input = driver1.find_element(*Login.password) - password_input.send_keys("123456789") - login_button = driver1.find_element(*Login.login_button) +def to_login(browse): + """Function to login in tests.""" + login_page = Login(browse) + login_page.enter_email(login_page.my_email) + login_page.enter_password("123456789") + login_button = login_page.click_login_button() login_button.click() - time.sleep(2) - - -def employees_page(driver1): - """Function to go to employees page in tests.""" - employees_button = driver1.find_element(*Employees.employees_button) - employees_button.click() - time.sleep(2) -def test_employees_displayed_on_page(driver1): +def test_employees_displayed_on_page(browse): """test for all Employees .""" - to_login(driver1) - employees_page(driver1) - parent_element = driver1.find_element(*Employees.parent_element) - profile_links = parent_element.find_elements(*Employees.profile_links) - # Dictionary to track if the profile is present or not - profile_presence = {} - # Initialize the profile - for name in Employees.profile_names: - profile_presence[name] = False - # Iterate through each profile link - for link in profile_links: - profile_element = link.find_element(*Employees.profile_text_element) - profile_text = profile_element.text - # Put value if existi - profile_presence[profile_text] = True - # Check if all profile names are present - all_present = all(value for value in profile_presence.values()) + to_login(browse) + employees_page = Employees(browse) + employees_page.click_dashboard_button() + all_present = employees_page.is_profile_present(Employees.profile_names) assert all_present -def test_employee_information_displayed(driver1): +def test_employee_information_displayed(browse): """test for employee information .""" - to_login(driver1) - employees_page(driver1) - random_profile = driver1.find_element(*Employees.random_profile) - random_profile.click() - profile = driver1.find_element(*Employees.email_profile) - assert profile.text == "admin@gmail.com" + to_login(browse) + employees_page = Employees(browse) + employees_page.click_dashboard_button() + random_profile_email = employees_page.get_random_prfile_email().text + employees_page.click_random_profile() + profile = employees_page.get_profile_email() + assert profile.text == random_profile_email -def test_employee_information_accuracy(driver1): +def test_employee_information_accuracy(browse): """test for my profile .""" - to_login(driver1) - employees_page(driver1) - my_profile = driver1.find_element(*Employees.my_profile) - my_profile.click() - my_profile_email = driver1.find_element(*Employees.my_profile_email) - assert my_profile_email.text == "A@test.cs" + to_login(browse) + login_page = Login(browse) + my_login_email = login_page.my_email + employees_page = Employees(browse) + employees_page.click_dashboard_button() + employees_page.click_my_profile() + my_profile_email = employees_page.get_my_profile_email() + assert my_profile_email.text == my_login_email