Adding custom LocatorBuilders to selenium ide

Adding custom LocatorBuilders to selenium ideSocialTwist Tell-a-Friend

Background : Selenium is an open source tool for web application testing.
Selenium IDE is a Firefox plugin allows you to record tests in browser and run them from the browser or as a java test ( or any other languages ) using Selenium Remote Control libraries.
You can extend functionality of Selenium IDE by writing Event Handlers, Locator Builders, Command Builders, Custom Format all in JavaScript.
For more about that http://wiki.openqa.org/display/SIDE/Writing+extensions.

More on Locator Builders
Locator Builders decide how HTML elements in a page are identified.
eg id attribute is a default locator builder.
So while recording a test an html element attribute selenium using the id attribute to recognize the element you changed, clicked etc.

Writing a new locator builder

You can instruct selenium to use a custom attribute to identify the elements in your page. Default Locator builders can be found at chrome://selenium-ide/content/locatorBuilders.js

Here's the js code to add a location builder for an attribute myattr

LocatorBuilders.add('myattr', function(e) {
if (e.hasAttribute('myattr')) {
if (e.getAttribute("myattr")) {
return '//' + e.nodeName + '[@myattr=\'' +
e.getAttribute("myattr") + '\']';
}
}
return null;
});


Since there are plenty of existing location builders, you need to specify the order in which they are invoked. This is how its done

LocatorBuilders.order = ['myattr','id', 'link', 'name', 'dom:name',
'xpath:link','xpath:img', 'xpath:attributes', 'xpath:href',
'dom:index', 'xpath:position'];

Complete code:
mylocator.js

LocatorBuilders.add('myattr', function(e) {
if (e.hasAttribute('myattr')) {
if (e.getAttribute("myattr")) {
return '//' + e.nodeName + '[@myattr=\'' +
e.getAttribute("myattr") + '\']';
}
}
return null;
});


LocatorBuilders.order = ['myattr','id', 'link', 'name', 'dom:name',
'xpath:link','xpath:img', 'xpath:attributes', 'xpath:href',
'dom:index', 'xpath:position'];

Steps to add the extension code to selenium IDE

  • Write locator code in a new .js file
  • Specify the path in "Selenium IDE extensions" field in Selenium IDE > Options and restart selenium IDE


Writing an xml document to a file & indent it

Writing an xml document to a file & indent itSocialTwist Tell-a-Friend

Heres a simple code snippet in java for writing an xml document created
to an xml file.
Seems quite a common task but had to google quite a bit to get it right ....



Document doc = null; // load your DOM into this document object

TransformerFactory transfactory = TransformerFactory.newInstance();

Transformer transformer = transfactory.newTransformer();

StringWriter writer = new StringWriter();
StreamResult destination = new StreamResult(writer);
DOMSource source = new DOMSource(doc);

transformer.transform(source, destination);

String xmlString = writer.toString();

OutputStream os;

byte buf[] = xmlString.getBytes();
os = new FileOutputStream("output.xml");

for(int i=0;i
os.write(buf[i]);
}

os.close();
buf = null;




Modifications to the code so that the output xml file is properly indented.



TransformerFactory transfactory = TransformerFactory.newInstance();

// code for indenting
transfactory.setAttribute("indent-number", new Integer(2));

Transformer transformer = transfactory.newTransformer();

// code for indenting
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

Kandil 2009

Kandil 2009SocialTwist Tell-a-Friend

http://photos-f.ak.fbcdn.net/hphotos-ak-snc1/hs275.snc1/10226_298034140206_810140206_9114742_6068614_n.jpg

Shantaram Waingankar wrote
at 9:26pm on October 19th, 2009
My kandil made from 212 old cd's

Radhika Wagle wrote
at 9:28pm on October 19th, 2009
wow!!...HOW!!??

Priyanka Potdar wrote
at 10:08pm on October 19th, 2009
WOW!

Jaideep Mahajan wrote
at 10:37pm on October 19th, 2009
wat wrk .....superb

Aaron D'souza (MICA India) wrote
at 10:39pm on October 19th, 2009
send me the image in full resolution

Shantaram Waingankar wrote
at 11:09pm on October 19th, 2009
i'll take a good pic tomm in hi res nd send it

Anil Raju Puliyeril wrote
at 11:56pm on October 19th, 2009
Awesome man. U did some phtotshop editing kya??
Coz the light effect etc seems to be superb...

Shantaram Waingankar wrote
at 12:03am on October 20th, 2009
dude .... come over tomorrow if u cant believe it

Anil Raju Puliyeril wrote
at 12:13am on October 20th, 2009
Hehe just joking... Too good man just upload
sm better pic so that we can relish it even more...

Gayatri Singh wrote
at 12:46am on October 20th, 2009
Hey.. That's awesome...& Happy Diwali to u !

