Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avuori/861a3b6142a1576854a9 to your computer and use it in GitHub Desktop.
Save avuori/861a3b6142a1576854a9 to your computer and use it in GitHub Desktop.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.UUID;
public class SignupTest {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
// Open website
// Find the link to registration form
WebElement link = driver.findElement(By.cssSelector("[data-name='Register']"));
// Click the link;
// Generate a random email
final String randomEmail = randomEmail();
// Find the email form field
WebElement email = driver.findElement("register-email"));
// Type the random email to the form
// Find the password form field
WebElement password = driver.findElement("register-password"));
// Type a password to the form. This needs not be unique.
// Submit the sign up form
// Check the sign up succeeded by checking that the randomized
// email appears in the website's header bar.
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
WebElement header = d.findElement("header-login"));
return header.getText().contains(randomEmail);
//Close the browser
private static String randomEmail() {
return "random-" + UUID.randomUUID().toString() + "";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment