Playwright Test Scripting with Natural Language - Part 01

Lahiru Madhawa
3 min readNov 25, 2023

GPT4 and GPT5 are revolutionising the software engineering world and software testing world day by day. Playwright (Typescript) with multiple AI supporting 3rd party providers is looming up to become one of the best testing tool prospects to cater the AI integration requirement.

One of the most prominent libraries to support the feature at the moment for playwright typescript wrapper is ‘ZeroStep’ (unlocks the power of AI with GPT3.5 and GPT4). In this article let’s have a look at how to set up ‘ZeroStep’ and how to quickly perform the actions without worrying about html element locators.

  1. How to Setup

Install the @zerostep/playwright dependency.

$ npm i @zerostep/playwright -D

This package relies on an environment variable with your zerostep token being exposed to the playwright process. This token can be found in your account on https://app.zerostep.com. Do this however you’d like, e.g.

$ export ZEROSTEP_TOKEN=”<your token here>”

2. Simply integrate with Playwright Test Script

Import and use the ‘ai’ function. Example:

SourceDemo Application Test Script

3. How to optimise the code with Playwright Fixture

The zerostep/playwright library ships with a playwright fixture out of the box. This allows you to call ai() steps without passing the { test, page } argument every time which makes the test script code clean. You can use the playwright docs as a guide to get setup, but here's some example code

Playwright Fixture
Playwright Test Script Leveraging Fixture

Once you see the latest code you will see it is much nicer and cleaner with the use of Playwright fixture.

ZeroStep is a commercial library however, there are two categories.

First one is the Free version which allows you 1,000 ai() function calls per month for Free and allows access to unlimited users.

Keep in mind an instance of ‘ai’ method in your test script is one function call. Thus, be mindful with how you plan to leverage the facility if you are planning to use the free option. (Recommend to come up with a hybrid approach to use the feature effectively in the actual test scripting frameworks.)

There is a Second option. This option starts with a cost of 20$ per month supporting 2,000 ai() function calls per month for unlimited users. And this option can be customised based on the function calls you need in your project or in your company.

Please refer the the below two official sites for more information.

Official Site: https://zerostep.com/

Git repository: https://github.com/zerostep-ai/zerostep

Happy testing. Future is today…

Cheers & Stay tuned for Part 2 for more content.

--

--