diff --git a/pages/vacation.py b/pages/vacation.py new file mode 100644 index 000000000..7f1c47580 --- /dev/null +++ b/pages/vacation.py @@ -0,0 +1,66 @@ +"""page objects.""" +import random +from selenium.webdriver.common.by import By + + +class Login: + """login class.""" + email = (By.XPATH, '//*[@type="email"]') + password = (By.XPATH, '//*[@type="password"]') + login_button = (By.XPATH, '//button[text()="Login"]') + undefined_message = (By.XPATH, '//*[@id="liveToast"]/div[2]') + + +class Vacation: + """Vacation class.""" + dashboard_button = (By.XPATH, "//a[contains(@href, '/dashboard')]") + users_button = (By.XPATH, "//div[@class='caret svelte-1v9yc5w']") + xpath_for_section = '/html/body/div[20]/div[2]/section/div/div[2]/div/' + random_userx2 = 'div[2]/div/div/div/div/div/div/div/ul/li[3]/div/div/div' + random_user = (By.XPATH, xpath_for_section + random_userx2) + random_user_namex1 = '//*[@id="v-tabs-user-vacation-balance"]/div/div/' + random_user_namex2 = 'div/div[1]/div/div/div/div[1]/button' + random_user_name = (By.XPATH, random_user_namex1 + random_user_namex2) + load_balanc_butt = (By.XPATH, "//button[contains(text(), 'Load Balance')]") + annual_leavesx2 = 'div[2]/div/div/div/div/div[2]/div/div/input' + annual_leaves = (By.XPATH, xpath_for_section + annual_leavesx2) + leave_execusesx2 = 'div[2]/div/div/div/div/div[3]/div/div/input' + leave_execuses = (By.XPATH, xpath_for_section + leave_execusesx2) + emergency_leavesx2 = 'div[2]/div/div/div/div/div[4]/div/div/input' + emergency_leaves = (By.XPATH, xpath_for_section + emergency_leavesx2) + delete_old_balance_button = (By.XPATH, '//*[@id="flexCheckDefault"]') + submit_xpath = 'div[2]/div/div/div/div/div[6]/button' + submit_button = (By.XPATH, xpath_for_section + submit_xpath) + user_name_selected = (By.CLASS_NAME, "user_full_name") + error_messages = '/html/body/div[20]/div[2]/section/div/div[2]/div/div[2]/' + annual_error = 'div/div/div/div/div[2]/div/div/div[1]/span' + annual_error_message = (By.XPATH, error_messages+annual_error) + leave_error = 'div/div/div/div/div[3]/div/div/div[1]/span' + leave_error_message = (By.XPATH, error_messages+leave_error) + emergency_error = 'div/div/div/div/div[4]/div/div/div[1]/span' + emergency_error_message = (By.XPATH, error_messages+emergency_error) + + +class Employees: + """Employees class.""" + xpath1 = "//*[name()='svg' and contains(@class, 'bi-microsoft-teams')]" + employees_button = (By.XPATH, xpath1) + parent_element = (By.CLASS_NAME, "row.justify-content-between") + xpath_random_profile1 = '//*[@id="body-pd"]/div[2]/div/div/div/' + xpath_random_profile2 = 'div/div/div[4]/a/div/h5/div[1]/a' + random_profile = (By.XPATH, xpath_random_profile1 + xpath_random_profile2) + xpath_email_profile1 = '//*[@id="body-pd"]/div[2]/section/div/div' + xpath_email_profile2 = '/div[2]/div[1]/div/div[2]/div[2]/p' + profile_text = '//*[@id="body-pd"]/div[2]/section/div/' + annual_number = random.randint(1, 1000) + leave_number = random.randint(1, 1000) + emergency_number = random.randint(1, 1000) + annual_string = f"{annual_number} / {annual_number}" + leave_string = f"{leave_number} / {leave_number}" + emergency_string = f"{emergency_number} / {emergency_number}" + annual_leaves_text1 = 'div/div[2]/div[4]/div[2]/div[2]/div[1]' + annual_leaves_text = (By.XPATH, profile_text + annual_leaves_text1) + leave_execuses_text1 = 'div/div[2]/div[4]/div[2]/div[2]/div[3]' + leave_execus_text = (By.XPATH, profile_text + leave_execuses_text1) + emergency_leaves_text1 = '/div[2]/div[4]/div[2]/div[2]/div[2]' + emergency_leaves_text = (By.XPATH, profile_text + emergency_leaves_text1) diff --git a/tests/test_vacation.py b/tests/test_vacation.py new file mode 100644 index 000000000..60790b0b8 --- /dev/null +++ b/tests/test_vacation.py @@ -0,0 +1,137 @@ +"""Module to test Update User Vacation Balance functionality.""" +import time +from selenium import webdriver +import pytest +from pages.vacation import Login, Vacation, 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 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) + login_button.click() + time.sleep(3) + + +def to_select_user(driver1): + """Function to select user in tests.""" + time.sleep(3) + dashboard_button = driver1.find_element(*Vacation.dashboard_button) + dashboard_button.click() + time.sleep(3) + button = driver1.find_element(*Vacation.users_button) + button.click() + time.sleep(3) + random_user = driver1.find_element(*Vacation.random_user) + random_user.click() + + +def test_update_of_user_vacation_balance(driver1): + """Function to test update of user vacation balance.""" + to_login(driver1) + time.sleep(3) + to_select_user(driver1) + load_balanc_button = driver1.find_element(*Vacation.load_balanc_butt) + load_balanc_button.click() + time.sleep(3) + leave_execuses = driver1.find_element(*Vacation.leave_execuses) + leave_execuses.click() + leave_execuses.send_keys(Employees.leave_number) + annual_leaves = driver1.find_element(*Vacation.annual_leaves) + annual_leaves.click() + annual_leaves.send_keys(Employees.annual_number) + emergency_leaves = driver1.find_element(*Vacation.emergency_leaves) + emergency_leaves.click() + emergency_leaves.send_keys(Employees.emergency_number) + delete_button = driver1.find_element(*Vacation.delete_old_balance_button) + delete_button.click() + time.sleep(3) + submit_button = driver1.find_element(*Vacation.submit_button) + submit_button.click() + # go to employees page to check update + employees_button = driver1.find_element(*Employees.employees_button) + employees_button.click() + time.sleep(3) + random_profile = driver1.find_element(*Employees.random_profile) + random_profile.click() + time.sleep(3) + annual_text = driver1.find_element(*Employees.annual_leaves_text) + emergency_text = driver1.find_element(*Employees.emergency_leaves_text) + leave_text = driver1.find_element(*Employees.leave_execus_text) + is_annual = annual_text.text == Employees.annual_string + is_emergency = emergency_text.text == Employees.emergency_string + is_leave = leave_text.text == Employees.leave_string + assert is_annual and is_emergency and is_leave + + +def test_name_of_the_user(driver1): + """Function to test name of selected user.""" + to_login(driver1) + time.sleep(3) + to_select_user(driver1) + random_user_name = driver1.find_element(*Vacation.random_user_name) + user_name_in_selected_button = random_user_name.text + load_balanc_button = driver1.find_element(*Vacation.load_balanc_butt) + load_balanc_button.click() + time.sleep(3) + user_after_selected = driver1.find_element(*Vacation.user_name_selected) + assert user_after_selected.text in user_name_in_selected_button + + +def test_check_load_balance_button(driver1): + """Function to test load balance button.""" + to_login(driver1) + time.sleep(3) + to_select_user(driver1) + load_balanc_button = driver1.find_element(*Vacation.load_balanc_butt) + assert load_balanc_button.is_enabled() + assert load_balanc_button.text == "Load Balance" + + +@pytest.mark.parametrize("annual, leave, emergency", [ + ("", "123", "456"), + ("789", "", "456"), + ("789", "123", ""), +]) +def test_fields_with_empty(driver1, annual, leave, emergency): + """Function to test load balance button.""" + to_login(driver1) + to_select_user(driver1) + load_balanc_button = driver1.find_element(*Vacation.load_balanc_butt) + load_balanc_button.click() + time.sleep(3) + annual_leaves = driver1.find_element(*Vacation.annual_leaves) + annual_leaves.click() + annual_leaves.send_keys(annual) + leave_execuses = driver1.find_element(*Vacation.leave_execuses) + leave_execuses.click() + leave_execuses.send_keys(leave) + emergency_leaves = driver1.find_element(*Vacation.emergency_leaves) + emergency_leaves.click() + emergency_leaves.send_keys(emergency) + submit_button = driver1.find_element(*Vacation.submit_button) + if annual == "": + error_message = driver1.find_element(*Vacation.annual_error_message) + assert "Annual leaves is invalid" in error_message.text + assert not submit_button.is_enabled() + if leave == "": + error_message = driver1.find_element(*Vacation.leave_error_message) + assert "Leave execuses is invalid" in error_message.text + assert not submit_button.is_enabled() + if emergency == "": + error_message = driver1.find_element(*Vacation.emergency_error_message) + assert "Emergency leaves is invalid" in error_message.text + assert not submit_button.is_enabled() diff --git a/utils/base.py b/utils/base.py new file mode 100644 index 000000000..3ae4ec420 --- /dev/null +++ b/utils/base.py @@ -0,0 +1,2 @@ +"""base URL""" +BASEURL = "https://cshr.gent01.dev.grid.tf/"