Selenium Design Patterns By Dima Kovalenko

Recently have gone through the book “Selenium  Design Patterns” by Dima Kovalenko. I would like to summarise few good points from these chapters here.

This book mainly has discussed about some design patterns and best practices to be followed while writing the selenium code for automating the Test Scripts.
1.Chapter One has discussed about the fundamental concepts of how to use the selenium IDE, assertions, comparison, disadvantages and advantages like price, flexibility and Open source. This chapter mainly useful for the newbies to the selenium tool on how to use the Record and Run and view the basic scripts

2.Chapter Two deals with the design patterns. Design Pattern is nothing but a solution to a commonly occurring problem. It is like a template, that can be used in many different situations.

Spaghetti Design Pattern is discussed in this chapter. This pattern is easy to get started as it doesn’t have to have plan ahead. Disadvantage with this pattern is tightly coupled and maintainability is difficult, code duplication

Interesting and important topic of this chapter is Locating of Elements in the Application using different strategies and tools like Inspect Element, Xpath etc.

3.Chapter Three describes about ‘Refactoring Tests‘, which reduces the duplicate code. It is mainly useful when someone implements the code and also helps to reduce the code duplication, it just explained about the importance and how to do it

And finally the last chapter which helps the user on how to set up the selenium with the ruby scripts. This chapter will be much useful to testers, who are interested to Automate the test cases in Ruby, will be much useful.

Advertisements

How to get an xpath in IE

if you are testing an application that will work only in IE or the specific scenario or page that has this element will open-up/play-out only in IE then you cannot use any of the above mention tools to find the XPATH.
Well the only thing that works in this case is the Bookmarklets that were coded just for this purpose. Bookmarklets are JavaScript code that you will add in IE as bookmarks and later use to get the XPATH of the element you desire. Using these you can get the XPATH as easily as you get using xpather or any other Firefox add-on.

STEPS TO INSTAL BOOKMARKLETS
1) Open IE
2) Type about: blank in the address bar and hit enter
3) From Favorites main menu select—>Add favorites
4) In the Add a favorite popup window enter name GetXPATH1.
5) Click add button in add a favorite popup window.
6) Open the Favorites menu and right click the newly added favorite and select properties option.
7) GetXPATH1 Properties will open up. Select the web Document Tab.
8) Enter the following in the URL field.

javascript:function getNode(node){var nodeExpr=node.tagName;if(!nodeExpr)return null;if(node.id!=''){nodeExpr+="[@id='"+node.id+"']";return "/"+nodeExpr;}var rank=1;var ps=node.previousSibling;while(ps){if(ps.tagName==node.tagName){rank++;}ps=ps.previousSibling;}if(rank>1){nodeExpr+='['+rank+']';}else{var ns=node.nextSibling;while(ns){if(ns.tagName==node.tagName){nodeExpr+='[1]';break;}ns=ns.nextSibling;}}return nodeExpr;}

9) Click Ok. Click YES on the popup alert.
10) Add another favorite by following steps 3 to 5, Name this favorite GetXPATH2 (step4)
11) Repeat steps 6 and 7 for GetXPATH2 that you just created.
12) Enter the following in the URL field for GetXPATH2

javascript:function o__o(){var currentNode=document.selection.createRange().parentElement();var path=[];while(currentNode){var pe=getNode(currentNode);if(pe){path.push(pe);if(pe.indexOf(‘@id’)!=-1)break;}currentNode=currentNode.parentNode;}var xpath=”/”+path.reverse().join(‘/’);clipboardData.setData(“Text”, xpath);}o__o();

13)Repeat Step 9.

You are all done!!

Now to get the XPATH of elements just select the element with your mouse. This would involve clicking the left mouse button just before the element (link, button, image, checkbox, text etc) begins and dragging it till the element ends. Once you do this first select the favorite GetXPATH1 from the favorites menu and then select the second favorite GetXPATH2. At his point you will get a confirmation, hit allow access button. Now open up a notepad file, right click and select paste option. This will give you the XPATH of the element you seek.

Note : hoping that the above post, which i got from google will help you solve finding xpath… to some extent