How to automate testing of forms?

Hi. Noob question here: I want to create a script that tests form validation. Example: I want to make sure a required text field results in an error if it’s left blank. I can use your recorder, which does record accurately what I, the user, do on the form. But the recorded steps only show what I do, not whether what I do is successful or not.
Looks like a fantastic product, by the way.

1 Like

Try/read this:

Basically, in order to check if your test step was successful, you need to “assert” something. For example, “when I do this, text field will be blank”.

In your case, you could use someText = WebUI.getText(findTestObject(‘your text field’)) and then assert it is empty by comparing it with an empty string:
WebUI.verifyMatch(someText, ``" "``, false)

Hi Donna,

You can you can use assertValue command in the recorder. It checks the text field’s value.

Command: assertValue
Target: your text field’s locator
Value: sample text

so, if its left blank or wrong inputted text, when the assertValue checks it, it will return a failed result because it’s not equal to the declared expected value.

I missed to look at the category, very sorry…

You can also use this approach in the studio:

WebUI.verifyElementText(findTestObject(‘your text field locator’), ‘sample text’)
*it will return a failed result also if its left blank or wrong inputted text.

You can also do an assert in studio, just import junit.framework.Assert and do this code

WebElement findTextField = WebUiCommonHelper.findWebElement(findTestObject(objectPath), 30)
AssertEquals(findTextField.getAttribute(‘value’), ‘sample value’)
*it will also return a failed result if its left blank or wrong inputted text.

I have successfully used assertText command for this purpose