Sunday 24 January 2021

How to generate random string for test data in Automation Framework?


  • How to generate Random String for test data?

    In the below code return type is String and input parameter is integer(int length)

//generate random alphabet string

public static String generateRandomString(int length) {

        String text ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                StringBuilder sb = new StringBuilder(length);
        for( int i = 0; i < length; i++ )
            sb.append( text.charAt( random.nextInt(text.length()) ) );
        return sb.toString();

    }

//generate random integer string

    public static String generateRandomNumericString(int length) {
        String textnumber ="0123456789";
        StringBuilder sb = new StringBuilder(length);
        for( int i = 0; i < length; i++ )
            sb.append( textnumber.charAt( random.nextInt(textnumber.length()) ) );
        return sb.toString();//build

    }

More Framework Design related code?

https://automationreinvented.blogspot.com/search/label/FrameworkDesign

  • How to call above methods to generate the string and save in a variable ?

Generate random string of length 5?

String job = RandomUtils.generateRandomString(5);//generateRandomString = method we have created as above

Generate random numeric string of length 8?

String name = RandomUtils.generateRandomNumericString(8);//generateRandomNumericString= method we have created as above

 

************************************************* 

  • Explain testNG annotation in sequence with real time scenario?example of @After@Before in TestNG?selenium interview qus/testng

Click Here For Answer

**************************************************

SeleniumWebdriver Automation Testing Interview Questions:

API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API

 
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes

 
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

 
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux

 
Automation Testing/SDET Framework Design
https://automationreinvented.blogspot.com/search/label/FrameworkDesign


Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java


GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT


Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions

No comments:

Post a Comment

All Time Popular Posts

Most Featured Post

Introduction to Web Testing with Playwright

  Introduction to Web Testing with Playwright 📌  Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 📌  YouTube channel:  https://lnkd.in/gGUG...