Home > Back-end >  How to create permanent method for random email in Selenium webdriver
How to create permanent method for random email in Selenium webdriver

Time:11-24

I create a random email method in selenium but would like to know how to create a permanent method for the same in the Selenium web driver, so it will save time in testing.

    driver.findElement(By.id("email")).click();
    Random randomEmail = new Random();
    int randomInt = randomEmail.nextInt(1000);
    driver.findElement(By.id("email")).sendKeys("username"   randomInt   "@gmail.com");

CodePudding user response:

You can build your own random string generator like this:

protected String getSaltString() {
        String SALTCHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
        StringBuilder salt = new StringBuilder();
        Random rnd = new Random();
        while (salt.length() < 10) { // length of the random string.
            int index = (int) (rnd.nextFloat() * SALTCHARS.length());
            salt.append(SALTCHARS.charAt(index));
        }
        String saltStr = salt.toString()   "@gmail.com";
        return saltStr;

    }
  • Related