top of page
Search

How Can You Use AI in Test Automation?

In this article, we show how you can improve test automation by using AI. In an example, I will show how to add coded custom commands to our tool by applying appropriate prompts.



The answer is that you can use AI in many ways. Here I show you one application. In codeless test automation or during model-based testing actions (inputs) and assertions (outputs) are predefined. This means that there is a set of commands such as clicking, opening a page, entering text, or assertions such as ‘visible’, ‘non-visible’, ‘enabled’, ‘disabled’, etc.


However, in some cases, you need more. For example, you would like to test that the date to be entered has to be in the past, and not today or a future date. You cannot add a fixed date as the test will be wrong in the future. Therefore, we need a function, where the input is an integer. If this integer is -1, then the date for each test execution will be yesterday, if it’s 1 then always be tomorrow.


A simple prompt would be enough for AI to generate the necessary code. However, it’s not enough to ask MS Copilot to make a function, here is an input date command. The code should also consist of some special elements for our tool Harmony, such as including the selector, and some unique text that will appear in the pop-up menu when this command has to be selected. For example, this code for our date function can be the following:

When('{selector} receives date shift {string}', async function (locator, shift)


We can create a prompt that consists of two parts. The first part consists of a general description, you can copy it without any modification:


Our test automation tool generates JavaScript code for Playwright. The users just hover the mouse on a UI element, press the right button, and select a command such as

 

When {selector} is {string}

 

then enter a string such as ‘Monday’.

The code that fills the UI element with ‘Monday’ is:

 

When('{selector} is {string}', async function (locator, value) { await locator.fill(value) })

 

The text between {selector} and {string} should be unique and thus cannot be ‘is’, please invent something that fits the requirement below. However, you cannot change {string} to any {otherthanstring}


The second part should contain the description of the functionality:

 

Can you write a JavaScript code, where the input is the day shift form today (-1: yesterday, 1: tomorrow) and the output, i.e. the content of the UI element is a string in the form 04/15/2024, i.e. today?


Copilot generated the perfect code:



From here, adding a new date is very simple. Let’s select the command:



That is a simplification of calling the When function with its first parameter which is a string that identifies the command.


Then you should select the number of days related to the present day:



And pressing ok, the date will be yesterday (today is 04/24/2024):



In this way, the codeless tool remains codeless and you can add any functionality you need without knowing JavaScript.





29 views0 comments

Recent Posts

See All

Comments


bottom of page