Revolutionizing AI Test Automation: Using NLP and Prompt Language with AI
HISTORY OF AI
John McCarthy coined the term "artificial intelligence" in 1956 at the Dartmouth Summer Research Project on Artificial Intelligence, and drove the development of the first AI programming language, LISP, in the 1960's , Artificial Intelligence, refers to using computer systems to perform tasks that would typically require human communication. Followed by AI is created by combining data, algorithms, and computational power to enable machines to perform tasks that typically require human intelligence.
INTRODUCTION
Using AI for automation and manual testing in the different areas and scenarios and how we can reduce our time and effort so work with Ai we have to know a proper prompting, Examples of AI applications include expert systems, natural language processing (NLP), speech recognition and machine vision.
EVERYDAY EXAMPLES OF AI
Text editing and autocorrect.
Social media.
Transportation and navigation.
fraud prevention
WHAT IS NLP
Natural language processing (NLP) it acts like bridge between human communication and computer understanding, teaching computers how to "read" and "write" in our languages,
1. AUTOMATE SCRIPTS USING AI WITH NLP
Automating scripts through AI makes easier the tester to get the code in a seconds it will reduce the time and energy, By using Natural language processing (NLP) pipeline engine we can send requirements to an NLP model then its generates test cases automatically, it keep getting smarter and improves testcases automatically

USER PROMPT IN TEXT FILE
verify the url https://petstore.swagger.io/v2/pet/1 for getVerify Response status code is 200Verify Content type is application/jsonVerify Id is a non-negative integerVerify Name is a non-empty stringVerify PhotoUrls array is present and not emptyVerify Tags array is present and not empty The small piece of USER PROMPT called prompt-to-Action pipeline, user prompt is given in simple plain English words to understand the AI and save as text file, Automatically turning simple English words to generate the tests.
FRAMEWORK OF NLP
This is basic framework of NLP , "nlp-testng-framework," likely uses AI (OpenAIClient) to help with testing (NLPTests using TestNG). It has open AI logic, a base test class, actual tests, and utilities (like reading test data). Maven manages dependencies, and TestNG runs the tests defined in testng.xml, using test cases from testcases.txt. Test results will be in the test-output directory.

This pom.xml defines a Maven project named "nlp-testng-framework" that uses TestNG for testing. Maven for managing dependencies and the build process.
This text file as plain English words to understand the NLP and generate the tests and save as textcases.txt,
Each line is one "test case description".

The test data reader. java code to Read Text and Create TestNG tests, It reads all data from testcases.txt

The base test to sets up and tears down the browser for every test.

This OpenAIClient class handles communication with the OpenAI API to generate test steps from user prompts,

For this we have to create a API_KEY through URL:https://platform.openai.com/api-keys
and it pop-up window there give a name and it make key then it connects API and connects

API_URL = "https://api.openai.com/v1/chat/completions"; The method takes a prompt, constructs a JSON request body with the prompt for the "gpt-3.5-turbo" model, sends a POST request to the OpenAI API with authorization, and then likely processes the API response to generate test steps.
The NLPTests class has TestNG tests that provideTest Cases method, using the @DataProvider annotation, reads test case from "testcases.txt". @DataProvider, takes a test case prints it, uses the Open AI Client to generate a test step based on the description, testng.xml defining the test suites, tests, classes, and methods to be executed.

To see the generate steps right click run Test ng to see output from Testng.xml , testng.xml defining the test suites, tests, classes, and methods to be executed.

Here is the clear TestNG report shows the steps generated and passed.


ADVANTAGES
Faster test creation
Increased test coverage
Reduce maintenance
Earlier defect detection
AUTOMATING THE SCRIPTS USING PROMPT LANGUAGE
Automation script using prompting, Instead of building traditional NLP pipelines now here using prompt language to get response ,A prompting means we can give proper instructions to the AI can analyze our instructions and it give response in proper way is called prompting .

user story creation using AI by prompt - for this we want requirement
prompt: crate user stories for the following requirements
Requirement is As a User i should login ecommerce application so that user can access all tech features from the application (when we give this prompt to AI it will generates User stories)
NOTE: Review the code, If you feel the code is correct whatever you want then copy and paste .

b. Test Automation Script writing
prompt: write automation test script using selenium with java and Testng for following testcase
testcase: successful User registration (When we give this prompt to AI it generates test scripts)

1. Like this we can go for syntax and logical error detection and correction, X path locators when we copy paste URL of UI and give proper prompt it will give all X path locators of page, if prompt is correct we can see specific results, if prompt is not correct we have to search for more reviews and modifications.
2 we can understood sometimes reviewing code is also more difficult, let's say some testers or developers write the code in very complex and we can't get it then we can ask AI to explain the code, it will explain each and every statement written the code, no one need to explain we can know by reading.
3. You can utilize this whenever it is needed in automation very useful and mainly it will reduce or effort and time especially when you create pom and utility files ,so lot of effort will be reduced and for manual tests more easier because a lot of documentation is involved
USING AI IN AUTOMATION ADVANTAGES:
we need to create test plans, test cases, user stories, templates, Gherkins, step definitions. so AI ca will give you within minutes and seconds everything will be done.
Happy Learning ! 😊


