Watir is lightweight browser driver built in Ruby. Watir holds ATDD ideology where tests are easy to read and maintain. Tests are based to scenarios written with Gherkin. Step definitions will contain Ruby code which drives web browser like normal user e.g. open browser, goto web page, click some button, write text to fields and select checkbox. Very cool indeed. Here some example lines:
browser = Watir::Browser.new
browser.goto 'http://www.google.com'
browser.button(:name => 'submit').click
browser.text_field(:name => 'somefield').set "some text"
browser.checkbox(:value => 'Watir').set
See more examples herePair coding
We continued practices from last week. Our instructor has been done scenarios and code implementation to ready so we could test something. Good job. From those scenarios we created skeletons to step definitions which we started to complete with test implementations. Implementation was not so trivial even Ruby syntax look readable. Our computer was the Mac and seems it was not so familiar most of us ;) Also Ruby syntax and how to define methods with it etc. were uncertain. Implementation happened quite well after we get familiar with basics of Mac and Ruby. Purpose of this coding dojo were to test user account creation form. Tests should ensure that the required text fields are not empty after submit button click. After button click the test should also check that user account really exists in system.
Validation of required fields gives an error message to the screen which contains number of missing fields and under it the name list of missing fields. We could use the error message text as a criterion for the test result. In this way we cannot get information which fields doesn't meet the validation rules. This approach could be harmful in later if validation of fields are changed so that some field are not required anymore e.g. first name is optional. If not required and some required field has not been filled after submit process then we need in the test to find out which fields are required and not. So the better solution could be use the name list of missing fields to solve test result.
During implementation we found that table lookup were quite heavy and hard to done. We decide that system under test need to be updated for the test methods. We needed user identifier for each table row to find user account information from table easily to ensure that user data is really stored in the system. After the changes test implementation were easy to implement. This is a good idea to keep in the mind when making tests. It is pointless to implement complicated tests if the changes are easier to implement to the system under test.
This coding dojo was very good. I got many ideas how to improve my own working. I decide to study Watin soon. Watin is .NET implementation of Watir. Here is easy example:
[Test]
public void SearchForWatiNOnGoogle()
{
using (var browser = new IE("http://www.google.com"))
{
browser.TextField(Find.ByName("q")).TypeText("WatiN");
browser.Button(Find.ByName("btnG")).Click();
Assert.IsTrue(browser.ContainsText("WatiN"));
}
}
