How correct I executed the test case?



  • I'm new to Automation Testing.

    So I have a simple test case - "Login with incorrect username and password".


    Steps:

    1. Open the browser
    2. Enter the URL “http://practice.automationtesting.in/
    3. Click on "My Account"
    4. Enter incorrect username in username textbox
    5. Enter incorrect password in password textbox.
    6. Click on login button
    7. Proper error must be displayed (i.e. Invalid username) and prompt to enter login again.

    My logic is quite simple, if the provided user/pass are incorrect, I must receive an error message, and if I find this element on the page (by it's XPath), then the user/pass are incorrect indeed.

    class LoginTest(unittest.TestCase):
        baseURL = "http://practice.automationtesting.in/"
        username = "incorrect@email.com"
        password = "incorrect_password"
        driver = webdriver.Chrome()
    
        @classmethod
        def setUpClass(cls):
            cls.driver.get(cls.baseURL)
            cls.driver.maximize_window()
    
        def test_login(self):
            self.driver.find_element_by_xpath("//*[@id='menu-item-50']/a").click()
            lp = LoginPage(self.driver)
            lp.setUsername(self.username)
            lp.setPassword(self.password)
            lp.clickLogin()
            time.sleep(3)
            error = self.driver.find_element_by_xpath("//*[@id='page-36']/div/div[1]/ul/li/strong")
            if error.is_displayed():
                print("Incorrect username/password, please provide another one.")
    
        @classmethod
        def tearDownClass(cls):
            cls.driver.quit()
    

    I did something wrong? I'm sure there is another way to execute the step nr. 7. Can you give me an example? Thank you.



  • You would normally use an assert statement.

    So assert condition, "Custom message on failure of assert"

    I'm not 100% on python but think the formatting would be:

    assert error.is_displayed(),"Error - Expected incorrect password message to be displayed"
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2