Test Automation Example using GPT 4.0
Create a page

`<!DOCTYPE html>
A&E Hospital Patient Form
`
Sample Data

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
`
**Updated version **
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
class Program
{
static void Main(string[] 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[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[value='chestPain']")).Click();
try
{
driver.FindElement(By.CssSelector("button[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[value='headInjury']")).Click();
driver.FindElement(By.CssSelector("button[type='submit']")).Click();
}
finally
{
driver.Quit();
}
}
}
Imported from rifaterdemsahin.com · 2024