i am using selenium with java , cucumber , j unit and Gradle.

on my registration form there are many fields which has the validation message.

For example username field gives below error messages 1) When use the existing username giving "Username already exists " 2) Empty username giving " required " validation message 3) Its only allowing to create username which contains a-z and 0-9 if not then giving "can only contain a-z and 0-9" message

Do i need to create the separate tests to check this validation message? Like below

 Feature file : 
  Scenario Outline: Username already exist

    When Click on SignUp
    And username is '<username>'
    And phone is '<phonenumber>'
    And Email is '<email>'
    And companyname is '<companyname>'
    Then validation of username and email

    Examples: :

  | username | phonenumber | email | companyname |
  | romalwinn888554  | 65236523 | phurbadolma@yahoo.com | AAA |
  | laroche | 789654456 | phurbadolma@yahoo.com | AAA |
  | macharya1 | 786541212 | phurbadolma@yahoo.com | AAA|

Method : 
 public void userAlreadyExist(){
        utils.waitForElements(useralreadyExist , KnowsTestContext.timeout , KnowsTestContext.driver);
        String actual = useralreadyExist.getText();
        String expected = "Username already exists" ;
        Assert.assertEquals(actual , expected);

    public void emailAlreadyExist(){
        utils.waitForElements(emailalreadyExist , KnowsTestContext.timeout , KnowsTestContext.driver);
        String actual = emailalreadyExist.getText();
        String expected = "Email already exists" ;
        Assert.assertEquals(actual , expected);

Is it possible to do all the validation in one method ?

  • Are these can't be covered in unit/ API level tests? Jul 6 '18 at 10:58

In simple terms, the answer to "Do i need to create the separate tests to check this validation message?" is: Yes.

In general, it is advisable to create separate tests for each test case.


  • Combining several tests will make the tests more clumsy.

  • Unless it is a step in the test, you should not have an assert till the final step validation.

  • Debugging the failures will become more complicated, if you keep adding multiple validations from different paths to a single test. The real complexity comes when you have to debug tens of failures from random flaky tests, everyday.

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.