1

I am trying to generate random characters - may be string or symbols or just random numbers sometimes for my test.

Example strings: Anything within A-Z, or from 0-9, 0r speacila characters such as @#$%^&&. May be 3 or 4 words. I should be able to choose what to send.

These will be sent to a text field to test.

Right now the code I use just generates random number (Example : 7dc53df5-703e-49b3-8670-b1c468f47f1f) which doesn't make sense all the time.

Is there any better way to implement this? How can I control what I want to send.

My code:

String uuid = UUID.randomUUID().toString();
        waitAndClickElement(textTitle);
        sendKeysToWebElement(textTitle, uuid);
moh17
  • 223
  • 1
  • 6
  • 25
  • I am open to any good and practical options. May be something that makes sense or that I can modify in a way that I get the type of string that I require. – moh17 Jun 16 '18 at 15:59
  • @Mohan `generates random number` and `doesn't make sense`; can you update the question with an example the type of _character sequence_ you are trying to generate? – undetected Selenium Jun 16 '18 at 17:30

1 Answers1

1

I needed to generate random string with exact length of 10 character in one of my project.
I used this method :

public static String generateString() {
        String uuid = UUID.randomUUID().toString();
        uuid = uuid.substring(0, Math.min(uuid.length(), 10));
        System.err.println(uuid);
        return uuid;
    }  

Though there are multiple ways you can generate random strings.

I'm giving some of the references for you.

Alpha-numeric-string
string-with-a-z-and-0-9-
java-random-string

Hope this will help.

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
  • 1
    Thank you. I will try this out and mark it as answer if this is the best way for me :) – moh17 Jun 16 '18 at 16:11
  • 1
    Marking it as answer because the links provided helped me to learn about apache class and generate strings that i required. – moh17 Jun 17 '18 at 09:00