diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..dfe0770424b2a19faf507a501ebfc23be8f54e7b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..9c22eec7d167d7746160029a9bbb0c805dc3a34c --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +# Ignore log files and directories +logs/ + +# Ignore Python compiled files +*.pyc +__pycache__/ + +# Ignore virtual environment directories +venv/ +env/ + +# Ignore other sensitive or temporary files +*.env +*.tmp +.DS_Store diff --git a/__pycache__/set_up.cpython-310.pyc b/__pycache__/set_up.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fe3a83c753484f2fb1f1d51363ffdc79041048ac Binary files /dev/null and b/__pycache__/set_up.cpython-310.pyc differ diff --git a/__pycache__/test_log.cpython-310-pytest-8.2.1.pyc b/__pycache__/test_log.cpython-310-pytest-8.2.1.pyc new file mode 100644 index 0000000000000000000000000000000000000000..af91b3f94d7424407e49224576ca1814459231de Binary files /dev/null and b/__pycache__/test_log.cpython-310-pytest-8.2.1.pyc differ diff --git a/__pycache__/test_old.cpython-310-pytest-8.2.1.pyc b/__pycache__/test_old.cpython-310-pytest-8.2.1.pyc new file mode 100644 index 0000000000000000000000000000000000000000..540a1cfad84c625b43fff7d31aa233558c78a7b2 Binary files /dev/null and b/__pycache__/test_old.cpython-310-pytest-8.2.1.pyc differ diff --git a/__pycache__/test_sign_in.cpython-310-pytest-8.2.1.pyc b/__pycache__/test_sign_in.cpython-310-pytest-8.2.1.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6ef2b784278b6d21c4c6d2495d891e8dafd5bb4a Binary files /dev/null and b/__pycache__/test_sign_in.cpython-310-pytest-8.2.1.pyc differ diff --git a/actions.py b/actions.py new file mode 100644 index 0000000000000000000000000000000000000000..24136b32482c0a9216a05d56cb18f6a98bde15f7 --- /dev/null +++ b/actions.py @@ -0,0 +1,75 @@ +import requests +import json +from selenium.webdriver.common.by import By + +def click_sign_in(driver, logger, config): + try: + driver.find_element(By.XPATH, "//button[text()='Sign in']").click() + logger.debug("Clicked the Sign In button") + except Exception as e: + error_message = "Failed to load the Sign In button" + logger.error(f"{error_message}: {e}") + email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed to load the Sign In button.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Wait to see if the Sign In button can be loaded.</li></ol></p></body></html>" + email_subject = "Error occured in the Home page" + send_email(config, email_content, email_subject) + +def enter_name(driver, logger, config): + driver.find_element(By.XPATH, "//input[@name='fullName']").send_keys(config["signUp_name"]) + logger.debug("Entered name") + +def enter_email(driver, logger, config, email_input): + driver.find_element(By.XPATH, "//input[@name='email']").send_keys(email_input) + logger.debug("Entered email") + +def enter_password(driver, logger, config, validity, mode): + if (validity == "valid"): + pass_to_enter = config["correct_password"] + elif (validity == "invalid"): + pass_to_enter = config["wrong_password"] + if (mode == "first_enter"): + path = "//input[@name='password']" + elif (mode == "re_enter"): + path = "//input[@name='confirmPassword']" + driver.find_element(By.XPATH, path).send_keys(pass_to_enter) + logger.debug(f"Entered {validity} password") + +def submit_sign_in(driver, logger): + driver.find_element(By.XPATH, "//button[@type='submit']").click() + logger.debug("Clicked the Submit button") + +def click_register(driver, logger): + driver.find_element(By.XPATH, "//button[text()='Register']").click() + logger.debug("Clicked the Register button") + +# Postman helper functions +def send_email(config, input_content, input_subject): + url = config["email_url"] + sending_obj = { + "to": config["developer_email"], + "subject": input_subject, + "content": input_content + } + requests.post(url, json = sending_obj) + +def get_access_token(config): + email = config["signIn_email"] + password = config["correct_password"] + url = "https://backend-core-etas.digital.auto/v2/auth/login" + sending_obj = {"email": email, "password": password} + response = requests.post(url, json=sending_obj) + data = json.loads(response.content) + if "tokens" in data and "access" in data["tokens"] and "token" in data["tokens"]["access"]: + return data["tokens"]["access"]["token"] + else: + print("Unexpected response structure:", data) + return None + +def delete_model(token, model_id): + url = f"https://backend-core-etas.digital.auto/v2/models/{model_id}" + headers = {"Authorization": f"Bearer {token}"} + requests.delete(url, headers=headers) + +def delete_prototype(token, prototype_id): + url = f"https://backend-core-etas.digital.auto/v2/prototypes/{prototype_id}" + headers = {"Authorization": f"Bearer {token}"} + requests.delete(url, headers=headers) \ No newline at end of file diff --git a/class_method.py b/class_method.py new file mode 100644 index 0000000000000000000000000000000000000000..25775447d2dfa1c723cc366d42ec4a98afb5f2ae --- /dev/null +++ b/class_method.py @@ -0,0 +1,28 @@ +import json +import datetime +from set_up import Base # Importing the Base class + +class BaseTest: + @classmethod + def setUpClass(cls): + cls.base = Base() + cls.base.setup_logger() + # Making sure that logger is configured only once at the beginning of every test cases + + @classmethod + def tearDownClass(cls): + cls.base.logSummarizer() + # Making sure that the summarizer is configured only once at the end of every test cases + + def setUp(self): + self.base.setup_browser() + self.base.start_timer() + self.next = self.base.next + self.driver = self.base.driver + self.logger = self.base.logger + with open('info.json') as config_file: + self.config = json.load(config_file) + + def tearDown(self): + self.base.clean_up() + diff --git a/info.json b/info.json new file mode 100644 index 0000000000000000000000000000000000000000..bf3c5b76c045ad25146e9acf1d2703ffcf4f3b16 --- /dev/null +++ b/info.json @@ -0,0 +1,11 @@ +{ + "web_url": "https://autowrx-etas.digital.auto/", + "email_url": "https://backend-core-dev.digital.auto/v2/emails", + "test_file": "test_no_data.py", + "developer_email": "my.giangvu@gmail.com", + "signIn_email": "vuy4hc@bosch.com", + "wrong_password": "31280129850", + "correct_password": "blablabla", + "signUp_email": "bcd@gmail.com", + "signUp_name": "Bcd" +} diff --git a/main.py b/main.py new file mode 100644 index 0000000000000000000000000000000000000000..706f4a989b9c45df3c1b6a9bdc1bec1a04bb3d54 --- /dev/null +++ b/main.py @@ -0,0 +1,4 @@ +import os + +os.system("pytest -v -s test_model.py") +os.system("pytest -v -s test_signInOut.py") \ No newline at end of file diff --git a/set_up.py b/set_up.py new file mode 100644 index 0000000000000000000000000000000000000000..021c99ef73a7c072d8c82d61a6a20f2af68d3377 --- /dev/null +++ b/set_up.py @@ -0,0 +1,90 @@ +from selenium import webdriver +import logging +import time +from datetime import datetime +import json +import os + +with open('info.json') as config_file: + config = json.load(config_file) + +class Base(): + def setup_browser(self): + # Setting up Chrome Browser + self.driver = webdriver.Chrome() + try: + self.driver.get(config["web_url"]) + self.driver.maximize_window() + self.driver.implicitly_wait(10) # Timeout = 10s + self.next = True + except: + self.logger.error("Wrong web URL, the site can't be reached.") + self.next = False + + def setup_logger(self): + # Setting up Logger + timestamp = time.strftime("%H:%M:%S %d-%m-%Y") + log_dir = config.get("log_dir", "logs") # Default to "logs" if not specified + os.makedirs(log_dir, exist_ok=True) # Ensure the log directory exists + self.log_file_name = os.path.join(log_dir, f"logfile {timestamp}.log") + self.logger = logging.getLogger(config["test_file"]) + fileHandler = logging.FileHandler(self.log_file_name) + formatter = logging.Formatter(f"{timestamp} :%(levelname)s: %(filename)s :%(message)s") + fileHandler.setFormatter(formatter) + self.logger.addHandler(fileHandler) + self.logger.setLevel(logging.INFO) # Do not print the DEBUG statements + + def beginOfTest_logFormat(self, test_name): + for handler in self.logger.handlers: + if isinstance(handler, logging.FileHandler): + handler.stream.write(f"Begin {test_name}\n") + handler.flush() + + def endOfTest_logFormat(self): + self.end_time = datetime.now() + duration = self.end_time - self.start_time + duration_reformat = self.format_time(duration) + for handler in self.logger.handlers: + if isinstance(handler, logging.FileHandler): + handler.stream.write(f"Duration of the test case: {duration_reformat} seconds") + handler.stream.write("\n------------------------------------------------------------------------------------\n") + handler.flush() + + def logSummarizer(self): + with open(self.log_file_name, 'r') as fileReader: + countFailed = 0 + numOfTest = 0 + failed_tests = [] + for line in fileReader.readlines(): + if ("Begin" in line): + test_name = line[6:] + numOfTest += 1 + if ("ERROR" in line) or ("CRITICAL" in line): + countFailed += 1 + failed_tests.append(test_name) + failed_tests.append(line[21:]) + for handler in self.logger.handlers: + if isinstance(handler, logging.FileHandler): + handler.stream.write("SUMMARY:\n") + handler.stream.write(f"\tNumber of failed test cases: {countFailed} / {numOfTest}\n") + if (len(failed_tests) > 0): + handler.stream.write("Test cases that failed:\n") + for i in range(0, len(failed_tests), 2): + handler.stream.write(f"\t{failed_tests[i]}") + handler.stream.write(f"\t\t{failed_tests[i+1]}") + + def start_timer(self): + self.start_time = datetime.now() + + def format_time(self, input_time) -> str: + total_seconds = int(input_time.total_seconds()) + hours, remainder = divmod(total_seconds, 3600) #returns a pair of numbers consisting of their quotient and remainder + minutes, seconds = divmod(remainder, 60) + # return f"{hours:02}:{minutes:02}:{seconds:02}" + return f"{seconds:02}" + + def clean_up(self): + time.sleep(5) + self.driver.close() + self.logger.info("Closed the browser and ended the session.") + self.endOfTest_logFormat() diff --git a/test_model.py b/test_model.py new file mode 100644 index 0000000000000000000000000000000000000000..21ef4a754c9d84f64f3ddacfa7079f6b6b1c0a76 --- /dev/null +++ b/test_model.py @@ -0,0 +1,143 @@ +from util import * + +class Test_Model(BaseTest, unittest.TestCase): + + # Test case 1: Not sign in, if "Create New Model" button is visible then fail the test + def test_noSignIn_createNewModel(self): + self.base.beginOfTest_logFormat("test_noSignIn_createNewModel") + if (self.next is True): + self.logger.info("Started checking the visibility of 'Create New Model' button when not signing in") + signIn_button = self.driver.find_element(By.XPATH, "//button[text()='Sign in']") + if (signIn_button.is_displayed()): + self.logger.debug("User is not signing in") + self.driver.find_element(By.CSS_SELECTOR, "a[href='/model']").click() + self.logger.debug("Clicked the Select Model button") + try: + createModel_button = self.driver.find_element(By.XPATH, "//button[contains(text(),'Create New Model')]") + # assert (not createModel_button.is_displayed()) + assert (createModel_button.is_displayed()) + self.logger.info("Successfully tested the case of not seeing the 'Create New Model' button when not signing in") + except Exception as e: + error_message = "Failed the test. User did not sign in but can still see the 'Create New Model' button" + self.logger.critical(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed the test. User did not sign in but can still see the 'Create New Model' button.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Do not sign in and click the Select Model button</li><li>Wait to see if there is the Create New Model button</li></ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20the%20test.%20User%20did%20not%20sign%20in%20but%20can%20still%20see%20the%20'Create%20New%20Model'%20button.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3EDo%20not%20sign%20in%20and%20click%20the%20Select%20Model%20button%3C%2Fli%3E%3Cli%3EWait%20to%20see%20if%20there%20is%20the%20Create%20New%20Model%20button%3C%2Fli%3E%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Model page" + send_email(self.config, email_content, email_subject) + + # Test case 2: Sign in, test create new model and create new prototype + def test_SignIn_createNewModel(self): + self.base.beginOfTest_logFormat("test_SignIn_createNewModel") + if (self.next is True): + click_sign_in(self.driver, self.logger, self.config) + enter_email(self.driver, self.logger, self.config, self.config["signIn_email"]) + enter_password(self.driver, self.logger, self.config, "valid", "first_enter") + submit_sign_in(self.driver, self.logger) + + time.sleep(5) # Explicit wait doesn't work here + self.driver.find_element(By.CSS_SELECTOR, "a[href='/model']").click() + self.logger.debug("Clicked the Select Model button") + self.driver.find_element(By.XPATH, "//button[contains(text(),'Create New Model')]").click() + wait = WebDriverWait(self.driver, 5) + wait.until(expected_conditions.visibility_of_element_located((By.XPATH, "//img[@src='/imgs/profile.png']"))) + + # Hit Create New Model button without entering name + try: + self.driver.find_element(By. XPATH, "//button[text()='Create Model']").click() + self.logger.debug("Submitted the Create Model button") + wait = WebDriverWait(self.driver, 2) + wait.until(expected_conditions.visibility_of_element_located((By.XPATH, "//label[@class='da-label-small mt-2 text-da-accent-500']"))) + message = self.driver.find_element(By.XPATH, "//label[@class='da-label-small mt-2 text-da-accent-500']").text + assert (message == '"name" is not allowed to be empty') + self.logger.info("Successfully tested the case of empty input field when creating new model.") + except Exception as e: + error_message = "Failed the test. Empty input field passed" + self.logger.error(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed the test. Empty input field passed.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Sign in and click Select Model</li><li>Click the Create New Model, leave the name field empty and click Create Model.</li></ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20the%20test.%20Empty%20input%20field%20passed.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3ESign%20in%20and%20click%20Select%20Model%3C%2Fli%3E%3Cli%3EClick%20the%20Create%20New%20Model%2C%20leave%20the%20name%20field%20empty%20and%20click%20Create%20Model.%3C%2Fli%3E%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Model page" + send_email(self.config, email_content, email_subject) + + # Hit Create New Model button and entering name + try: + expected_name = "Automation Test Model" + self.driver.find_element(By.CSS_SELECTOR, "input[placeholder='Model Name']").send_keys(expected_name) + self.logger.debug("Entered the name for the new model") + self.driver.find_element(By. XPATH, "//button[text()='Create Model']").click() + self.logger.debug("Submitted the Create Model button") + wait = WebDriverWait(self.driver, 4) + wait.until(expected_conditions.visibility_of_element_located((By.XPATH, "//div[@class='col-span-6']/label"))) + self.logger.debug("Created successfully a new model") + model_name = self.driver.find_element(By.XPATH, "//div[@class='col-span-6']/label").text + assert (model_name == expected_name) + self.logger.info("Successfully verified the name of the new model") + + except Exception as e: + error_message = "Failed the test. Entered new model name is different from resulting new model name" + self.logger.error(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed the test. Entered new model name is different from resulting new model name.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Sign in and click Select Model</li><li>Click the Create New Model, enter the name and click Create Model.</li><li>Verify the entered model name with the actual model name on the screen</li></ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20the%20test.%20Entered%20new%20model%20name%20is%20different%20from%20resulting%20new%20model%20name.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3ESign%20in%20and%20click%20Select%20Model%3C%2Fli%3E%3Cli%3EClick%20the%20Create%20New%20Model%2C%20enter%20the%20name%20and%20click%20Create%20Model.%3C%2Fli%3E%3Cli%3EVerify%20the%20entered%20model%20name%20with%20the%20actual%20model%20name%20on%20the%20screen%3C%2Fli%3E%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Model page" + send_email(self.config, email_content, email_subject) + + # Navigate to other pages to test the prototype creation functions + self.driver.find_element(By.XPATH, "//label[text()='Prototype Library']").click() + self.logger.debug("Clicked the Prototype Library button") + self.driver.find_element(By.XPATH, "//button[text()='Create New Prototype']").click() + self.logger.debug("Clicked the Create New Prototype button") + + # Hit Create New Prototype without entering name + try: + self.driver.find_element(By.XPATH, "//button[text()='Create']").click() + self.logger.debug("Clicked the Create Prototype button") + self.driver.find_element(By.XPATH, "//label[@class='da-label-small mt-4 text-da-accent-500']") + wait = WebDriverWait(self.driver, 5) + wait.until(expected_conditions.visibility_of_element_located((By.XPATH, "//label[@class='da-label-small mt-4 text-da-accent-500']"))) + message = self.driver.find_element(By.XPATH, "//label[@class='da-label-small mt-4 text-da-accent-500']").text + assert (message == "Something went wrong") + self.logger.info("Successfully tested the case of empty input field when creating new prototype.") + except Exception as e: + error_message = "Failed the test. Empty input field passed" + self.logger.error(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed the test. Empty input field passed.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Sign in and click Select Model, choose a model and click Prototype Library</li><li>Click the Create New Prototype, leave the name field empty and click Create.</li></ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20the%20test.%20Empty%20input%20field%20passed.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3ESign%20in%20and%20click%20Select%20Model%2C%20choose%20a%20model%20and%20click%20Prototype%20Library%3C%2Fli%3E%3Cli%3EClick%20the%20Create%20New%20Prototype%2C%20leave%20the%20name%20field%20empty%20and%20click%20Create.%3C%2Fli%3E%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Model page" + send_email(self.config, email_content, email_subject) + + # Hit Create New Prototype and entering name + try: + expected_name = "Automation Test Prototype" + self.driver.find_element(By.XPATH, "//input[@placeholder='Name']").send_keys(expected_name) + self.driver.find_element(By.XPATH, "//button[text()='Create']").click() + self.logger.debug("Clicked the Create Prototype button") + wait = WebDriverWait(self.driver, 5) + wait.until(expected_conditions.visibility_of_element_located((By.XPATH, "//label[@class='da-label-regular text-da-gray-dark']"))) + prototype_name_left = self.driver.find_element(By.XPATH, "//label[@class='da-label-regular text-da-gray-dark']").text + assert (prototype_name_left == expected_name) + self.driver.find_element(By.XPATH, "//div[@style='max-width: 2000px;']").click() + self.logger.debug("Clicked the prototype box") + self.logger.info("Successfully verified the name of the newly created prototype") + wait = WebDriverWait(self.driver, 2) + wait.until(expected_conditions.visibility_of_element_located((By.XPATH, "//label[@class='da-label-title text-gray-600']"))) + prototype_name_right = self.driver.find_element(By.XPATH, "//label[@class='da-label-title text-gray-600']").text + assert (prototype_name_right == expected_name) + self.driver.find_element(By.XPATH, "//a/button[text()='Open']").click() + + # Delete the testing prototype + token = get_access_token(self.config) + current_url = self.driver.current_url + prototype_id = current_url[83:107] + delete_prototype(token,prototype_id) + + except Exception as e: + error_message = "Failed the test. Incorrect name of the newly created prototype" + self.logger.error(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed the test. Incorrect name of the newly created prototype.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Sign in and click Select Model, choose a model and click Prototype Library</li><li>Click the Create New Prototype, enter the name and click Create.</li><li>Wait and see the prototype name on the prototype page</li></ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20the%20test.%20Incorrect%20name%20of%20the%20newly%20created%20prototype.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3ESign%20in%20and%20click%20Select%20Model%2C%20choose%20a%20model%20and%20click%20Prototype%20Library%3C%2Fli%3E%3Cli%3EClick%20the%20Create%20New%20Prototype%2C%20enter%20the%20name%20and%20click%20Create.%3C%2Fli%3E%3Cli%3EWait%20and%20see%20the%20prototype%20name%20on%20the%20prototype%20page%3C%2Fli%3E%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Model page" + send_email(self.config, email_content, email_subject) + + # Delete the testing model + current_url = self.driver.current_url + model_id = current_url[40:64] + delete_model(token, model_id) \ No newline at end of file diff --git a/test_no_data.py b/test_no_data.py new file mode 100644 index 0000000000000000000000000000000000000000..f1958115089c8edd31fe543efa988b3b5b6d897f --- /dev/null +++ b/test_no_data.py @@ -0,0 +1,62 @@ +from util import * + +class Test_NoData(BaseTest, unittest.TestCase): + + # Test Case 1 + def test_numOf_models(self): + if (self.next is True): + try: + self.logger.info("Started counting the model components in model page") + self.driver.find_element(By.CSS_SELECTOR, "div[class='flex h-full items-center w-full']").click() + self.logger.debug("Clicked the Select Model button") + models = self.driver.find_elements(By.CSS_SELECTOR, "a[class='mr-2 w-full']") + assert (len(models) > 0) + self.logger.info("Successfully tested the number of model components in model page") + except Exception as e: + error_message = "Failed to load the model components in model page" + self.logger.error(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed to load the model components in model page.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Click on the 'Select Model' button.</li><li>Count the number of models.</li></ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20to%20load%20the%20model%20components%20in%20model%20page.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3EClick%20on%20the%20'Select%20Model'%20button.%3C%2Fli%3E%3Cli%3ECount%20the%20number%20of%20models.%3C%2Fli%3E%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Select Vehicle Models page" + send_email(self.config, email_content, email_subject) + + # Test Case 2 + def test_numOf_prototypes(self): + if (self.next is True): + try: + self.logger.info("Started counting the prototype components in home page") + prototypes = self.driver.find_elements(By.XPATH, "//div/div[@class='w-full h-full relative']/div/a/img") + assert (len(prototypes) > 0) + self.logger.info("Successfully tested the number of prototype components in home page") + except Exception as e: + error_message = "Failed to load the prototype components in home page" + self.logger.error(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed to load the prototype components in home page.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Count the number of prototypes.</li></ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20to%20load%20the%20prototype%20components%20in%20home%20page.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3ECount%20the%20number%20of%20prototypes.%3C%2Fli%3E%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Home page" + send_email(self.config, email_content, email_subject) + + + # Test Case 3 + def test_redPin_exist(self): + if (self.next is True): + try: + self.logger.info("Started counting the number of pins") + self.driver.find_element(By.CSS_SELECTOR, "div[class='flex h-full items-center w-full']").click() + self.logger.debug("Clicked the Select Model button") + self.driver.find_element(By.CSS_SELECTOR, "img[src='https://firebasestorage.googleapis.com/v0/b/digital-auto.appspot.com/o/media%2FE-Car_Full_Vehicle.png?alt=media&token=9c9d4cb4-fee0-42e3-bbb1-7feaa407cc8e']").click() + self.logger.debug("Clicked the ACME Car (EV) v0.1 Model") + self.driver.find_element(By.XPATH, "//div/div[text()='Vehicle APIs']").click() + self.logger.debug("Clicked the Vehicle APIs button") + hidden_element = self.driver.find_element(By.XPATH, "//span[text()='7']") + hidden_text = self.driver.execute_script("return arguments[0].textContent;", hidden_element) + assert (hidden_text == "7") + self.logger.info("Successfully tested the number of pins") + except: + error_message = "Failed to load the red pins on the canvas" + self.logger.error(error_message) + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed to load the red pins on the canvas.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Click on the 'Select Model' button.</li><li>Click on the 'ACME Car (EV) v0.1 Model' image.</li><li>Click on the 'Vehicle APIs' button.</li><li>Check for the existence of red pins on the canvas.</li></ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20to%20load%20the%20red%20pins%20on%20the%20canvas.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3EClick%20on%20the%20'Select%20Model'%20button.%3C%2Fli%3E%3Cli%3EClick%20on%20the%20'ACME%20Car%20(EV)%20v0.1%20Model'%20image.%3C%2Fli%3E%3Cli%3EClick%20on%20the%20'Vehicle%20APIs'%20button.%3C%2Fli%3E%3Cli%3ECheck%20for%20the%20existence%20of%20red%20pins%20on%20the%20canvas.%3C%2Fli%3E%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Vehicle APIs page" + send_email(self.config, email_content, email_subject) + \ No newline at end of file diff --git a/test_signInOut.py b/test_signInOut.py new file mode 100644 index 0000000000000000000000000000000000000000..34495a5b4c94be21c1ab5186d67364e90e5117ff --- /dev/null +++ b/test_signInOut.py @@ -0,0 +1,82 @@ +from util import * + +class Test_SignIn(BaseTest, unittest.TestCase): + + # Test case 1: Sign in with invalid password, catch the message -> Invalid username or password + def test_sign_in_invalid_password(self): + self.base.beginOfTest_logFormat("test_sign_in_invalid_password") + if (self.next is True): + self.logger.info("Started Signing In") + click_sign_in(self.driver, self.logger, self.config) + execute_next = True + try: + enter_email(self.driver, self.logger, self.config, self.config["signIn_email"]) + enter_password(self.driver, self.logger, self.config, "invalid", "first_enter") + submit_sign_in(self.driver, self.logger) + except Exception as e: + error_message = "Failed to open the Sign In pop up" + self.logger.error(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed to open the Sign In pop up.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Click the Sign In button</li><li>Wait to see if the Sign In pop up can be loaded.</li></ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20to%20open%20the%20Sign%20In%20pop%20up.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3EClick%20the%20Sign%20In%20button%3C%2Fli%3E%3Cli%3EWait%20to%20see%20if%20the%20Sign%20In%20pop%20up%20can%20be%20loaded.%3C%2Fli%3E%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Home page" + send_email(self.config, email_content, email_subject) + execute_next = False + + if (execute_next is True): + try: + wait = WebDriverWait(self.driver, 2) + wait.until(expected_conditions.visibility_of_element_located((By.XPATH, "//label[text()='Incorrect email or password']"))) + login_error = self.driver.find_element(By.XPATH, "//label[text()='Incorrect email or password']").text + assert (login_error == "Incorrect email or password") + self.logger.info("Successfully tested the invalid login attempt.") + except Exception as e: + error_message = "Wrong password passed. Broken implementation" + self.logger.critical(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Wrong password passed. Broken implementation.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Click the Sign In button</li><li>Enter the correct email but wrong password.</li><li>Click Sign In to see if the wrong password is accepted</li></ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EWrong%20password%20passed.%20Broken%20implementation.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3EClick%20the%20Sign%20In%20button%3C%2Fli%3E%3Cli%3EEnter%20the%20correct%20email%20but%20wrong%20password.%3C%2Fli%3E%3Cli%3EClick%20Sign%20In%20to%20see%20if%20the%20wrong%20password%20is%20accepted%3C%2Fli%3E%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Home page" + send_email(self.config, email_content, email_subject) + + # Test case 2: Sign in with valid password, verify the icon on the top right, then sign out + def test_sign_in_valid_password_and_sign_out(self): + self.base.beginOfTest_logFormat("test_sign_in_valid_password_and_sign_out") + if (self.next is True): + self.logger.info("Started Signing In") + click_sign_in(self.driver, self.logger, self.config) + execute_next = True + try: + enter_email(self.driver, self.logger, self.config, self.config["signIn_email"]) + enter_password(self.driver, self.logger, self.config, "valid", "first_enter") + submit_sign_in(self.driver, self.logger) + except Exception as e: + error_message = "Failed to open the Sign In pop up" + self.logger.error(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed to open the Sign In pop up.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Click the Sign In button</li><li>Wait to see if the Sign In pop up can be loaded.</li></ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20to%20open%20the%20Sign%20In%20pop%20up.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3EClick%20the%20Sign%20In%20button%3C%2Fli%3E%3Cli%3EWait%20to%20see%20if%20the%20Sign%20In%20pop%20up%20can%20be%20loaded.%3C%2Fli%3E%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Home page" + send_email(self.config, email_content, email_subject) + execute_next = False + + if (execute_next is True): + try: + wait = WebDriverWait(self.driver, 3) + wait.until(expected_conditions.visibility_of_element_located((By.XPATH, "//img[@src='/imgs/profile.png']"))) + self.driver.find_element(By.XPATH, "//img[@src='/imgs/profile.png']").click() + self.logger.debug("Clicked the user icon") + wait = WebDriverWait(self.driver, 2) + wait.until(expected_conditions.visibility_of_element_located((By.XPATH, "//label[contains(text(),'Logout')]"))) + logout_icon = self.driver.find_element(By.XPATH, "//label[contains(text(),'Logout')]") + assert (logout_icon.text == "Logout") + self.logger.info("Successfully signed in with the valid password.") + logout_icon.click() + self.logger.debug("Clicked the logout icon") + signIn_button = self.driver.find_element(By.XPATH, "//button[text()='Sign in']") + assert (signIn_button.is_displayed()) + self.logger.info("Successfully logged out.") + except Exception as e: + error_message = "Failed to sign in and log out with valid password. Broken implementation" + self.logger.critical(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed to sign in and log out with valid password. Broken implementation.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Click the Sign In button</li><li>Enter the correct email and correct password.</li><li>Click Sign In to see if the correct password is accepted</li><li>Then click log out button</li></ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20to%20sign%20in%20and%20log%20out%20with%20valid%20password.%20Broken%20implementation.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3EClick%20the%20Sign%20In%20button%3C%2Fli%3E%3Cli%3EEnter%20the%20correct%20email%20and%20correct%20password.%3C%2Fli%3E%3Cli%3EClick%20Sign%20In%20to%20see%20if%20the%20correct%20password%20is%20accepted%3C%2Fli%3E%3Cli%3EThen%20click%20log%20out%20button%3C%2Fli%3E%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Home page" + send_email(self.config, email_content, email_subject) diff --git a/test_signUp.py b/test_signUp.py new file mode 100644 index 0000000000000000000000000000000000000000..c46d9198f560a39523281af8bec348da9e8e11b4 --- /dev/null +++ b/test_signUp.py @@ -0,0 +1,151 @@ +from util import * + +class Test_SignUp(BaseTest, unittest.TestCase): + + # # Test case 1: Enter all info and sign up successfully + # def test_SignUp_successfully(self): + # if (self.next is True): + # click_sign_in(self.driver, self.logger, self.config) + # self.logger.info("Started Signing Up") + # click_register(self.driver, self.logger) + # execute_next = True + # try: + # enter_name(self.driver, self.logger, self.config) + # enter_email(self.driver, self.logger, self.config, self.config["signUp_email"]) + # enter_password(self.driver, self.logger, self.config, "valid", "first_enter") + # enter_password(self.driver, self.logger, self.config, "valid", "re_enter") + # except Exception as e: + # error_message = "Failed to open the Register pop up" + # self.logger.error(f"{error_message}: {e}") + # #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed to open the Register pop up.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Click the Sign In button then the Register button</li><li>Wait to see if the Register pop up can be loaded.</li></ol></p></body></html>" + # email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20to%20open%20the%20Register%20pop%20up.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3EClick%20the%20Sign%20In%20button%20then%20the%20Register%20button%3C%2Fli%3E%3Cli%3EWait%20to%20see%20if%20the%20Register%20pop%20up%20can%20be%20loaded.%3C%2Fli%3E%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + # email_subject = "Error occured in the Home page" + # send_email(self.config, email_content, email_subject) + # execute_next = False + + # if (execute_next is True): + # try: + # click_register(self.driver, self.logger) + # user_icon = self.driver.find_element(By.XPATH, "//img[@src='/imgs/profile.png']") + # assert (user_icon.is_displayed()) + # self.logger.info("Successfully signed up an account.") + # except Exception as e: + # error_message = "Failed to register an account" + # self.logger.critical(f"{error_message}: {e}") + # #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed to register an account.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Click the Sign In button and click the Register button</li><li>Fill in all required fields</li><li>Click Register button to create an account</li><</ol></p></body></html>" + # email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20to%20register%20an%20account.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3EClick%20the%20Sign%20In%20button%20and%20click%20the%20Register%20button%3C%2Fli%3E%3Cli%3EFill%20in%20all%20required%20fields%3C%2Fli%3E%3Cli%3EClick%20Register%20button%20to%20create%20an%20account%3C%2Fli%3E%3C%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + # email_subject = "Error occured in the Home page" + # send_email(self.config, email_content, email_subject) + + # Test case 2: Enter all info but using existing email, sign up failed and catch the message -> Email taken + def test_signUp_existingEmail(self): + if (self.next is True): + click_sign_in(self.driver, self.logger, self.config) + self.logger.info("Started Signing Up") + click_register(self.driver, self.logger) + execute_next = True + try: + enter_name(self.driver, self.logger, self.config) + enter_email(self.driver, self.logger, self.config, self.config["signIn_email"]) + enter_password(self.driver, self.logger, self.config, "valid", "first_enter") + enter_password(self.driver, self.logger, self.config, "valid", "re_enter") + except Exception as e: + error_message = "Failed to open the Register pop up" + self.logger.error(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed to open the Register pop up.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Click the Sign In button then the Register button</li><li>Wait to see if the Register pop up can be loaded.</li></ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20to%20open%20the%20Register%20pop%20up.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3EClick%20the%20Sign%20In%20button%20then%20the%20Register%20button%3C%2Fli%3E%3Cli%3EWait%20to%20see%20if%20the%20Register%20pop%20up%20can%20be%20loaded.%3C%2Fli%3E%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Home page" + send_email(self.config, email_content, email_subject) + execute_next = False + + if (execute_next is True): + try: + click_register(self.driver, self.logger) + wait = WebDriverWait(self.driver, 3) + wait.until(expected_conditions.visibility_of_element_located((By.XPATH, "//label[text()='Email already taken']"))) + message = self.driver.find_element(By.XPATH, "//label[text()='Email already taken']").text + assert (message == "Email already taken") + self.logger.info("Successfully tested the case of using existing email.") + except Exception as e: + error_message = "Failed the test - existing email was used to sign up the account. Broken implementation" + self.logger.critical(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed the test - existing email was used to sign up the account. Broken implementation.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Click the Sign In button and click the Register button</li><li>Fill in all required fields but use an existing email</li><li>Click Register button to create an account</li><</ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20the%20test%20-%20existing%20email%20was%20used%20to%20sign%20up%20the%20account.%20Broken%20implementation.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3EClick%20the%20Sign%20In%20button%20and%20click%20the%20Register%20button%3C%2Fli%3E%3Cli%3EFill%20in%20all%20required%20fields%20but%20use%20an%20existing%20email%3C%2Fli%3E%3Cli%3EClick%20Register%20button%20to%20create%20an%20account%3C%2Fli%3E%3C%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Home page" + send_email(self.config, email_content, email_subject) + + # Test case 3: Confirm password and password is different, catch the message -> "password" and "confirm password" must be the same + def test_signUp_confirmPassword(self): + if (self.next is True): + click_sign_in(self.driver, self.logger, self.config) + self.logger.info("Started Signing Up") + click_register(self.driver, self.logger) + execute_next = True + try: + enter_name(self.driver, self.logger, self.config) + enter_email(self.driver, self.logger, self.config, self.config["signIn_email"]) + enter_password(self.driver, self.logger, self.config, "valid", "first_enter") + enter_password(self.driver, self.logger, self.config, "invalid", "re_enter") + except Exception as e: + error_message = "Failed to open the Register pop up" + self.logger.error(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed to open the Register pop up.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Click the Sign In button then the Register button</li><li>Wait to see if the Register pop up can be loaded.</li></ol></p></body></html>" + email_contentt = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20to%20open%20the%20Register%20pop%20up.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3EClick%20the%20Sign%20In%20button%20then%20the%20Register%20button%3C%2Fli%3E%3Cli%3EWait%20to%20see%20if%20the%20Register%20pop%20up%20can%20be%20loaded.%3C%2Fli%3E%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Home page" + send_email(self.config, email_content, email_subject) + execute_next = False + + if (execute_next is True): + try: + click_register(self.driver, self.logger) + wait = WebDriverWait(self.driver, 3) + wait.until(expected_conditions.visibility_of_element_located((By.XPATH, "//label[@class='da-label-small mt-3 block text-da-accent-500']"))) + message = self.driver.find_element(By.XPATH, "//label[@class='da-label-small mt-3 block text-da-accent-500']").text + assert (message == '"password" and "confirm password" must be the same') + self.logger.info("Successfully tested the case of different entered password and confirmed password.") + except Exception as e: + error_message = "Failed the test - confirm password was different from entered password. Broken implementation" + self.logger.critical(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed the test - confirm password was different from entered password. Broken implementation.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Click the Sign In button and click the Register button</li><li>Fill in all required fields but enter a different password in the confirm password field</li><li>Click Register button to create an account</li><</ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20the%20test%20-%20confirm%20password%20was%20different%20from%20entered%20password.%20Broken%20implementation.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3EClick%20the%20Sign%20In%20button%20and%20click%20the%20Register%20button%3C%2Fli%3E%3Cli%3EFill%20in%20all%20required%20fields%20but%20enter%20a%20different%20password%20in%20the%20confirm%20password%20field%3C%2Fli%3E%3Cli%3EClick%20Register%20button%20to%20create%20an%20account%3C%2Fli%3E%3C%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Home page" + send_email(self.config, email_content, email_subject) + + # Test case 4: Lack 1 field of input, catch the message -> "email" is required + def test_signUp_lackOneField(self): + if (self.next is True): + click_sign_in(self.driver, self.logger, self.config) + self.logger.info("Started Signing Up") + click_register(self.driver, self.logger) + execute_next = True + try: + enter_name(self.driver, self.logger, self.config) + enter_password(self.driver, self.logger, self.config, "valid", "first_enter") + enter_password(self.driver, self.logger, self.config, "valid", "re_enter") + except Exception as e: + error_message = "Failed to open the Register pop up" + self.logger.error(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed to open the Register pop up.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Click the Sign In button then the Register button</li><li>Wait to see if the Register pop up can be loaded.</li></ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20to%20open%20the%20Register%20pop%20up.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3EClick%20the%20Sign%20In%20button%20then%20the%20Register%20button%3C%2Fli%3E%3Cli%3EWait%20to%20see%20if%20the%20Register%20pop%20up%20can%20be%20loaded.%3C%2Fli%3E%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Home page" + send_email(self.config, email_content, email_subject) + execute_next = False + + if (execute_next is True): + try: + click_register(self.driver, self.logger) + wait = WebDriverWait(self.driver, 3) + wait.until(expected_conditions.visibility_of_element_located((By.XPATH, "//label[@class='da-label-small mt-3 block text-da-accent-500']"))) + message = self.driver.find_element(By.XPATH, "//label[@class='da-label-small mt-3 block text-da-accent-500']").text + assert (message == '"email" is required') + self.logger.info("Successfully tested the case of not entered the email field.") + except Exception as e: + error_message = "Failed the test - empty email field but can still registered. Broken implementation" + self.logger.critical(f"{error_message}: {e}") + #email_content = "<!DOCTYPE html><html lang='en'><body><p>Failed the test - empty email field but can still registered. Broken implementation.</p><p>Steps to Reproduce:</p><ol><li>Navigate to the home page.</li><li>Click the Sign In button and click the Register button</li><li>Fill in all required fields except the email field</li><li>Click Register button to create an account</li><</ol></p></body></html>" + email_content = "%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D'en'%3E%3Cbody%3E%3Cp%3EFailed%20the%20test%20-%20empty%20email%20field%20but%20can%20still%20registered.%20Broken%20implementation.%3C%2Fp%3E%3Cp%3ESteps%20to%20Reproduce%3A%3C%2Fp%3E%3Col%3E%3Cli%3ENavigate%20to%20the%20home%20page.%3C%2Fli%3E%3Cli%3EClick%20the%20Sign%20In%20button%20and%20click%20the%20Register%20button%3C%2Fli%3E%3Cli%3EFill%20in%20all%20required%20fields%20except%20the%20email%20field%3C%2Fli%3E%3Cli%3EClick%20Register%20button%20to%20create%20an%20account%3C%2Fli%3E%3C%3C%2Fol%3E%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E" + email_subject = "Error occured in the Home page" + send_email(self.config, email_content, email_subject) + + +# Test case 5: Enter all info but invalid email address, catch the message -> this is failing diff --git a/util.py b/util.py new file mode 100644 index 0000000000000000000000000000000000000000..72a63c102e0ec8089cc9c2e5d70137fc7fc83a54 --- /dev/null +++ b/util.py @@ -0,0 +1,12 @@ +from selenium.webdriver.common.by import By +from selenium.webdriver.support.wait import WebDriverWait +from selenium.webdriver.support import expected_conditions +from selenium.common.exceptions import NoSuchElementException +from class_method import BaseTest +from set_up import Base +import unittest +import json +import requests +import time +import os +from actions import * \ No newline at end of file