← Back to Blog

Test Automation Example using GPT 4.0

Test Automation Example using GPT 4.0 Create a page `<!DOCTYPE html> A&E Hospital Patient Form body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background-color: #f2f2f2; } .container { max-width: 600px; margin: 0 auto; padding: 20px; background-color: #fff;

Test Automation Example using GPT 4.0

Create a page

test automation example 1

`<!DOCTYPE html>

A&E Hospital Patient Form

A&E Hospital Patient Form

`

Sample Data

test automation example 2

Business Rules

  • Patient has to select at least one of the options.

  • If nothing is selected there would be an alert.

**The Test use case should check **

  • There cant be any submissions without selecting the options

Reference

https://chatgpt.com/c/01e0f143-e399-4cb1-8a6f-0c8508376d2c

Second iteration

`<!DOCTYPE html>

A&E Hospital Patient Form

A&E Hospital Patient Form

`

**Updated version **

using OpenQA.Selenium;
                using OpenQA.Selenium.Firefox;
                using System;
                
                class Program
                {
                    static void Main(string&#091;] args)
                    {
                        IWebDriver driver = new FirefoxDriver();
                
                        try
                        {
                            driver.Navigate().GoToUrl("file:///C:/Users/Pexabo/Downloads/care.html");
                
                            driver.FindElement(By.Id("patientName")).SendKeys("Erdem");
                            Thread.Sleep(1000);
                            driver.FindElement(By.Id("hospitalName")).SendKeys("Addenbrooks");
                            Thread.Sleep(1000);
                
                            driver.FindElement(By.Id("address")).SendKeys("Petersfield Mansions CB1 1BB Cambridge");
                            Thread.Sleep(1000);
                
                            driver.FindElement(By.Id("patientSituation")).SendKeys("I have a chest pain");
                            Thread.Sleep(1000);
                
                            try
                            {
                                driver.FindElement(By.CssSelector("button&#091;type='submit']")).Click();
                                IAlert alert = driver.SwitchTo().Alert();
                                string alertText = alert.Text;
                                alert.Accept();
                                Console.WriteLine("Alert displayed as expected: " + alertText);
                            }
                            catch (NoAlertPresentException)
                            {
                                Console.WriteLine("No alert displayed when triage is not selected.");
                            }
                
                            driver.FindElement(By.CssSelector("input&#091;value='chestPain']")).Click();
                
                            try
                            {
                                driver.FindElement(By.CssSelector("button&#091;type='submit']")).Click();
                                IAlert alert = driver.SwitchTo().Alert();
                                string alertText = alert.Text;
                                alert.Accept();
                                Console.WriteLine("Alert displayed as expected: " + alertText);
                            }
                            catch (NoAlertPresentException)
                            {
                                Console.WriteLine("No alert displayed when no checkbox is selected.");
                            }
                
                            driver.FindElement(By.CssSelector("input&#091;value='headInjury']")).Click();
                
                            driver.FindElement(By.CssSelector("button&#091;type='submit']")).Click();
                
                        }
                        finally
                        {
                            driver.Quit();
                        }
                    }
                }
                
                

Imported from rifaterdemsahin.com · 2024