Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
aliwaleed1 authored Aug 29, 2023
1 parent 73d0da5 commit 010248f
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 0 deletions.
111 changes: 111 additions & 0 deletions pages/evaluation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
"""page objects."""
import random
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from utils.utils import create_links, create_numbers


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]')
my_email = "[email protected]"

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 Evaluation:
"""Evaluation class."""
# '/html/body/div[20]/div[1]/nav/div/div/a[5]'
# "//a[contains(@href, '/dashboard')]"
dashboard_button = (By.XPATH, "//a[contains(@href, '/dashboard')]")
eval_path = '//*[@id="v-tabs-user-eval"]/div/div/div/form/div/'
select_user = (By.XPATH, eval_path+'div[1]/div/div/div')
selected_userx = eval_path+'div[1]/div/div/div/ul/li[3]/div/div/div'
selected_user = (By.XPATH, selected_userx)
name_befor = (By.XPATH, selected_userx+'/span')
user_name_after_selectedx = eval_path+'div[1]/div/div/div/div[1]/button'
user_name_after_selected = (By.XPATH, user_name_after_selectedx)
evaluation_quartur_xpath = eval_path+'div[2]/div/div/div'
evaluation_quartur = (By.XPATH, evaluation_quartur_xpath)
quartur_name_befor = (By.XPATH, evaluation_quartur_xpath + '/div')
quartur_name_after = (By.XPATH, evaluation_quartur_xpath+'/div[1]/button')
selected_quartur = (By.XPATH, eval_path+'div[2]/div/div/div/ul/li[3]/div')
link_path1 = '/html/body/div[20]/div[2]/section/div/div[2]/div/div[4]/div'
link_path2 = '/div/div/form/div/div[3]/div/div/input'
evaluation_link = (By.XPATH, link_path1+link_path2)
score_value = (By.XPATH, '//input[@placeholder="Enter score value"]')
random_score_value = random.randint(1, 1000)
submit_button = (By.XPATH, link_path1+'/div/div/form/div/div[5]/button')
links = create_links(5)
numbers = create_numbers(5)

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.dashboard_button))
dash_button = self.browser.find_element(*Evaluation.dashboard_button)
dash_button.click()

def click_select_user(self):
wait = WebDriverWait(self.browser, 30)
wait.until(EC.visibility_of_element_located(self.select_user))
select_user = self.browser.find_element(*Evaluation.select_user)
select_user.click()

def selected_usered(self):
wait = WebDriverWait(self.browser, 30)
wait.until(EC.visibility_of_element_located(self.selected_user))
select_usered = self.browser.find_element(*Evaluation.selected_user)
select_usered.click()

def select_evaluation_quartur(self):
eval_qurtur = self.browser.find_element(*Evaluation.evaluation_quartur)
eval_qurtur.click()

def select_quartur(self):
selec_quartur = self.browser.find_element(*Evaluation.selected_quartur)
selec_quartur.click()

def input_evaluation_link(self, link):
eval_link = self.browser.find_element(*Evaluation.evaluation_link)
eval_link.send_keys(link)

def input_score_value(self, value):
score_value = self.browser.find_element(*Evaluation.score_value)
score_value.clear()
score_value.send_keys(value)

def get_submit_button(self):
return self.browser.find_element(*Evaluation.submit_button)

def get_name_befor(self):
return self.browser.find_element(*Evaluation.name_befor)

def get_user_name_after_selected(self):
return self.browser.find_element(*Evaluation.user_name_after_selected)

def get_quartur_name_befor(self):
return self.browser.find_element(*Evaluation.quartur_name_befor)

def get_quartur_name_after(self):
return self.browser.find_element(*Evaluation.quartur_name_after)
12 changes: 12 additions & 0 deletions tests/contest.py
Original file line number Diff line number Diff line change
@@ -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()
94 changes: 94 additions & 0 deletions tests/test_evaluation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
"""Module to test Update User Vacation Balance functionality."""
import validators
import pytest
from pages.evaluation import Login, Evaluation


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()


