Now, let's add one more test to our framework and see how it grows.
In my previous post we created one basic test which tests that user can successfully login to the application. Let's add next test to same login tests category which will test that user cannot login to application with incorrect credentials and then develop corresponding needed framework.
Second test to Framework
For this we will create test and corresponding framework for below steps:- User tries to login with incorrect credentials
- Verify that the login error message is visible
Here, we have created one test method as "User_Cannot_Login_With_Invalid_Credentials". In this method again we have added required steps to test our scenario.
First and second steps are similar to previous test. Here, third step is assert step which is testing whether error message is visible or not when user tries to login with invalid credentials. In this test I am passing password as invalid but you can try any combination which in whole makes credentials invalid.
We have created one method in LoginPage class as "IsErrorMessageShowing" which will be checking whether error message is visible after invalid attempt.
Below is the code snippet of this method.
In this method we are just checking whether message is visible or not. But we can also check what actually the error message is i.e. whether error message is showing same as we are expecting or not. We can add a separate test for this.
Again in this method you can see that I am locating the web element in the method itself which can be refactored later as I mentioned in my earlier post.
Execution of test:
When you execute this test, as a first step Driver.GoTo method will make us navigate to "http://localhost:26382/wp-login.php". After this in second step LoginPage.Login method will be called. In this method as we are passing invalid password, login won't be successful.
And in third step, in assert we are calling IsErrorMessageShowing method of LoginPage class. It will be true if error message is visible otherwise it will return false. It error message does not show then test will fail with specified error message.
That's it. We have successfully added two tests with corresponding code to our framework.
In next post I will be writing something about the test structure. Till now we are just having one method in our test class i.e. [TestMethod]. But there are some other methods too in unit testing framework which you should be aware of and should be used to make tests more powerful and easy.
Thanks for reading this post. See you in the next post very soon...!!!
Comments
Post a Comment