Untitled
unknown
csharp
2 years ago
2.8 kB
7
Indexable
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using System;
using Xunit;
public class AppointmentFormTests : IDisposable
{
private IWebDriver driver;
private WebDriverWait wait;
public AppointmentFormTests()
{
// Set up the WebDriver
driver = new ChromeDriver();
wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
}
[Fact]
public void SubmitAppointmentForm_Success()
{
// Navigate to the application
driver.Navigate().GoToUrl("URL_OF_YOUR_APPLICATION");
// Locate and fill the form fields
FillForm();
// Submit the form
driver.FindElement(By.Id("btnCreateAppointment")).Click();
// Wait for alert to be present
wait.Until(ExpectedConditions.AlertIsPresent());
// Switch to the alert and accept it (click OK)
IAlert alert = driver.SwitchTo().Alert();
alert.Accept();
// Wait for success message or any other element that indicates success
wait.Until(ExpectedConditions.ElementIsVisible(By.Id("successMessage")));
// Assert the success message or check for any other success criteria
Assert.True(driver.FindElement(By.Id("successMessage")).Displayed);
}
private void FillForm()
{
// Fill in the form fields with appropriate data
driver.FindElement(By.Id("mobilePhone")).SendKeys("1234567890");
driver.FindElement(By.Id("fullName")).SendKeys("John Doe");
// Select options in dropdowns
SelectElement hairdresserDropdown = new SelectElement(driver.FindElement(By.Id("hairdresserId")));
hairdresserDropdown.SelectByText("Hairdresser Name");
SelectElement serviceDropdown = new SelectElement(driver.FindElement(By.Id("serviceId")));
serviceDropdown.SelectByText("Service Name");
SelectElement paymentMethodDropdown = new SelectElement(driver.FindElement(By.Id("paymentMethod")));
paymentMethodDropdown.SelectByText("Pix");
// Set date and time if needed
driver.FindElement(By.Id("bookDate")).SendKeys("2024-01-30"); // Example date
SelectElement hourDropdown = new SelectElement(driver.FindElement(By.Id("hour")));
hourDropdown.SelectByIndex(1); // Example index
// Store selected date and time in hidden field (if applicable)
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("document.getElementById('selectedDateTime').value = '2024-01-30 10:00 AM';"); // Example date and time
}
public void Dispose()
{
// Close the browser after the test
driver.Quit();
}
}
Editor is loading...
Leave a Comment