TestNG DataProviders and asserts

Hi,

I read the article that you wrote: http://toolsqa.com/selenium-webdriver/testng-parameters-data-provider/

In a scenario where I want to automate the login functionality of a website , I want to provide 2 data sets:

  1. invalid username and invalid password
  2. valid username and valid password

I want my first test case to provide invalid credentials with the first set of data that I defined in the DataProvider method. Than I want to execute the first assert, and verify that I get the error message: ERROR: The password you entered for the email address test@email.com is incorrect.
In the second test case I want to provide valid credentials with the second set of data that I defined in the DataProvider method. Than I want to execute the second assert, and verify that I’m logged in.

Since the test method runs twice and both assert statements are running, one test always passes and one test always fails.
How do I use assert in this scenario?

Default Asked on January 24, 2018 in Selenium WebDriver.
Add Comment
  • 0 Answer(s)
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.