I am searching for methods to generate a string of alphabets and generate text to assert it, in selenium webDriver. i am trying to create a customer with random name. however, I have to search for the newly created customer and click on the text to enter further info.
You can use RandomStringUtils from apache commonlang api.
// random string of length 8 composed of alphabetic characters
String s = RandomStringUtils.randomAlphabetic(8);
// random string of length 8 composed of alphabetic characters and numbers
String s = RandomStringUtils.randomAlphanumeric(8);
// random string of length 8 composed only of lettes a, b, and c
String alphabet = "abc";
String s = RandomStringUtils.random(8, alphabet);
You can generate random alphanumeric number as :-
import java.util.UUID;
String uuid = UUID.randomUUID().toString();
//Now this uuid enter to your text box
driver.findElement(By.id("text box id")).sendKeys(uuid);
public static String randomString(int intValue) throws Exception {
char c[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int randomPosition;
String randomString = "";
for (int i = 0; i < intValue; i++) {
randomPosition = generateRandomIntIntRange(0, 51);
randomString = randomString + c[randomPosition];
}
System.out.println(randomString);
return randomString;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.