HomeJava

functions for test automation in java with examples

Like Tweet Pin it Share Share Email

In this article you will have access to a huge number of reusable functions for test automation in java with examples. This can be considered as your bible for all of your needs.

We will divide them in to multiple categories as below

  • String manipulation
  • Date and time
  • Number manipulation
  • Currency related

Remember that you can customize all the functions written in this article for your own needs. One of our assumption is that we are writing all the methods in a class by name “CM”. The methods have static scope, which allows you to call the methods without creating an object.

String manipulation functions for test automation in java

1. Iterate through all pattern matches in a string and replace with a given string
Purpose: This method is generally used when we want to replace a certain pattern of words in a string with different string or value. You can customize this code to your needs.
Code:
Example: If i want to replace all words which look like {{var1}} , {{var2}} etc with a certain value, then you can use above method as below

Date & Time functions for test automation in java

1. Function to get current date in a specific format
Purpose: Generally in a test case you might want to enter today’s date in an input field. You can get date using below method.
Code:
Example: You need to test a scenario where you need to provide today’s date as a product received date and continue the test case.

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *