2011-05-22

iPhone UI Automation and the Page Object pattern

At the time when I was actively contributing to Selenium I used it only in conjunction with FitNesse and could therefore not directly apply the Page Object pattern. However, one of the key principles was for me the abstraction of the UI elements by creating UI maps which contain simple mappings of logical names to XPath path expressions.

The Page Object pattern defines the same abstraction: Define and use UI elements only in one module, and provide only service functions to the test cases.
Instead of diving deeper into theoretical details here is an example:

#import "Common.js"

function LoginView() {
    this.loginCells = window.tableViews()[0].cells();
    this.loginField = this.loginCells["loginFieldCell"].textFields()["loginField"];
    this.passwordField = this.loginCells["passwordFieldCell"].secureTextFields()["passwordField"];
    this.loginButton = this.loginCells["loginButtonCell"].buttons()["loginButton"];

}

LoginView.prototype.login = function(user, password) {
    this.loginField.setValue(user);
    this.passwordField.setValue(password);
    this.loginButton.tap();
}

LoginView.prototype.waitForDisappear = function() {
    this.loginField.waitForInvalid();
}
So a test looks like as follows:

#import "../TestControllers/LoginView.js"
#import "../TestControllers/UserDetailView.js"

var loginView = new LoginView();
var userDetailView;

test("Valid login leads to user detail page", function(t, a) {
    loginView.login("andras_hatvani","password");
    loginView.waitForDisappear();
    userDetailView = new UserDetailView();
    userDetailView.assertUserData("andras_hatvani", "Andras Hatvani");
},options)};

Although I use tuneup_js as test framework in this example, it could be Jasmine or a custom framework.
Important is that I could formulate the tests in a business-like language i.e. in an own DSL, thus it is not only straightforward to write, but also to read. Furthermore, if the UI changes, then I only need to adapt one single unit, namely LoginView.js to make my tests run again.

6 comments:

  1. Nice information about iPhone UI Automation and the Page Object pattern.People willing to get the indepth knowledge in getting framework such as TestNG,jenkins,Maven and POM should get properly get best selenium training in chennai

    ReplyDelete
  2. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.. Selenium Training in Chennai

    ReplyDelete
  3. Excellent explanation about iphone technology., its very interesting to read.. Thanks for sharing such a nice article. Dot Net Training in Chennai | Java Training in Chennai

    ReplyDelete
  4. Nice and good article.. it is very useful for me to learn and understand easily.. thanks for sharing your valuable information and time.. please keep updating.


    Software Testing Training in chennai | Android Training in chennai

    ReplyDelete
  5. Awesome Blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a nice blog. Selenium Training Institute in Chennai | ISTQB Training Institute in Chennai | Six Sigma Certification Training in Chennai

    ReplyDelete