Selenium Testing: How to Check Error Messages for a Component in Binder Val

Hello,

I am working on adding Selenium 3 and JUnit 5 tests to my team’s project in order to test basic form validation. Just to note in advance, we are not able to use TestBench as an alternative to Selenium because we are using the Core Version of Vaadin (Currently on LTS 14.5.1)

To start, I have a basic TextField that stores a Person’s name (required). Below is the Binder I have set to this component:

binder.forField(first_name)
	.asRequired("First name is required")
	.withValidator(new StringLengthValidator("First name must be between 1 and 50 characters", 1, 50))
	.bind(Person::getFirst_name, Person::setFirst_name);

For the Unit Tests, we can check and confirm that the error message below the component appears when too many characters are entered into the field by performing the following: (The TextField is initially populated with a value retrieved from our database.)

WebElement first_name = webDriver.findElement(By.xpath("[path_to_component's input]
"))"
first_name.clear();
first_name.sendKeys("[helper method to populate the field to over the binder limit]
");
WebElement invalidText = driverWait
				.until(ExpectedConditions.presenceOfElementLocated(By.xpath("[path_to_error_message"]
")));
assertEquals("First name must be between 1 and 50 characters", invalidText.getText());

However, I can’t seem to do the same in order to test for an empty value entered to the field, even though the binder requires a non-null/empty value. If the test script uses first_name.clear() or first_name.sendKeys(""), the text in the error field does not update to the binder’s invalid message, “First name is required.” This also does not happen when the script clicks the Button component that is meant to trigger the binder.writeBean() validation portion of the form; the error message that is supposed to show up (“First name is required”) does not appear and the system proceeds as if the TextField was not updated to an empty String via sendKeys("")

What steps am I missing to be able to use Selenium to check empty/missing input on required/bound fields?

Thanks for the help in advance.

Hello,

Wanted to bump this question back up to see if anyone had any insight on this.

If not, I plan to post the question again in the near future.

Thanks!