Skip to main content


Showing posts from November, 2016

How to remove duplicate page object methods

You may come across situation when you find page object methods on various classes having similar operations. For ex in following example there are two different different methods doing almost same thing. Both methods get the count of ticket in opening and outgoing queue in a system. The only difference is the element locator. One method uses element locator openingTicketCount while other uses  outgoingTicketCount - public int getOpeningTicketCount() { final String count = fluent( openingTicketCount ). getText(); return count.length() == 0 ? 0 : Integer. valueOf (count); } public int getOutgoingTicketCount() { final String count = fluent( outgoingTicketCount ). getText(); return count.length() == 0 ? 0 : Integer. valueOf (count); } We can extract the common steps and create a new private method to encapsulate them - private int getTicketCount(By locator) { final String count = fluent(locator).getText(); return count.length() == 0 ? 0 : Integer. valueOf

What else should page object test?

As we know that objective of page object is to provide services offered by page (or part of it). In its true sense page object does not advocate asserting page condition in page object class. Except the page object constructor which can check if control is on right page on it, like following - But this is not the only use case of a check on page object. When returning data set from page object one could also check if data set is empty, for ex following method checks if collection of webelement is empty using Preconditions.checkState() method before returning it’s content - In the above code snippet, if element list is empty then page object method would throw IllegalStateException exception. This check could also be carried out on test method which receives the member name list. But I prefer to keep such checks on page object method and focus on assertion on test method. What do you think of this approach? Do you also have such checks in your page object methods?

Using chrome console to test xPath and css selectors

Note: If you are new to java and selenium then start with selenium java training videos .       Since the advent of selenium there have been many plugin to test xPath / css selectors but you don’t need any of them if you have chrome browser. Using Chrome console you can test both xPath and css selectors. Launch website to be tested in chrome browser and hit F-12 and you would see chrome console opened in lower pane of application - Hit escape key and console would open another pane to write element locators - And now you can start writing xPath or css selectors in chrome console and test them - The syntax for writing css id - $$(“ ”) And hit the enter key. If your expression is right then html snippet of the application element corresponding to the css selector would be displayed - If you mouse over the html snippet in chrome console then it would highlight the corresponding element in application - If you want to clean console of previously wri

Structure of test automation project

Note: If you are new to java and selenium then start with selenium java training videos .     Have you come across situation when you did not know where you should keep the test class, page object or any supporting class. I am going to share some of the practices I follow when working on test automation project. Given that I work with java and maven , it solves the problem of the directory structure. Maven project may have many directory but these are the ones I use most - src/main/java - any non test class, i.e - page object etc src/main/resources - resources like - properties file, text file etc used by main classes src/test/java - the test classes src/test/resources - resources like - properties file, text file etc used by test classes. target - this directory is created automatically building a maven project and Let’s focus on src/main/java - this is a directory which contains all of non test code. I usually end up having following structure on src/main/java