Universal Set Value

Use setValue on a declared page element to set its value. It will work on all the standard input types out of the box.Define all the input fields inside a page object. In combination with universal setValue it will make your tests robust.Given a html snippet <html> <body> <div id="form"> <input id="name" /> <input id="startDate" type="date" /> <input id="confirmation" type="checkbox" /> <div id="choice-group" class="radio-group"> <div> <input type="radio" id="one" name="choice" value="value-one"/> <label for="one">one</label> </div> <div> <input type="radio" id="two" name="choice" value="value-two"/> <label for="two">two</label> </div> <div> <input type="radio" id="three" name="choice" value="value-three"/> <label for="three">three</label> </div> </div> <select id="rank"> <option /> <option value="A">Full A</option> <option value="B">Full B</option> <option value="C">Full C</option> <option value="D">Full D</option> <option value="E">Full E</option> </select> </div> </body> </html> Page object can be defined as package pages import static org.testingisdocumenting.webtau.WebTauDsl.* class FormPage { def name = $('#name') def rank = $('#rank') def confirmation = $('#confirmation') def choice = $('[name="choice"]') def startDate = $('#startDate') }

Default Input

form.name.setValue('Full Automation')

Date Input

form.startDate.setValue('2016-06-21')

Select

form.rank.setValue('B') form.rank.setValue('Full B')

CheckBox

form.confirmation.setValue(true)

Radio Button

form.choice.setValue('value-two')

Universal Assert

Form element value can be asserted the same way as any regular element. Underlying value will be extracted based on the element type form.name.should == 'Full Automation' form.rank.should == 'Full B' form.confirmation.should == true form.choice.should == 'value-two' form.startDate.should == '2016-06-21'

Custom Form Elements

One of the benefits of universal set and assert is that your test is focused on the data and not implementation details. But what if you decided to use a custom component to enter the data?To hide implementation details from your test you should define a custom input handler for your UI component.Let's consider a form component that you can start interacting with only after you clicked it. And after the value is entered, the input box disappears again. <div id="answer" class="special-selector" onclick="activate('answer')"> <div class="current-value"> current value </div><input class="value-input" value="" onblur="valueEntered('answer')"> </div> Our test should still be written in terms of data entering and validation. def customFormElement = $('#answer') customFormElement.setValue('hello') customFormElement.should == 'hello' In order to achieve this we need to register a custom handler. package scenarios.ui import static org.testingisdocumenting.webtau.WebTauGroovyDsl.* scenario('open forms') { browser.open('/special-forms') } scenario('get set custom based on registered handler') { def customFormElement = $('#answer') customFormElement.setValue('hello') customFormElement.should == 'hello' } package formHandlers import org.testingisdocumenting.webtau.browser.page.HtmlNodeAndWebElementList import org.testingisdocumenting.webtau.browser.page.PageElement import org.testingisdocumenting.webtau.browser.page.PageElementStepExecutor import org.testingisdocumenting.webtau.browser.handlers.PageElementGetSetValueHandler import org.testingisdocumenting.webtau.reporter.TokenizedMessage import static org.testingisdocumenting.webtau.WebTauDsl.browser class CustomInput implements PageElementGetSetValueHandler { @Override boolean handles(HtmlNodeAndWebElementList htmlNodeAndWebElements, PageElement pageElement) { def htmlNode = htmlNodeAndWebElements.firstHtmlNode() return htmlNode.attributes().class =~ /special-selector/ } @Override void setValue(PageElementStepExecutor stepExecutor, TokenizedMessage pathDescription, HtmlNodeAndWebElementList htmlNodeAndWebElements, PageElement pageElement, Object value, boolean noLog) { pageElement.click() pageElement.find('input').sendKeys("${value}" + browser.keys.tab) } @Override Object getValue(HtmlNodeAndWebElementList htmlNodeAndWebElements, PageElement pageElement, int idx) { return pageElement.find('.current-value').extractSingleValue() } }