Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Javafaker API – numerify(), letterify() and bothify() methods of Faker Class

Posted on 04/23/2025 By admin

Method names in the title might confuse you but those are the best words to give them when you go through this post.

If you want to create a string in a fixed format like “Amod123Mahajan” or “[email protected]” etc then the above methods will be useful for you.

I have used below Javafaker API dependency:-

  com.github.javafaker javafaker 1.0.2

I have covered Javafaker API below posts. You can go through it to understand more about Javafaker API.

Javafaker API – Generate Real-Time Fake Data – Faker Class

Generate Random Numbers Using Javafaker API – Java

String numerify​(String numberString)

As per official Javadoc, the above method returns a string with the ‘#‘ characters in the parameter replaced with random digits between 0-9 inclusive.

For example, the string “ABC##EFG” could be replaced with a string like “ABC99EFG“.

In simple words, if you want to have a number/s at specific places of a string just put a hash(“#”) there and numerify() method will put a random number there.

package FakerClassExamples;

import com.github.javafaker.Faker;

public class NumerifyExample {
        public static void main(String[] args) {

                Faker faker = new Faker();
                System.out.println(faker.numerify("Amod##Mahajan"));
                System.out.println(faker.numerify("A#mod##Maha#jan"));
                System.out.println(faker.numerify("A#mod##Mahajan453"));      
        }
}
Amod45Mahajan
A4mod23Maha2jan
A6mod39Mahajan453

String letterify​(String letterString)

As per official Javadoc, the above method returns a string with the ‘?’ characters in the parameter replaced with random alphabetic characters.

For example, the string “12??34” could be replaced with a string like “12ab34”.

In simple words, if you want to have an alphabet/s at specific places of a string just put a hash(“?”) there and letterify() method will put a random alphabet there.

By default, it will put lower case letters. If you want it should put upper case letters then you can use below-overloaded method.

public java.lang.String letterify​(java.lang.String letterString, boolean isUpper)

package FakerClassExamples;

import com.github.javafaker.Faker;

public class LetterifyExample {
        public static void main(String[] args) {

                Faker faker = new Faker();
                System.out.println(faker.letterify("167??789"));
                System.out.println(faker.letterify("?34?45??"));
                System.out.println(faker.letterify("Amod??Maha?an")); 
        }
}
167cn789
s34r45tv
AmodvnMahaban

String bothify​(String string)

Applies both a numerify(String) and a letterify(String) over the incoming string.

package FakerClassExamples;

import com.github.javafaker.Faker;

public class BothifyExample {
        public static void main(String[] args) {

                Faker faker = new Faker();
                System.out.println(faker.bothify("Amod##167??789"));
                System.out.println(faker.bothify("?34?45??"));
                System.out.println(faker.bothify("Amod##Maha?an"));   
        }
}
Amod18167mi789
c34t45bh
Amod59Mahacan

These methods will be helpful to create random email ids or alphanumeric strings etc.

You can clone above Git Repo from here.

You can subscribe to my YouTube channel RetargetCommon to learn from video tutorials.

If you have any doubt, feel free to comment below.If you like my posts, please like, comment, share and subscribe.#ThanksForReading

#HappyLearning

Uncategorized

Post navigation

Previous Post: findElement() And findElements() Methods in Selenium WebDriver
Next Post: Interview Experience at Publicis Sapient Bangalore for Selenium & API Testing Profile – Jan– 2020

Related Posts

How To Select Random Value From Any Drop down In Selenium Web Driver Uncategorized
How To Open Duplicate Tab In Chrome Browser – Selenium WebDriver Uncategorized
Page 26 Uncategorized
REST Assured Tutorial 61 – Deserialize Using JsonPath Uncategorized
Creating Object Repository In Selenium WebDriver Without Using Any External Data Source Uncategorized
npm Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark