arbisoft brand logo
arbisoft brand logo
Contact Us

Using AI LLMs and Playwright MCP to Convert Prompts to Working Test Automation

Asfa 's profile picture
Asfa AkbarPosted on
6-7 Min Read Time

Artificial Intelligence (AI) is evolving in every field of life. There is no doubt that AI is making things easy for you. In SQA, AI has brought testing into a new shape. Now, SQA can perform software testing more smartly. More fun to test and easier to test than before.

 

It is possible with AI that natural language prompts can be transformed into fully functional automated test scripts in seconds. You don't need to type lengthy lines of code. This is the whole game-changer for SQA. Now, an SQA Engineer can provide a plain English language test case, and Artificial Intelligence (AI) will provide its automated test scripts. AI will do smart work for you in no time.

 

In this blog, we will dive into how AI is doing this smart work together with LLMs and Playwright (MCP).

 

What are Large Language Models (LLMs)? 

LLMs stand for Large Language Models. LLMs are a type of AI program. They are text completion programs. They are trained to understand human language and produce results. These models are trained on a huge set of data, which is why they are referred to as large language models. These models can predict text, recognize data, and respond accordingly. 

 

Examples of LLM models are:

  1. Chat GPT.
  2. Claude.
  3. Gemini.
  4. Llama.
  5. Bring chat.

 

These LLM tools are effective for:

  • Understanding natural language prompts. 
  • Compiling and generating code.
  • Converting natural language into code. 
  • Explaining the logic.
  • Problem solving.

What Is an MCP Server?

MCP stands for Microsoft Cloud Platform. It is a backend system that receives the prompt in natural language and converts it into code. You provide the prompt in an AI tool, the MCP server receives the prompt and converts that natural language prompt into code.

 

It is specially used in tools like:

  1. Playwright.
  2.  selenium IDE + AI plugin.
  3. Mabl. 
  4. Testim.
  5. Functionize.

 

What is Playwright MCP?

A Playwright is a powerful end-to-end framework for testing web apps. It is developed by Microsoft. 

A Playwright MCP is a model conversion platform. It automatically converts plain English language prompts into playwright test scripts. It is like an AI assistive tool that helps in writing code by interpreting your instructions given as a prompt. 

 

Support Browsers:

  • Chrome. 
  • Firefox. 
  • Safari.

 

Key points:

  • Playwright test scripts are in JavaScript or TypeScript. By default, it is JavaScript code.
  • It reduces the manual testing effort.
  • It speeds up the automation testing. 
  • It improves the test coverage. 
  • It reduces the manual script errors. 
  • It makes the testing efficient with no repetitive coding. 

 

blog image .png

How Do AI LLMs and Playwright Work Together To Generate Code?

AI LLMs and Playwright are a great combo; they together interpret and generate code.

 

The following are the steps:

1. Write the prompt 

  • A user will write the prompt in simple English language describing a test scenario.
  • Verify the login functionality with valid credentials and ensure it redirects to the dashboard.

2. LLMs understand and interpret the prompt

After understanding the prompt, LLMs will identify its key actions (click, assert, input) and generate the code.

  • Go to the login page.
  • Add username and password.
  • Click on the login button.
  • Verify that the user is successfully logged in.
  • After logging in, the user is redirected to the dashboard.

3. Playwright MCP will generate the code

Code is generated by Playwright after LLMs interpret the prompt.

4. SQA role

  • Run the code script in the Playwright test runner.
  • Integrate into CI/CD pipelines.

 

Here is the example output of the given prompt:
Verify the login functionality with valid credentials and ensure it redirects to the dashboard.

 

blogimage 3.png

 

Real-World Use Cases

Here are the real-world use cases for an e-commerce website where Playwright MCP testing can be applied:

Test targeted testing website: automationexercise.com
Tool: Playwright MCP

1. Smoke Testing

A user can write a prompt for testing the happy paths of the testing application.


Use case: Verification of login, logout, navigation, and page loads.

Blogimage4.png

2. Regression Testing

It is helpful for regression testing as users do not need to manually update all the test cases. Instead, a user can write a prompt for testing the impacted areas of the application.


Use case: Verification of changes made to the cart UI.

 

BLOGIMG 5.png

3. Cross-Browser Testing

Once the scripts are generated, you can run them in different browsers and verify their cross-browser compatibility without writing separate configurations manually. Just one prompt is needed to test it on a supported browser.


Use case: Run the same test on different browsers.

 

blogimg6.png

4. Exploratory Testing

For exploratory testing, a user can write a prompt as an experienced QA and ask for creating flows and generating scripts using AI suggestions.


Use case: Write test cases for product filtering.

 

BLOGIMG7.png

5. Accessibility Testing

A user can write a prompt to check that all buttons are accessible via keyboard navigation. AI can generate test scripts for accessibility checks.


Use case: Verify the accessibility of buttons.

 

BLOGIMG8.png

6. Test Maintenance

AI models, together with Playwright MCP, recommend better selectors, locators, IDs, and classes in the code.


Use case: Refactor test cases with better selectors and locators.

 

BLOGIMG9.png

7. End-to-End Testing

Instead of spending hours writing end-to-end test scripts, AI can generate them very quickly with the help of simple prompts.


Use case: Full flow of the application from login to add to cart, then checkout.

 

BLOGIMG10.png

8. Localization and Multi-Language Testing

A user can test the same flow in different languages with a simple prompt. AI can change language selectors and assert translated text automatically.


Use case: Verify the application in different languages like German and French.

 

BLGIMG11.png

In The End

The future of test automation is not just about writing code, it's about prompting it. As an SQA engineer, using LLMs together with Playwright makes software testing much more efficient and improves testing coverage. You don't need to write code, but you do need to write a great prompt for testing efficiently. So, if you haven't already worked on it, start exploring and experimenting in the AI testing world.

...Loading Related Blogs

Explore More

Have Questions? Let's Talk.

We have got the answers to your questions.