Darshan Divecha wrote
at 1:21am on October 20th, 2009
same 2 u!

Kunal Modi wrote
at 6:29am on October 20th, 2009
finally you used the cds.. great.. Happy New Year..


Kitesh Jain wrote
at 2:08pm on October 20th, 2009
awesome man nd happy new year


Soni mami (UShenoy@aol.com) wrote
at 5:00 PM on October 24, 2009
neat way of being creative. Loved the creation.


Nikhil Patwardhan wrote
at 8:13 PM on October 24, 2009
Nice!! :-)
How was Diwali?


Vikram wrote
at 8:26 PM on October 24, 2009
Boss - this is quite amazing. very creative!


purnit chhajer wrote
at 11:06 PM on October 24, 2009
hey nice wrk yaar...it can be a nice go green venture, wat say??
where r u wrkin now? and happy diwali!!!


Kavita Dabke wrote
at 6:49 PM on Sun, Oct 25, 2009
Kandil masta ahe! Khuupach creative idea!

Vrunda Modi wrote
at 5:37 AM on October 26, 2009
I love ur Kandil.=]


Kadambari Raut wrote
at 10:52 AM on Mon, Oct 26, 2009
"jr. Edison", awsm kandil.. fantabulous!!!


Vansa wrote
at 12:31 AM on Thu, Oct 22, 2009
wow...that's really pretty,Shantaram!!!
your kandil

rangde.org

rangde.orgSocialTwist Tell-a-Friend

RangDe.Org Film from rahulchittella on Vimeo.

Startup city Mumbai 09

Startup city Mumbai 09SocialTwist Tell-a-Friend

Heres an invite to Startup City thats been organised in Mumbai for the first time on 12th of this month. A must attend for all wanna be entrepreneurs especially ones eyeing the Internet/ IT sector.

SiliconIndia


Hello,

wherein there were 4000 attendees and 150 Startups, siliconindia is organizing Startupcity on Saturday September 12, 2009 at Hotel Rangsharda, Bandra (West), Mumbai. It's by far the largest and most exciting event of its kind in Mumbai.

To attend this event, register FREE at http://www.siliconindia.com/startupcity_mumbai/index.php

It is your chance to know the building of cool startups as their founders come and share their journey with us.

Watch live product demonstrations
Get a peek into cutting edge technologies
Lay hands on the best-of-breed solutions
Meet young, energetic, passionate geeks
Experience the culture of innovation in small companies
Visionary Keynotes
In-depth Panel Discussion

TIME: 8.45 AM to 4.30 PM
WHEN: Saturday, September 12, 2009
WHERE: Hotel Rangsharda, Bandra (West), Mumbai

CONFIRMED STARTUPS: Adoroi, Aegis, Ashvatec, Auxano Technologies, Bolohealth.com, Content Syndicate, Colayer, Crederity, Indictrans Technologies, Iken, Jiobindaas, Mapmy India, Mind Technologies, Mobien Technologies, Mobiwik, Naaptol, Nitman Software, Neev Technologies, plugHR, Prescient Technologies, Quantum Pages, Rudraksha Technology, Sampada Software Solutions, Signure Technologies, Soft Script Solutions (Find Guru), Web Bazaar, Virtual Rack, Viral Technologies, VelaiSMS, YoKnowledge.com (Hayagriva Software), YoPedia

Founders of these Startups will pitch their business plans to the investors panel.

Some of the Investors who will be present: Accel Partners, Artiman Ventures, Axon Ventures, Battery Ventures, Bluerun Ventures, Canaan Partners, DFJ, Epiphany Ventures, Greylock, Helion Ventures, IDG, Indian Angel Network, Inventus Capital, Jafco Asia Ventures, Lightspeed, Mercatus Capital, Mumbai Angels, NEA-Indo US Ventures, Nexus India Capital, Ojas Ventures, Qualcomm Ventures, Reliance Capital, Seeed Fund, Sequioa Capital, Singularity Ventures, UTI Ventures, Venture East, Walden International.

A close-door CEO Conclave will bring CEOs, presidents and company owners together for an invigorating exchange of information, ideas and insights. Leaders of over 300 technology companies (startups, domestic IT companies and multinational companies) will attend this event. The roundtable will facilitate an informal discussion amongst the senior management about the best practices of building technology companies, what works, what doesn?t work, potential pitfalls and other challenges. They delve into candid, solution- seeking discussions focused on CEO-level issues - the challenges and pressures unique to top-level management.

To attend this event, register FREE at
http://www.siliconindia.com/startupcity_mumbai/index.php


This is undoubtedly the biggest event for startups. There's no better way to get a good sense of the product ecosystem!

Thanks
siliconindia Team

BlogCatalog

Travel Blogs - BlogCatalog Blog Directory