Please post your Web Driver questions in official Web Driver forum

Sunday, September 18, 2016

Action and Operation APIs

If you have been following page object pattern then you would have been abstracting page level operations in its own APIs. I usually write two types of page operations -


Action API - one which are very granular and focus only on actions on one element Operation API - which can either combine various actions and constitute bigger operations or could call just one action API.


For example when clicking on a link returns a new page object then following action API illustrates it -

public MemberProfilePage clickNameLinkofFirstMember() {
linkElement.click()
return new MemberProfilePage()    
}


And Operation API could be as simple as just invoking one action API -


public MemberProfilePage acessFirstMemberProfile() {
return clickNameLinkofFirstMember()
}

Or operation API can combine various action APIs to derive a workflow -


@Test
public void shouldDsplayUpdatedNameWhenFirstNameIsChanged () {
MemberProfilePage memberProfilePage = new MemberProfilePage().changeFirstName(newName)
assert memberProfilePage.equals(newName):"Wrong member name";              
}


And the workflow can be used in automated test -


@Test
Public void shouldDsplayUpdatedNameWhenFirstNameIsChanged () {
MemberProfilePage memberProfilePage = new MemberProfilePage().changeFirstName(newName)
assert memberProfilePage.equals(newName):"Wrong member name";

}

Fork me on GitHub