-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add user evaluation form tests #201
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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]" | ||
aliwaleed1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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')]" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget to review and clean the code from all the unused comments |
||
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() | ||
Comment on lines
+49
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These 4 lines could be shorter into 2 like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I split it into more lines because flake extension , need the line be less than 79 character. |
||
|
||
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) |
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are u using Edge and not the chrome? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i just try another browser to check the VPN , i changed it . |
||
driver.get(BASEURL) | ||
yield driver | ||
driver.quit() |
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To_login isn't the best description maybe it would be better like before_test_setup, setup_for_test |
||
"""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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why didn't u just click the button on the function itself and just call it here?
|
||
|
||
|
||
def test_form_submission(browse): | ||
"""Function to test submission of form.""" | ||
to_login(browse) | ||
evaluation_page = Evaluation(browse) | ||
evaluation_page.click_dashboard_button() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see that these lines (maybe more) are repeated in every test, so why not just call them once in the to_login function and return the object So only this instead of the repeated 3 lines
|
||
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() |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"""base URL""" | ||
BASEURL = "https://cshr.gent01.dev.grid.tf/" |
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", " "]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does it have an empty string? same with the extension? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because , i need generate valid link and invalid ,and then check in test ,if valid must button will clickable . |
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you implement the Login class in the evaluation page??