I want to check if a site allows a user to register using the same email multiple times. I use TestNG framework. How can I do negative testing for the case below?

public void testRegistration() throws Exception {
    driver.get(baseUrl + "/");
    driver.findElement(By.cssSelector("span.link.inlblk > strong")).click();

    driver.findElement(By.id("userEmailRegister")).sendKeys("[email protected]");
    driver.findElement(By.cssSelector("span.tdnone > span")).click();

1 Answer 1


You could extract the code for registration and invoke it from two test cases:

public void registration_with_unused_email_address_should_be_accepted() {
    // Create needed user data (e.g. first name, last name, email adress).
    // Invoke register method with created user data.
    // Assert confirmation text.

public void registration_with_used_email_address_should_be_rejected() {
    // Create needed user data (e.g. first name, last name, email address).
    // Invoke register method with created user data.
    // Reset window (e.g. logout).
    // Invoke register method with created user data again.
    // Assert error message.

This way, both test cases are independent. If you want to reduce the execution time, you can also adapt the "used email address" test case and invoke it after the "unused email address" test case, but personally I would prefer the other variant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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