I am testing form validation with selenium using C#. I have a update button that when clicked pops up a form with the users previously enter info. I am trying to test a user trying to submit an empty update form by finding the element and clearing the field. When submitting a form with empty values, I have validation errors that should display under the field. This works when running my program manually. When running my test, I can see that the fields are being cleared but when I hit submit, my form is repopulating with the data that had previously been there. I have also tried to clear the form, then in an empty string for the keys but it still repopulates the form when I hit submit. I also tried to clear the form and then fill it in using special characters to prompt a different error message. The form is clearing but then it is taking the value that was entered before and putting the special character to the end of that value. Here is part of my code:
var user = new Users(driver);
user.EditUserByEmail("pinocchio@aol.com");
driver.FindElement(By.Name("firstName")).Clear();
driver.FindElement(By.Name("lastName")).Clear();
driver.FindElement(By.Name("email")).Clear();
user.EnterFirstName("$");
user.EnterLastName("$");
user.EnterEmail("$");
var modal = new Modal(driver);
modal.SubmitForm();
These are the methods I am using in the Users class:
public void EnterFirstName(string firstName)
{
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
var firstNameInput = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.Name("firstName")));
firstNameInput.SendKeys(firstName);
}
public void EnterLastName(string lastName)
{
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
var lastNameInput = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.Name("lastName")));
lastNameInput.SendKeys(lastName);
}
public void EnterEmail(string email)
{
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
var emailInput = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.Name("email")));
emailInput.SendKeys(email);
}
The form clears and then this is what is entered in: 
By my code I would expect each field to just be entered with a $. I don't know how or why the previous data is repopulating.
Aucun commentaire:
Enregistrer un commentaire