Power of OpenScript: getElementsByTag


opneScript has some really powerful inbuilt methods for you to use. We will try to cover those methods. I am starting with one such method called getElementsByTag.  This method can be very helpful in scenario where you have to find the count of any element or you are searching for some element and ….

As the name suggests it will return the DOM Elements which has the HTML tag which you will be passing as parameter. Return type is List<DOMElements>; which means a list of DOM Elements.

Now we will see the example of this method on our very own google.com 😉

As you would have noticed that google has so many links in its page. Our job is to find out many links are displayed and if there is any link called ‘GMail’ then just click it.

We will call getElementsByTag method on the document to get all the links displayed in the page. I hope you all will be very familiar with basic of HTML tags such as <img> for image <a> for links <input type=”text”> for textbox in form and so on…

Here i would also recommend to use debug tool to understand the HTML structrure of a page. For Firefox there is a plugin called firebug, chrome has inbuilt developer tools…

Now coming back to the problem.. We have to find the number of links in the page so we will pass parameter as a;which is HTML tag for link. Also this method will return list of DOMElement so we will store them in List<DOMElement>

java.util.List<DOMElement> lt = web.document(“/web:window[@index=’0′ or @title=’Google’]/web:document[@index=’0′]”)
.getElementsByTagName(“a”);

Now lt has all the DOMElement which has HTML tag =<a>

int ltLength = lt.size();
for(int i=0;i<ltLength;i++)
{
String strAttr = lt.get(i).getAttribute(“text”);
if(strAttr.equalsIgnoreCase(“gmail”))
{
lt.get(i).click();
}
}

That’s all, SIMPLE, isn’t it?? Do let me know if you have any questions..

Cheers,

Pratik

Posted in OpenScript | Leave a comment

OpenScript: New automation tool


Hello,

OpenScript is the Oracle Functional Testing tool which is a part of Oracle Automated Testing Suite(OATS).

OpenScript is built on Eclipse IDE and uses JAVA as its scripting language. Since it is using Java it gives you the advantage of powerful language Java.

As of now QTP is the leader of Automation Tool so we will have a brief comparison between QTP and OpenScript:

1. OpenScript uses Java as its language while QTP uses VB Script.

2. OpenScript supports IE and FireFox browser. So you develop a script and now this script  you can run on IE as well as FF. While QTP supports only IE.

3. In QTP you can associate a single databank for each script where as in OpenScript you can associate n number of databanks for each script.

4. QTP recognizes its objects and store them in Object Repository file(.tsr) while OpenScript by default doesnot store your objects in any library however you have option to store them in Object Library(.properties)[Will see this in detail some time later]

5. QTP supports Windows based Application while OpenScript does not

I have worked on QTP as well as OpenScript. Both has its own advantage and disadvantage. When i started working on QTP i think it was pretty easy for a beginner to understand the tool and get used of it; this is certainly not the case with OpenScript. It took some time for me to get used of it( May be becasue i was so addicted of QTP). But once you get used of it you are certainly going to love it!!!

If you are a QTP user and planning to use OpenScript first few days you will feel out of town mainly because of the object recognition stuff. On a very high level you can take it as openscript reconizes object and show them in you script pretty similar to Descriptive Programming in QTP.

Will come back soon to let you guys know more about openscript. Meanwhile if you have anything do let me know your comments.

Cheers

Posted in OpenScript | 2 Comments