def test_form_submission(browse):
"""Function to test submission of form."""
to_login(browse)
evaluation_page = Evaluation(browse)
evaluation_page.click_dashboard_button()
evaluation_page.click_select_user()
evaluation_page.selected_usered()
evaluation_page.select_evaluation_quartur()
evaluation_page.select_quartur()
evaluation_page.input_evaluation_link("link.com")
evaluation_page.input_score_value(Evaluation.random_score_value)
submit_button = evaluation_page.get_submit_button()
assert submit_button.is_enabled()


def test_user_selection(browse):
"""Function to test user selection in form."""
to_login(browse)
evaluation_page = Evaluation(browse)
evaluation_page.click_dashboard_button()
evaluation_page.click_select_user()
name_befor = evaluation_page.get_name_befor()
name_befor = name_befor.text
evaluation_page.selected_usered()
name_after = evaluation_page.get_user_name_after_selected().text
assert name_befor in name_after


def test_evaluation_quarter_selection(browse):
"""Function to test evaluation quarter selection in form."""
to_login(browse)
evaluation_page = Evaluation(browse)
evaluation_page.click_dashboard_button()
evaluation_page.select_evaluation_quartur()
name_befor = evaluation_page.get_quartur_name_befor()
name_befor = name_befor.text
evaluation_page.select_quartur()
name_after = evaluation_page.get_quartur_name_after().text
assert name_befor in name_after


@pytest.mark.parametrize("link", Evaluation.links)
def test_link_input(browse, link):
"""Function to test link input validation in form."""
to_login(browse)
evaluation_page = Evaluation(browse)
evaluation_page.click_dashboard_button()
evaluation_page.click_select_user()
evaluation_page.selected_usered()
evaluation_page.select_evaluation_quartur()
evaluation_page.select_quartur()
evaluation_page.input_score_value(Evaluation.random_score_value)
evaluation_page.select_evaluation_quartur()
evaluation_page.input_evaluation_link(link)
submit_button = evaluation_page.get_submit_button()
if validators.url(link):
assert submit_button.is_enabled()
else:
assert not submit_button.is_enabled()


@pytest.mark.parametrize("number", Evaluation.numbers)
def test_score_number_input(browse, number):
"""Function to test link input validation in form."""
to_login(browse)
evaluation_page = Evaluation(browse)
evaluation_page.click_dashboard_button()
evaluation_page.click_select_user()
evaluation_page.selected_usered()
evaluation_page.select_evaluation_quartur()
evaluation_page.select_quartur()
evaluation_page.select_evaluation_quartur()
evaluation_page.input_evaluation_link("https://www.example.com")
evaluation_page.input_score_value(number)
submit_button = evaluation_page.get_submit_button()
if str.isdigit(number):
assert submit_button.is_enabled()
else:
assert not submit_button.is_enabled()
2 changes: 2 additions & 0 deletions utils/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"""base URL"""
BASEURL = "https://cshr.gent01.dev.grid.tf/"
29 changes: 29 additions & 0 deletions utils/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import random
import string


def generate_random_link():
scheme = random.choice(["http", "https", " "])
rando = random.choices(string.ascii_lowercase, k=random.randint(5, 10))
domain = ''.join(rando)
extension = random.choice(["com", "org", "net", " "])
link = f"{scheme}://www.{domain}.{extension}"
return link


def create_links(num_links):
links = [generate_random_link() for _ in range(num_links)]
return links


def generate_number():
digits = string.digits + string.ascii_letters + string.punctuation
length = random.choice([random.randint(1, 5), random.randint(6, 10)])
larger_number = ''.join(random.choices(digits, k=length))
smaller_number = ''.join(random.choices(string.digits, k=length))
return random.choice([larger_number, smaller_number])


def create_numbers(num_number):
numbers = [generate_number() for _ in range(num_number)]
return numbers

0 comments on commit 010248f

Please sign in to comment.