1

I'm new to automation testing, so I have a question regarding the code that I used to execute a simple test case: "Check if password is masked". 1. Open the browser; 2. Enter the URL “http://practice.automationtesting.in/my-account/”; 3. Click on "My Account"; 4. Enter some characters in the password field; 5. The password field should display the characters in asterisks or bullets such that the password is not visible on the screen.

class LoginTest(unittest.TestCase):
    baseURL = "http://practice.automationtesting.in/my-account/"
    username = ""
    password = "vq+fZ9!PpX"
    driver = webdriver.Chrome()

    @classmethod
    def setUpClass(cls):
        cls.driver.get(cls.baseURL)
        cls.driver.maximize_window()

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()

    def test_pass_type(self):
        lp = LoginPage(self.driver)
        lp.set_password(self.password)
        check_pass = self.driver.find_element_by_xpath("//*[@type='password']")
        assert check_pass.is_displayed(), "Your password is masked!"

My logic: The input type="password" defines a password field (characters are masked). So if the password field have type "password", that means that the characters are masked by default. Or I did it wrong? I'm sure there is another way to execute the step nr. 5. Can someone give me an example? Thank you.

3

You are not checking if the password is masked, but if it there is an input of type password. Which is good, because you do not want to test browser behaviour, but the implementation by the developers. Browser make password input types behave as you expect. In your example you could leave out the code that sets the password, because it is irrelevant as you have to trust the browser implementation.

If you need to test the browser implementation you might need a different tool. With WebDriver you cannot verify the password is really masked. You could take a screenshot of the part of the application and compare it to a known masked state. For Python have a look at this question: https://stackoverflow.com/questions/15018372/how-to-take-partial-screenshot-with-selenium-webdriver-in-python

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.