I have written a simple automated test to test the login functionality of a Web-based application. I have a question about the if clause at the bottom and the assert True statement within it. Is it unnecessary? My intention with the login check is to confirm that the bot is redirected to the home screen after successful login by having it look for an element I know is on the home page. loginCheck is a Boolean, and it will return true if the Expected Conditions are met, so do I really need to assert True a Boolean I already know must be true?
Or am I overthinking this?
I would appreciate any suggestions on how to fortify my code to make debugging easier.
def test1(self):
#register and login
driver = self.driver
driver.get("http://localhost:3000")
self.assertIn("React To-Do List with Registration and Login", driver.title)
#try to log in
driver.find_element(By.XPATH, Tags.nameField).send_keys("rogera")
driver.find_element(By.XPATH, Tags.passField).send_keys("cde34rfv")
driver.find_element(By.XPATH, Tags.loginButton).click()
#check for error message
failureCheck = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.XPATH, Tags.errorMessage)))
#register if login attempt fails
if failureCheck:
driver.find_element(By.XPATH, Tags.registerButton).click()
time.sleep(3)
driver.find_element(By.XPATH, Tags.firstNameField).send_keys("Roger")
driver.find_element(By.XPATH, Tags.lastNameField).send_keys("Allen")
driver.find_element(By.XPATH, Tags.usernameField).send_keys("rogera")
driver.find_element(By.XPATH, Tags.passwordField).send_keys("cde34rfv")
driver.find_element(By.XPATH, Tags.registerPageButton).click()
time.sleep(3)
successCheck = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.XPATH, Tags.successMessage)))
#login after registration
if successCheck:
driver.find_element(By.XPATH, Tags.nameField).send_keys("rogera")
driver.find_element(By.XPATH, Tags.passField).send_keys("cde34rfv")
driver.find_element(By.XPATH, Tags.loginButton).click()
time.sleep(3)
loginCheck = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, Tags.logoutButton)))
if loginCheck:
assert True
else:
AssertionError("Something went wrong with user registration")
assert True
. It cannot possibly fail.