Reputation: 1574
I've written a test case that creates random emails to be input to email fields
package DDselenium.general;
import org.apache.commons.lang3.RandomStringUtils;
public class GenerateData {
public String generateRandomString(int length){
return RandomStringUtils.randomAlphabetic(length);
}
public String generateRandomNumber(int length){
return RandomStringUtils.randomNumeric(length);
}
public String generateRandomAlphaNumeric(int length){
return RandomStringUtils.randomAlphanumeric(length);
}
public String generateStringWithAllobedSplChars(int length,String allowdSplChrs){
String allowedChars="abcdefghijklmnopqrstuvwxyz" + //alphabets
"1234567890"; //numbers
return RandomStringUtils.random(length, allowedChars);
}
public String generateEmail(int length) {
String allowedChars="abcdefghijklmnopqrstuvwxyz" + //alphabets
"1234567890"; //numbers
String email="";
String temp=RandomStringUtils.random(length,allowedChars);
email=temp.substring(0,temp.length()-9)+"@test.org";
return email;
}
public String generateUrl(int length) {
String allowedChars="abcdefghijklmnopqrstuvwxyz" + //alphabets
"1234567890"; //Numbers
String url="";
String temp=RandomStringUtils.random(length,allowedChars);
url=temp.substring(0,3)+"."+temp.substring(4,temp.length()-4)+"."+temp.substring(temp.length()-3);
return url;
}
}
I generate the random email as such
driver.findElement(By.id("email")).sendKeys(genData.generateEmail(30));
The issue I'm running into is that I have a field for confirm email so the actual code is like this
driver.findElement(By.id("email")).clear();
driver.findElement(By.id("email")).sendKeys(genData.generateEmail(30));
driver.findElement(By.id("emailconfirm")).clear();
driver.findElement(By.id("emailconfirm")).equals("email");
The problem is, I don't know how to get the emailconfirm element to duplicate whats in the email element.
Any help is appreciated.
Upvotes: 1
Views: 2565
Reputation: 10329
This is purely a Java problem, and has nothing to do with Selenium!
String email = genData.generateEmail(30);
driver.findElement(By.id("email")).clear();
driver.findElement(By.id("email")).sendKeys(email);
driver.findElement(By.id("emailconfirm")).clear();
driver.findElement(By.id("emailconfirm")).sendKeys(email);
Upvotes: 3