PumpITup's Guide to ChatGPT and Automated Testing

PumpITup's Guide to ChatGPT and Automated Testing

If you missed our latest Meetup event, there are 3 things you can do about it:

1.??????weep

2.??????watch the recording

3.??????read this informative summary

No alt text provided for this image

If you attended the event, you know that our demo didn’t work out as expected.

Well, if anything, we've learnt that ChatGPT is not almighty.

We still believe though, that the positives of using this powerful tool outweight it's occasional failures. To convince you of this, we’ve prepared an A-Z write-up of the best ChatGPT’s use cases for testers.

Can’t wait? Read on!


No alt text provided for this image

Artificial intelligence is transforming the way we approach software testing, offering exciting new possibilities for testers. OpenAI's ChatGPT is one such powerful tool that can generate code and provide useful information. In this article, we will explore how to use ChatGPT effectively, and provide practical examples of its application in automated testing and other tasks that software testers perform daily.


No alt text provided for this image


Understanding ChatGPT

ChatGPT is an advanced language model developed by OpenAI that leverages deep learning algorithms to generate realistic, human-like responses. It has been trained on vast amounts of data from the internet (with a knowledge cutoff of September 2021). Although highly capable, ChatGPT may occasionally generate plausible-sounding but incorrect or nonsensical answers. Always keep this in mind.?

Writing Prompts for ChatGPT

To get the most out of ChatGPT, follow these guidelines when crafting prompts:

1. Define AI's role: Clearly state the role you want the AI to play, e.g., "Act as a poet."

2. Use it for common tasks: Utilize ChatGPT for everyday tasks like generating test steps or troubleshooting.

3. Provide context: Give enough background information for the AI to understand the task.

4. Be precise: Ensure your prompt is specific and clear.

5. Keep trying: If the initial response isn't satisfactory, refine the prompt and try again.


No alt text provided for this image

? > Prompt example: Act as a poet and write a short poem about the joys and challenges of software testing, focusing on the theme of perseverance and attention to detail. Make sure to mention the importance of finding and fixing bugs to ensure the quality of the final product.


Creating Automated Tests with ChatGPT and Playwright

No alt text provided for this image

Playwright is a popular framework for web testing and automation that allows reliable end-to-end testing for modern web apps. Using Playwright's Codegen feature, you can generate test steps for test cases like "Add Items to Cart and Clear Cart."

?1. Generate basic test with Playwright's Codegen:

Use Playwright's Codegen to generate a basic test by manually navigating through the UI and clicking on web elements.

  1. Start the codegen with the command: `npx playwright codegen yourwebsite.com`
  2. Record the manual test execution and observe how the test code is generated.
  3. Save the generated test.

2. Create page object models:

Use ChatGPT to rewrite basic test and create page objects.

  1. Create a prompt for ChatGPT (use GPT-4 for best results). Ask it to act as a test developer and specify the code language and framework you are using. Mention that you want to create page object models for your test.
  2. Paste the generated test from Codegen into the ChatGPT prompt.
  3. Check the response. If locators are wrong, regenerate the response or edit your prompt.

??>?Prompt example: Act as a test developer using JavaScript and Playwright. Create page object models for the following test steps generated by Playwright's Codegen: [Paste your generated test steps here]

3. Generate test conditions:

Use ChatGPT to create the necessary test conditions for your test case.

  1. In the web browser's inspect mode, choose an element you want to include in your test condition.
  2. Copy the element attributes to the ChatGPT prompt.
  3. Add more details to the prompt, asking ChatGPT to create, for example, an if-else condition that checks the value or the text of the element.
  4. Copy the generated code and paste it into your Playwright test file.

??> Promt example: Act as a test developer and create an if-else condition for my test using JavaScript and Playwright. The condition should check the value of the following HTML element: [Paste your copied element attributes here]

?

No alt text provided for this image

Leveraging AI in Your Daily Job as a Tester

ChatGPT can be incredibly useful for various tasks in your daily work as a software tester:

1. Generating test steps: Ask ChatGPT to act as a test developer and generate test steps for a specific test case, e.g., "User login to e-shop (amazon.com) and select two items."

2. Creating step-by-step guides: Request ChatGPT to generate installation guides, such as "How to install Playwright? Make a step-by-step guide for me."

3. Troubleshooting: Use ChatGPT for help with error messages, e.g., "I am getting this error message. How can I solve it?"

4. Test strategy consulting: Seek ChatGPT's assistance in formulating test strategies, e.g., "Act as a test analyst. Give me ideas on how to test an e-shop."

Give it a try

ChatGPT offers a wealth of potential for software testers, streamlining tasks and improving efficiency. By using ChatGPT in combination with tools like Playwright, testers can create various aspects of their work, from creating automated test in a few minutes to getting step-by-step guides to help them. Embrace the power of AI and revolutionize your software testing process.


Do you have your own examples of how to use the AI tool to your benefit? Let us know in the comment

Jakub Bene?ovsky

Test Automation Engineer ve spole?nosti Tesena

1 年

Viktória Fri?ová You made it so cringe with all the gifs. I like it.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了