Skip to main content

Posts

Showing posts from September, 2016

When page object returns more than one type of page object

If have have been working with test automation then you would have probably heard of page objects . In a gist, page object provides clear separation of responsibility between who is responsible for testing (test classes) and who is responsible for services provided page (page classes). Page objects are known to return objects of same page when control retains on same page or another page object when operation on one page return object of another page. For example typing in a text box would keep control on same page (hence same page object) but submitting a form with valid data would most probably load a new page (hence a new page object). But what if return type of Page Object is not fixed. For example for A/B variations, user may be directed to one of many possible variation of a page. Hence the resulting page is a page object but you don’t know for sure which age object. This is where java generics comes for rescue, and to be more specific generic methods. Before delving i

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 = ne

Using JSONobject and JSONarray for parsing json

Did you ever wonder why sometimes you have json with curly brackets while sometimes with square brackets? This is because you were dealing with JSON object and arrays respectively. JSON array organizes collection of related items which can be json object in themselves - [{"name":"item 1"},{"name": "item2} ] JSON object usually contains key/value pair of related item. For ex - {"name": "firstname", "dateOfBirth":"65475645"} We used Jackson parser in API video tutorial but if you don’t need entire data set from json response of API call then you can parse the API response using JSONArray or JSONObject APIs. you would use JSONArray to parse JSON which starts with the array brackets.   On the other hand, you would use JSONObject when dealing with JSON that begins with curly braces. Of course, JSON arrays and objects may be nested inside one another. One common example of this is an