Skip to content

Commit 1fbf2f5

Browse files
committed
Implemented the selenium tests for the auth page only for UI
1 parent 4d1bee8 commit 1fbf2f5

2 files changed

Lines changed: 109 additions & 0 deletions

File tree

testing/UI/pages/auth_page.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from utils.utils import BasePage
2+
from selenium.webdriver.common.by import By
3+
4+
class AuthPage(BasePage):
5+
def __init__(self, driver):
6+
super().__init__(driver)
7+
self.back_btn = (By.ID, "back-btn")
8+
self.login_input_username = (By.ID, "login-username")
9+
self.login_input_password = (By.ID, "login-password")
10+
self.login_btn = (By.CSS_SELECTOR, "#login-form button[type=submit]")
11+
self.signup_input_username = (By.ID, "signup-username")
12+
self.signup_input_password = (By.ID, "signup-password")
13+
self.signup_btn = (By.CSS_SELECTOR, "#signup-form button[type=submit]")
14+
self.switch_to_signup_link = (By.ID, "switch-to-signup")
15+
self.switch_to_login_link = (By.ID, "switch-to-login")
16+
self.login_info_element = (By.ID, "login-info")
17+
self.signup_info_element = (By.ID, "signup-info")
18+
19+
def get_title(self):
20+
return self.driver.title
21+
22+
def click_back_btn(self):
23+
self.wait_for_element(self.back_btn).click()
24+
25+
def type_login_username(self, username):
26+
inp = self.wait_for_element(self.login_input_username)
27+
inp.clear()
28+
inp.send_keys(username)
29+
30+
def type_login_password(self, password):
31+
inp = self.wait_for_element(self.login_input_password)
32+
inp.clear()
33+
inp.send_keys(password)
34+
35+
def type_signup_username(self, username):
36+
inp = self.wait_for_element(self.signup_input_username)
37+
inp.clear()
38+
inp.send_keys(username)
39+
40+
def type_signup_password(self, password):
41+
inp = self.wait_for_element(self.signup_input_password)
42+
inp.clear()
43+
inp.send_keys(password)
44+
45+
def click_switch_to_signup_link(self):
46+
self.wait_for_element(self.switch_to_signup_link).click()
47+
48+
def click_switch_to_login_link(self):
49+
self.wait_for_element(self.switch_to_login_link).click()
50+
51+
def get_login_info_element(self):
52+
return self.wait_for_element(self.login_info_element)
53+
54+
def get_signup_info_element(self):
55+
return self.wait_for_element(self.signup_info_element)
56+
57+
def click_login_btn(self):
58+
self.wait_for_element(self.login_btn).click()
59+
60+
def click_signup_btn(self):
61+
self.wait_for_element(self.signup_btn).click()

testing/UI/tests/test_auth.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from pages.auth_page import AuthPage
2+
3+
# This test is only for UI test it doesn't tests login and signup functionality.
4+
def test_auth(driver):
5+
# Loads the authentication page.
6+
driver.get("http://localhost:5501/webclient/src/auth.html")
7+
8+
# Creating object of AuthPage
9+
auth_page = AuthPage(driver)
10+
11+
# Tests
12+
assert auth_page.get_title() == "Authentication Page"
13+
14+
driver.execute_script("localStorage.setItem('authView', 'login')") # Setting the default view to login.
15+
16+
auth_page.type_login_username(" ")
17+
auth_page.type_login_password(" ")
18+
19+
auth_page.click_login_btn()
20+
21+
login_info = auth_page.get_login_info_element()
22+
23+
assert login_info.text == "Fields can't be empty"
24+
assert login_info.value_of_css_property("color") == "rgba(255, 0, 0, 1)" # red gets converted to this.
25+
26+
auth_page.click_switch_to_signup_link()
27+
28+
auth_page.type_signup_username(" ")
29+
auth_page.type_signup_password(" ")
30+
31+
auth_page.click_signup_btn()
32+
33+
signup_info = auth_page.get_signup_info_element()
34+
35+
assert signup_info.text == "Fields can't be empty"
36+
assert signup_info.value_of_css_property("color") == "rgba(255, 0, 0, 1)" # Red gets converted to this.
37+
38+
auth_page.type_signup_username("hello")
39+
auth_page.type_signup_password("world")
40+
41+
auth_page.click_signup_btn()
42+
43+
signup_info = auth_page.get_signup_info_element()
44+
45+
assert signup_info.text == "Password should be atleast of 6 characters"
46+
assert signup_info.value_of_css_property("color") == "rgba(255, 0, 0, 1)"
47+
48+
auth_page.click_back_btn()

0 commit comments

Comments
 (0)