diff --git a/actions.py b/actions.py index d7034ee00d192cd64dd3bda40220f73694ed2889..9a3a5c2831176a2c58147ce155bfdd7e3e0d9297 100644 --- a/actions.py +++ b/actions.py @@ -5,26 +5,13 @@ import re from urllib.parse import quote 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 occurred 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 sign_in(driver, configInfo): + driver.find_element(By.XPATH, "//button[text()='Sign in']").click() + driver.find_element(By.XPATH, "//input[@name='email']").send_keys(configInfo["signIn_email"]) + enter_password(driver, configInfo, "valid", "first_enter") + driver.find_element(By.XPATH, "//button[@type='submit']").click() -def enter_password(driver, logger, config, validity, mode): +def enter_password(driver, config, validity, mode): if (validity == "valid"): pass_to_enter = config["correct_password"] elif (validity == "invalid"): @@ -34,27 +21,6 @@ def enter_password(driver, logger, config, validity, mode): 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") - -def click_select_model(driver, logger): - driver.find_element(By.CSS_SELECTOR, "a[href='/model']").click() - logger.debug("Clicked the Select Model button") - -def click_prototype_library(driver, logger): - driver.find_element(By.XPATH, "//label[text()='Prototype Library']").click() - logger.debug("Clicked the Prototype Library button") - -def click_create_prototype(driver, logger): - driver.find_element(By.XPATH, "//button[text()='Create New Prototype']").click() - logger.debug("Clicked the Create New Prototype button") def error_handler(level, logger, configInfo, error_message, exception, email_content, place_occur): if (level == "critical"): @@ -102,7 +68,6 @@ def delete_testing_object(type, driver, logger, configInfo): except Exception as e: error_handler("warning", logger, "", f"Failure. Cannot use Postman API to delete the testing {type}.", e, "", "") -# Postman helper functions def send_email(configInfo, email_content, email_subject, mode): if (mode == "now"): url = configInfo["email_url"] diff --git a/info.json b/info.json index 28075994bed8944476256447f09b3bcb97d1a635..cc2bc63da97c9810d5527920efd3b50f8cadf12c 100644 --- a/info.json +++ b/info.json @@ -1,7 +1,7 @@ { "web_url": "https://autowrx.digital.auto/", "email_url": "https://backend-core-dev.digital.auto/v2/emails", - "test_file": "test_no_data.py", + "test_image_path": "C:\\Users\\VUY4HC\\Desktop\\WorkCode\\automation-test-digital-auto\\testing_image.jpg", "developer_email": "vuy4hc@bosch.com", "signIn_email": "vuy4hc@bosch.com", "wrong_password": "31280129850", diff --git a/main.py b/main.py index 5125966f614a755208cb0c04dac288ecce5fd7ef..a79aaeee57e26e69739ce8e4beb574966b3ce933 100644 --- a/main.py +++ b/main.py @@ -17,10 +17,10 @@ def main(): else: os.environ["HEADLESS"] = "false" - os.system("pytest -v -s --disable-warnings test_no_data.py") - os.system("pytest -v -s --disable-warnings test_page_traversal.py") - os.system("pytest -v -s --disable-warnings test_signInOut.py") - os.system("pytest -v -s --disable-warnings test_signUp.py") + # os.system("pytest -v -s --disable-warnings test_no_data.py") + # os.system("pytest -v -s --disable-warnings test_page_traversal.py") + # os.system("pytest -v -s --disable-warnings test_signInOut.py") + # os.system("pytest -v -s --disable-warnings test_signUp.py") os.system("pytest -v -s --disable-warnings test_model.py") os.system("pytest -v -s --disable-warnings test_prototype.py") diff --git a/set_up.py b/set_up.py index d70896d4a361f29c96c6e60d672e9353dfdd2b4f..d6c5e98cd73347c344c188d8031615c016131826 100644 --- a/set_up.py +++ b/set_up.py @@ -34,7 +34,7 @@ class Base(): log_dir = configInfo.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(configInfo["test_file"]) + self.logger = logging.getLogger( ) fileHandler = logging.FileHandler(self.log_file_name) formatter = logging.Formatter(f"{timestamp} :%(levelname)s: %(filename)s :%(message)s") fileHandler.setFormatter(formatter) diff --git a/test_model.py b/test_model.py index 7bf3e97aa8b2c7477fdb1dcc40f5f3011f578559..9d7cf358330e2391a57e553b5595d2775b696fd8 100644 --- a/test_model.py +++ b/test_model.py @@ -7,7 +7,8 @@ class Test_Model(BaseTest, unittest.TestCase): self.SignIn_createModel() # Also check the dropdown content inside this function self.check_modelVisibility() self.add_member_contributor() - self.create_wishlist_API() # NOT DONE + self.create_delete_wishlist_API() # Also create and delete discussion + self.use_API_filter() delete_testing_object("model", self.driver, self.logger, self.configInfo) @@ -17,7 +18,7 @@ class Test_Model(BaseTest, unittest.TestCase): 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") - click_select_model(self.driver, self.logger) + self.driver.find_element(By.CSS_SELECTOR, "a[href='/model']").click() try: createModel_button = self.driver.find_element(By.XPATH, "//button[contains(text(),'Create New Model')]") if (createModel_button.is_displayed()): @@ -27,27 +28,18 @@ class Test_Model(BaseTest, unittest.TestCase): self.logger.info("Success. Tested the case of not seeing the 'Create New Model' button when not signing in") def SignIn_createModel(self): - self.base.beginOfTest_logFormat("SignIn_createModel") - self.logger.info("Started creating new model when signing in") - - click_sign_in(self.driver, self.logger, self.configInfo) - enter_email(self.driver, self.logger, self.configInfo, self.configInfo["signIn_email"]) - enter_password(self.driver, self.logger, self.configInfo, "valid", "first_enter") - submit_sign_in(self.driver, self.logger) - - time.sleep(5) # Explicit wait doesn't work here - click_select_model(self.driver, self.logger) + self.base.beginOfTest_logFormat("SignIn_createModel") + sign_in(self.driver, self.configInfo) + time.sleep(5) + self.driver.find_element(By.CSS_SELECTOR, "a[href='/model']").click() self.driver.find_element(By.XPATH, "//button[contains(text(),'Create New Model')]").click() - self.logger.debug("Clicked the Create New Model button") wait = WebDriverWait(self.driver, 5) wait.until(expected_conditions.visibility_of_element_located((By.XPATH, "//img[@src='/imgs/profile.png']"))) - self.check_dropdownContent() # 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 @@ -60,9 +52,7 @@ class Test_Model(BaseTest, unittest.TestCase): 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, f"//label[text()='{expected_name}']"))) self.logger.debug("Created a new model") @@ -70,7 +60,7 @@ class Test_Model(BaseTest, unittest.TestCase): assert (model_name == expected_name or model_name == 'Model "Automation Test Model" created successfully') self.logger.info("Success. Verified the name of the new model") except Exception as e: - error_handler("warning", self.logger, "Failure. Entered new model name is different from resulting new model name", e, "", "") + error_handler("warning", self.logger, self.configInfo, "Failure. Entered new model name is different from resulting new model name", e, "", "") def check_dropdownContent(self): self.base.beginOfTest_logFormat("check_dropdownContent") @@ -147,8 +137,66 @@ class Test_Model(BaseTest, unittest.TestCase): result_text = self.driver.find_element(By.XPATH, "//div[@class='py-1 grow']/label").text assert (result_text == expected_result) - def create_wishlist_API(self): + def create_delete_wishlist_API(self): + self.base.beginOfTest_logFormat("create_delete_wishlist_API") self.driver.find_element(By.XPATH, "//div[text()='Vehicle APIs']").click() time.sleep(2) - self.driver.find_element(By.XPATH, "//button[contains(., 'Add Wishlist API')]").click() - self.driver.find_element(By.XPATH, "//input[@name='name']").send_keys("Testing API") \ No newline at end of file + try: + self.driver.find_element(By.XPATH, "//button[contains(., 'Add Wishlist API')]").click() + self.driver.find_element(By.XPATH, "//input[@name='name']").send_keys("Vehicle") + object = self.driver.find_element(By.XPATH, "//label[contains(text(),'API name must start with')]") + assert (object.text == 'API name must start with "Vehicle."') + time.sleep(3) + self.driver.find_element(By.XPATH, "//input[@name='name']").send_keys(".AutomationTest") + self.driver.find_element(By.XPATH, "//button[text()='Create']").click() + time.sleep(2) + self.driver.find_element(By.TAG_NAME, "input").send_keys("Vehicle.Automation") + self.driver.find_element(By.XPATH, "//label[text()='Vehicle.AutomationTest']").click() + self.logger.info("Success. Created successfully a wishlist API.") + except Exception as e: + error_handler("error", self.logger, self.configInfo, "Failure. Cannot create a wishlist API.", e, "", "") + + self.create_delete_discussion() + + try: + self.driver.find_element(By.XPATH, "//div[text()='Delete Wishlist API']").click() + self.driver.find_element(By.XPATH, "//button[text()='Confirm']").click() + self.logger.info("Success. Deleted successfully a wishlist API.") + except Exception as e: + error_handler("warning", self.logger, self.configInfo, "Failure. Cannot delete a wishlist API.", e, "", "") + + def create_delete_discussion(self): + self.base.beginOfTest_logFormat("create_delete_discussion") + try: + self.driver.find_element(By.TAG_NAME, "textarea").send_keys("Automation Test Discussion") + self.driver.find_element(By.XPATH, "//button[text()='Submit']").click() + time.sleep(2) + object = self.driver.find_element(By.XPATH, "//div[@class='whitespace-pre-wrap da-label-small max-h-[200px] overflow-y-auto']") + assert (object.text == "Automation Test Discussion") + self.logger.info("Success. Created successfully a discussion.") + except Exception as e: + error_handler("warning", self.logger, self.configInfo, "Failure. Cannot create a discussion.", e, "", "") + + try: + self.driver.find_element(By.XPATH, "//div[@class='inline-flex']/span/button[@class='da-btn da-btn-plain da-btn-sm']").click() + self.driver.find_element(By.XPATH, "//button[text()=' Delete']").click() + self.driver.find_element(By.XPATH, "//button[text()='Confirm']").click() + time.sleep(2) + self.logger.info("Success. Deleted successfully a discussion.") + except Exception as e: + error_handler("warning", self.logger, self.configInfo, "Failure. Cannot delete a discussion.", e, "", "") + + def use_API_filter(self): + self.base.beginOfTest_logFormat("use_API_filter") + for _ in range(20): + self.driver.find_element(By.TAG_NAME, "input").send_keys(Keys.BACK_SPACE) + self.driver.find_element(By.TAG_NAME, "input").send_keys("Vehicle.Body") + time.sleep(2) + self.driver.find_element(By.XPATH, "//button[normalize-space()='Filter']").click() + self.driver.find_element(By.XPATH, "//span[text()='Branch']").click() + self.driver.find_element(By.XPATH, "//span[text()='Actuator']").click() + self.driver.find_element(By.XPATH, "//span[text()='Attribute']").click() + numOf_sensors = self.driver.find_elements(By.XPATH, "//label[text()='sensor']") + assert (len(numOf_sensors) > 0) + time.sleep(3) + self.driver.find_element(By.XPATH, "//label[text()='COVESA VSS 4.1']").click() diff --git a/test_no_data.py b/test_no_data.py index 59a90e836bb4873d7a8f32b80dfd41d3cdcee844..c1906bc648bf8d2e3d95239a897c870da5fad8c3 100644 --- a/test_no_data.py +++ b/test_no_data.py @@ -9,7 +9,7 @@ class Test_NoData(BaseTest, unittest.TestCase): def count_numOf_models(self): self.base.beginOfTest_logFormat("count_numOf_models") try: - click_select_model(self.driver, self.logger) + self.driver.find_element(By.CSS_SELECTOR, "a[href='/model']").click() models = self.driver.find_elements(By.XPATH, "//div/a/div") assert (len(models) > 0) self.logger.info("Success. Tested the number of model components in model page") diff --git a/test_prototype.py b/test_prototype.py index 32169b7907aa50178bed843dcd109c8783a0c933..c4c656f92d70afd82d1c00dcd92d66adeefacff1 100644 --- a/test_prototype.py +++ b/test_prototype.py @@ -1,17 +1,18 @@ -# NOT DONE from util import * class Test_Prototype(BaseTest, unittest.TestCase): def test_Prototype_functionalities(self): if (self.next is True): - click_sign_in(self.driver, self.logger, self.configInfo) - enter_email(self.driver, self.logger, self.configInfo, self.configInfo["signIn_email"]) - enter_password(self.driver, self.logger, self.configInfo, "valid", "first_enter") - submit_sign_in(self.driver, self.logger) + sign_in(self.driver, self.configInfo) time.sleep(5) self.create_and_verify_prototypeName() + action = ActionChains(self.driver) + action.move_by_offset(100, 100).click().perform() # Click outside the pop up self.driver.find_element(By.XPATH, "//button[text()='Open']").click() # Open the prototype detail page + + self.edit_prototype() + time.sleep(5) self.use_Code_dashboardConfig() self.check_widgetList_content() self.add_widget() @@ -28,6 +29,44 @@ class Test_Prototype(BaseTest, unittest.TestCase): delete_testing_object("prototype", self.driver, self.logger, self.configInfo) delete_testing_object("model", self.driver, self.logger, self.configInfo) + + def edit_prototype(self): + self.base.beginOfTest_logFormat("edit_prototype") + try: + # edit the information + self.driver.find_element(By.XPATH, "//button[normalize-space()='Edit Prototype']").click() + self.driver.find_element(By.XPATH, "//div/label[text()='Problem']/following-sibling::div/div/input").send_keys("Testing Problem") + self.driver.find_element(By.XPATH, "//div/label[text()='Says who?']/following-sibling::div/div/input").send_keys("Testing People") + self.driver.find_element(By.XPATH, "//div/label[text()='Solution']/following-sibling::div/div/input").send_keys("Testing Solution") + complexity = self.driver.find_element(By.XPATH, "//label[text()='Complexity']/following-sibling::div/label/button[@role='combobox']") + complexity.click() + action = ActionChains(self.driver) + action.move_to_element(complexity).move_by_offset(0,100).click().perform() + status = self.driver.find_element(By.XPATH, "//label[text()='Status']/following-sibling::div/label/button[@role='combobox']") + status.click() + action1 = ActionChains(self.driver) + action1.move_to_element(status).move_by_offset(0,100).click().perform() + self.driver.find_element(By.XPATH, "//button[text()=' Change Image']").click() + self.driver.find_element(By.XPATH, "//input[@type='file']").send_keys(self.configInfo["test_image_path"]) + self.driver.find_element(By.XPATH, "//button[text()='Save']").click() + + # verify the changes + object = self.driver.find_element(By.XPATH, "//label[text()='Testing Problem']") + assert (object.is_displayed()) + object = self.driver.find_element(By.XPATH, "//label[text()='Testing People']") + assert (object.is_displayed()) + object = self.driver.find_element(By.XPATH, "//label[text()='Testing Solution']") + assert (object.is_displayed()) + object = self.driver.find_element(By.XPATH, "//label[text()='Released']") + assert (object.is_displayed()) + object = self.driver.find_element(By.XPATH, "//label[text()='Low']") + assert (object.is_displayed()) + object = self.driver.find_element(By.XPATH, "//div/img[contains(@src, 'https://upload.digitalauto.tech/data')]") + assert (object.is_displayed()) + + self.logger.info("Success. Edited succesfully the information of prototype.") + except Exception as e: + error_handler("warning", self.logger, "", "Failure. Failed to edit the information of prototype.", e, "", "") def run_code(self, mode): self.base.beginOfTest_logFormat(f"run_code_{mode}") @@ -68,7 +107,7 @@ class Test_Prototype(BaseTest, unittest.TestCase): action1 = ActionChains(self.driver) action1.key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL).key_down(Keys.BACK_SPACE).send_keys('print("Automation Test")').perform() - time.sleep(2) # wait for the update in the Dashboard tab + time.sleep(5) # wait for the update in the Dashboard tab self.driver.find_element(By.XPATH, "//a/div[text()='Dashboard']").click() self.driver.find_element(By.XPATH, "//div[@class='flex']/button").click() self.driver.find_element(By.XPATH, "//div[@class='flex']/div[text()='Code']").click() @@ -97,19 +136,17 @@ class Test_Prototype(BaseTest, unittest.TestCase): def create_and_verify_prototypeName(self): self.base.beginOfTest_logFormat("create_and_verify_prototypeName") time.sleep(3) - click_select_model(self.driver, self.logger) + self.driver.find_element(By.CSS_SELECTOR, "a[href='/model']").click() self.driver.find_element(By.XPATH, "//button[contains(text(),'Create New Model')]").click() expected_name = "Automation Test Model" self.driver.find_element(By.CSS_SELECTOR, "input[placeholder='Model Name']").send_keys(expected_name) self.driver.find_element(By. XPATH, "//button[text()='Create Model']").click() - # self.driver.find_element(By.XPATH, "//label[text()='Combustion Car']").click() - click_prototype_library(self.driver, self.logger) - click_create_prototype(self.driver, self.logger) + self.driver.find_element(By.XPATH, "//label[text()='Prototype Library']").click() + self.driver.find_element(By.XPATH, "//button[text()='Create New Prototype']").click() # 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") 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 @@ -122,19 +159,16 @@ class Test_Prototype(BaseTest, unittest.TestCase): try: expected_name = "Automation Test Prototype" self.driver.find_element(By.XPATH, "//input[@placeholder='Name']").send_keys(expected_name) - self.logger.debug("Entered the prototype 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, f"//label[text()='{expected_name}']"))) prototype_name_left = self.driver.find_element(By.XPATH, f"//label[text()='{expected_name}']").text assert (prototype_name_left == expected_name) self.driver.find_element(By.XPATH, f"//label[text()='{expected_name}']").click() - self.logger.debug("Clicked the prototype box") self.logger.info("Success. Verified the name of the newly created prototype on the left") except Exception as e: error_handler("warning", self.logger, "", "Failure. Incorrect name of the newly created prototype on the left", e, "", "") - + try: wait = WebDriverWait(self.driver, 2) wait.until(expected_conditions.visibility_of_element_located((By.XPATH, f"//div[@class='p-5']/div/label[text()='{expected_name}']"))) @@ -144,6 +178,18 @@ class Test_Prototype(BaseTest, unittest.TestCase): except Exception as e: error_handler("warning", self.logger, "", "Failure. Incorrect name of the newly created prototype on the right", e, "", "") + # Test case of creating a duplicate prototype + try: + self.driver.find_element(By.XPATH, "//button[text()='Create New Prototype']").click() + 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() + message = self.driver.find_element(By.XPATH, "(//label[contains(text(),'Duplicate prototype name')])[1]").text + assert ("Duplicate prototype name" in message) + self.logger.info("Success. Tested the case of creating duplicate prototype name.") + except Exception as e: + error_handler("warning", self.logger, "", "Failure. Duplicate prototoype name passed. Broken implementation.", e, "", "") + def use_Code_dashboardConfig(self): self.base.beginOfTest_logFormat("use_Code_dashboardConfig") @@ -200,6 +246,7 @@ class Test_Prototype(BaseTest, unittest.TestCase): self.base.beginOfTest_logFormat("add_widget") try: self.driver.find_element(By.XPATH, "(//div[contains(text(), 'Marketplace')])[2]").click() + time.sleep(5) self.driver.find_element(By.XPATH, "//label[text()='Simple Wiper Widget']").click() self.driver.find_element(By.XPATH, "//button[text()='Add selected widget']").click() widget_text = self.driver.find_element(By.XPATH, "//div[text()='Simple Wiper Widget']").text diff --git a/test_signInOut.py b/test_signInOut.py index 799bc333c8754852f3e3b537f3f0a9f6ee5c917b..d41ff9127cc38403d514f5c6b3a5e2a65dcc8239 100644 --- a/test_signInOut.py +++ b/test_signInOut.py @@ -11,7 +11,7 @@ class Test_SignIn_SignOut(BaseTest, unittest.TestCase): def open_SignIn_popup(self): self.base.beginOfTest_logFormat("open_SignIn_popup") - click_sign_in(self.driver, self.logger, self.configInfo) + self.driver.find_element(By.XPATH, "//button[text()='Sign in']").click() canOpen_popUp = False try: popup = self.driver.find_element(By.TAG_NAME, "form") @@ -25,9 +25,9 @@ class Test_SignIn_SignOut(BaseTest, unittest.TestCase): def signIn_invalid_password(self): self.base.beginOfTest_logFormat("signIn_invalid_password") try: - enter_email(self.driver, self.logger, self.configInfo, self.configInfo["signIn_email"]) - enter_password(self.driver, self.logger, self.configInfo, "invalid", "first_enter") - submit_sign_in(self.driver, self.logger) + self.driver.find_element(By.XPATH, "//input[@name='email']").send_keys(self.configInfo["signIn_email"]) + enter_password(self.driver, self.configInfo, "invalid", "first_enter") + self.driver.find_element(By.XPATH, "//button[@type='submit']").click() 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 @@ -41,8 +41,9 @@ class Test_SignIn_SignOut(BaseTest, unittest.TestCase): self.base.beginOfTest_logFormat("signIn_valid_password") try: self.driver.find_element(By.XPATH, "//input[@name='password']").clear() - enter_password(self.driver, self.logger, self.configInfo, "valid", "first_enter") - submit_sign_in(self.driver, self.logger) + enter_password(self.driver, self.configInfo, "valid", "first_enter") + self.driver.find_element(By.XPATH, "//button[@type='submit']").click() + time.sleep(5) user_icon = self.driver.find_element(By.TAG_NAME, "picture") assert (user_icon.is_displayed()) self.logger.info("Success. Tested the valid login attempt.") @@ -61,6 +62,7 @@ class Test_SignIn_SignOut(BaseTest, unittest.TestCase): logout_icon.click() self.logger.debug("Clicked the logout icon") signIn_button = self.driver.find_element(By.XPATH, "//button[text()='Sign in']") + time.sleep(5) assert (signIn_button.is_displayed()) self.logger.info("Success. Tested logging out.") except Exception as e: diff --git a/test_signUp.py b/test_signUp.py index 355e88b002a980777e773e11528d4169bdb0335d..5f41caa2ff17c50c45ee80502b301a8ab8371ddf 100644 --- a/test_signUp.py +++ b/test_signUp.py @@ -10,6 +10,8 @@ class Test_SignUp(BaseTest, unittest.TestCase): time.sleep(2) self.signUp_fail_confirmPassword() time.sleep(2) + self.signUp_fail_password_notLongEnough() + time.sleep(2) self.signUp_success() delete_testing_object("user", self.driver, self.logger, self.configInfo) @@ -17,8 +19,8 @@ class Test_SignUp(BaseTest, unittest.TestCase): def open_SignUp_popup(self): self.base.beginOfTest_logFormat("open_SignUp_popup") try: - click_sign_in(self.driver, self.logger, self.configInfo) - click_register(self.driver, self.logger) + self.driver.find_element(By.XPATH, "//button[text()='Sign in']").click() + self.driver.find_element(By.XPATH, "//button[text()='Register']").click() popup = self.driver.find_element(By.XPATH, "//form/label[text()='Register']") assert (popup.is_displayed()) canOpen_popUp = True @@ -30,10 +32,10 @@ class Test_SignUp(BaseTest, unittest.TestCase): def signUp_fail_lackOneField(self): self.base.beginOfTest_logFormat("signUp_fail_lackOneField") try: - enter_name(self.driver, self.logger, self.configInfo) - enter_password(self.driver, self.logger, self.configInfo, "valid", "first_enter") - enter_password(self.driver, self.logger, self.configInfo, "valid", "re_enter") - click_register(self.driver, self.logger) + self.driver.find_element(By.XPATH, "//input[@name='fullName']").send_keys(self.configInfo["signUp_name"]) + enter_password(self.driver, self.configInfo, "valid", "first_enter") + enter_password(self.driver, self.configInfo, "valid", "re_enter") + self.driver.find_element(By.XPATH, "//button[text()='Register']").click() expected_message = '"email" is required' wait = WebDriverWait(self.driver, 3) wait.until(expected_conditions.visibility_of_element_located((By.XPATH, f"//label[text()='{expected_message}']"))) @@ -46,8 +48,8 @@ class Test_SignUp(BaseTest, unittest.TestCase): def signUp_fail_existingEmail(self): self.base.beginOfTest_logFormat("signUp_fail_existingEmail") try: - enter_email(self.driver, self.logger, self.configInfo, self.configInfo["signIn_email"]) - click_register(self.driver, self.logger) + self.driver.find_element(By.XPATH, "//input[@name='email']").send_keys(self.configInfo["signIn_email"]) + self.driver.find_element(By.XPATH, "//button[text()='Register']").click() 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 @@ -60,8 +62,8 @@ class Test_SignUp(BaseTest, unittest.TestCase): self.base.beginOfTest_logFormat("signUp_fail_confirmPassword") try: self.driver.find_element(By.XPATH, "//input[@name='confirmPassword']").clear() - enter_password(self.driver, self.logger, self.configInfo, "invalid", "re_enter") - click_register(self.driver, self.logger) + enter_password(self.driver, self.configInfo, "invalid", "re_enter") + self.driver.find_element(By.XPATH, "//button[text()='Register']").click() expected_message = '"password" and "confirm password" must be the same' wait = WebDriverWait(self.driver, 3) wait.until(expected_conditions.visibility_of_element_located((By.XPATH, f"//label[text()='{expected_message}']"))) @@ -71,16 +73,34 @@ class Test_SignUp(BaseTest, unittest.TestCase): except Exception as e: error_handler("error", self.logger, "", "Failure. Confirm password was different from entered password. Broken implementation", e, "", "") + def signUp_fail_password_notLongEnough(self): + self.base.beginOfTest_logFormat("signUp_fail_password_notLongEnough") + try: + self.driver.find_element(By.XPATH, "//input[@name='password']").clear() + self.driver.find_element(By.XPATH, "//input[@name='password']").send_keys("pass") + self.driver.find_element(By.XPATH, "//input[@name='confirmPassword']").clear() + self.driver.find_element(By.XPATH, "//input[@name='confirmPassword']").send_keys("pass") + self.driver.find_element(By.XPATH, "//button[text()='Register']").click() + expected_message = 'password must be at least 8 characters' + wait = WebDriverWait(self.driver, 3) + wait.until(expected_conditions.visibility_of_element_located((By.XPATH, f"//label[text()='{expected_message}']"))) + message = self.driver.find_element(By.XPATH, f"//label[text()='{expected_message}']").text + assert (message == expected_message) + self.logger.info("Success. Tested the case of too short password entered.") + except Exception as e: + error_handler("error", self.logger, "", "Failure. Too short password passed. Broken implementation.", e, "", "") + def signUp_success(self): self.base.beginOfTest_logFormat("signUp_success") try: self.driver.find_element(By.XPATH, "//input[@name='email']").clear() - enter_email(self.driver, self.logger, self.configInfo, self.configInfo["signUp_email"]) + self.driver.find_element(By.XPATH, "//input[@name='email']").send_keys(self.configInfo["signUp_email"]) + self.driver.find_element(By.XPATH, "//input[@name='password']").clear() + enter_password(self.driver, self.configInfo, "valid", "first_enter") self.driver.find_element(By.XPATH, "//input[@name='confirmPassword']").clear() - enter_password(self.driver, self.logger, self.configInfo, "valid", "re_enter") - click_register(self.driver, self.logger) - wait = WebDriverWait(self.driver, 4) - wait.until(expected_conditions.visibility_of_element_located((By.TAG_NAME, "picture"))) + enter_password(self.driver, self.configInfo, "valid", "re_enter") + self.driver.find_element(By.XPATH, "//button[text()='Register']").click() + time.sleep(5) user_icon = self.driver.find_element(By.TAG_NAME, "picture") assert (user_icon.is_displayed()) self.logger.debug("Saw the user icon") @@ -88,7 +108,3 @@ class Test_SignUp(BaseTest, unittest.TestCase): except Exception as e: error_handler("error", self.logger, "", "Failure. Cannot register a new account.", e, "", "") self.driver.get_screenshot_as_file("screenshot-failed-register.png") - - # Test case 5: Enter all info but invalid email address, catch the message -> this is failing - - # Test case 6: Password has at least 8 characters -> is there any other conditions for password? diff --git a/testing_image.jpg b/testing_image.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0b88c91336ff8073f34d21ccd683a01f0e0995da Binary files /dev/null and b/testing_image.jpg differ