0

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?

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

    driver.findElement(By.id("userEmailRegister")).sendKeys("testmail@testemail.com");
    driver.findElement(By.id("userPassRegister")).clear();
    driver.findElement(By.id("userPassRegister")).sendKeys("testpassword");
    driver.findElement(By.xpath("//*[@id=\"registerForm\"]/div[3]/div/div/label[2]")).click();
    driver.findElement(By.xpath("//*[@id=\"registerForm\"]/div[4]/div/div/label[2]")).click();
    driver.findElement(By.id("button_register")).click();
    driver.findElement(By.cssSelector("span.tdnone > span")).click();
}
2

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

@Test
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.
}

@Test
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, privacy policy and cookie policy

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