Adding custom LocatorBuilders to selenium ide
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
Sunday, November 15, 2009 | 2 Comments
Writing an xml document to a file & indent it
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");
Tuesday, November 10, 2009 | 0 Comments
Kandil 2009
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Kavita Dabke wrote at 6:49 PM on Sun, Oct 25, 2009 Kandil masta ahe! Khuupach creative idea! | |
at 5:37 AM on October 26, 2009 I love ur Kandil.=] | |
|
|
Sunday, November 01, 2009 | 0 Comments
rangde.org
RangDe.Org Film from rahulchittella on Vimeo.
Saturday, September 12, 2009 | 0 Comments
Startup city Mumbai 09
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/
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/
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
Monday, September 07, 2009 | 0 Comments