About Me

My photo
I Love Bugs! Yum! Yum!

Wednesday, January 19, 2011

Selenium tips and tricks


Checking if a link is present by it’s href
verifyElementPresent
//a[@href="${itemlink}"]
displayAlert or echo
1. Cut and paste the following code to the end of C:\Selenium\selenium-core-0.8.2\core\scripts\user-extensions.js file
P.S. works on both IDE and TestRunner
//This extension adds command 'alert' that pops-up a alert message with a given parameter.This helps a lot in script debuging
Selenium.prototype.doDisplayAlert = function(value, varName) {
alert(value);
};

P.S. Echo works only on TestRunner
To see “echo” results in TestRunner - While running using TestRunner. Open the Log window just before you run the test suite and select the “Info” option. If you have “echo” commands it will show the information there.

SOA - Service Oriented Architecture



RESTSOAP
Message FormatXMLXML inside a SOAP Envelope
Interface DefinitionnoneWSDL
TransportHTTPHTTP,FTP,MIME,JMS,SMTP, etc...

Five key tests for any SOA
Ten examples of SOA at work, right now

JUnit

In search of an opensource one stop testing tool...

Friday, June 12, 2009

 TestLink - TestLink enables easily to create and manage Test cases as well as organize them into Test plans. These Test plans allow team members to execute Test cases and track test results dynamically, generate reports, trace software requirements, prioritize and assign tasks.

Get the latest UserManual (1.8) and Installation and Configuration Guide (1.8) from TestLink site. Download Testlink here. And here is a screenshot by screenshot demo.

TestLink requires MySQL, PHP and a Webserver (eg., Apache)

MySQL - MySQL is a popular open source database, it's also the database of choice for a new generation of applications built on the LAMP stack (Linux, Apache, MySQL, PHP / Perl / Python.) MySQL runs on more than 20 platforms including Linux, Windows, OS/X, HP-UX, AIX, Netware, giving you the kind of flexibility that puts you in control. (PHPMyAdmin for web based MySQL admin)

PHP - PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. If you are new to PHP and want to get some idea of how it works, try the introductory tutorial. After that, check out the online manual, and the example archive sites and some of the other resources available in the links section.

Apache - The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows. Documentation can be found here.

Bugzilla - Bugzilla is a "Defect Tracking System" or "Bug-Tracking System". Defect Tracking Systems allow individual or groups of developers to keep track of outstanding bugs in their product effectively.

TestLink cooperates with known Bug tracking systems as is Bugzilla, Mantis, etc.

Get the latest Documentation (3.3.4) from Bugzilla site. Download Bugzilla here.

Selenium - Selenium is a suite of tools to automate web app testing across many platforms. Learn more about it here.

Testlink API - XML/RPC support for get Test results from scripts/external tools.
With the new version of TestLink 1.8 http://groups.google.com/group/testlink-dev/web/automation-testing-scripts-for-tl

Disadvantages

Integration with automation tools. As I mentioned above, I read regarding integrating with Selenium in TestLink 1.8 version. But haven't tried yet. Will post if I find some info.
I read in an article that, "the simultaneous execution/update of one test scenario from several testers is not recommended. If more than one QA is working on your project, it is better to assign the scenario to a particular QA. If you have to update already executed scenario, my suggestion is to create a new version of the test plan."

Saucelabs

Thursday, July 9, 2009

Sauce Labs enables developer and testers to make their Selenium test suites run fast and provide test results, all without any of the configuration overhead of on-premise Selenium installations.

FogBugz

Tuesday, August 4, 2009

Bug tracking, project management, svn, wiki and more in one place. Also, has plugin for Agile projects. Stumbled upon this tool when searching for testing related blogs.

ec2 api tools how to

Friday, August 21, 2009

http://linuxsysadminblog.com/2009/06/howto-get-started-with-amazon-ec2-api-tools/

When selenium doesn't recognize your new window

Wednesday, September 2, 2009

Try the foll. options
selenium.selectwindow(null)
selenium.selectwindow(windowtitle)
selenium.selectwindow(windowid)
selenium.selectwindow(windowname)

If none of the above works,
Do a getattribute on the link which is trying to open the new window
then do a open(link) or
openwindow(link) if you want it to open on a new window and give it a name so that you can reference it later.

Selenium: To get table length

Wednesday, September 2, 2009

To get table length

1. table.row.length
2. if the table doesn't have name, take the xpath route
a. get the xpath for the table [eg., id('batch-action-form')/table/tbody/tr]
b. use storeXpathCount for the table's xpath
storeXpathCount | id('batch-action-form')/table/tbody/tr | rowcnt

Selenium: In a dynamic table, locate a row and click a radio button or checkbox or link

Friday, September 4, 2009

Let's say, you have a table which has rows getting added dynamically and you would like to select that particular row and do some action. Assuming there is one column which is unique
Have firebug and XPath checker handy. (firefox addons)

Let's say, the foll. is your source of the table (firebug)
<form id="batch-action-form" action="" method="post">
<div class="actions">
</div>
<table cellspacing="0">
<thead>
</thead>
<tbody>
<tr class="row1">
</tr>
<tr class="row2">
<td>
<input class="batch-select" type="checkbox" name="selected" value="13"/>
</td>
<th>
<a href="13/">observation</a>
</th>
<td>
<h2>This is a test</h2>
<img alt="This is a test" src="/media/test/photologue/photos/cache/test__thumbnail.jpg"/>
</td>
<td>Approved</td>
</tr>
<tr class="row1">
</tr>
<tr class="row2">
<td>
<input class="batch-select" type="checkbox" name="selected" value="14"/>
</td>
<th>
<a href="14/">observation</a>
</th>
<td>
<h2>This is not a test</h2>
<img alt="This is not a test" src="/media/test/photologue/photos/cache/nottest__thumbnail.jpg"/>
</td>
<td>Rejected</td>
</tr>
<tr class="row1">
</tr>
<tr class="row2">
<td>
<input class="batch-select" type="checkbox" name="selected" value="15"/>
</td>
<th>
<a href="15/">observation</a>
</th>
<td>
<h2>This may be a test</h2>
<img alt="This may be a test" src="/media/test/photologue/photos/cache/maybetest__thumbnail.jpg"/>
</td>
<td>Unmoderated</td>
</tr>
</tbody>
</table>
</form>



To click on the checkbox of the row which has "This is a test", the xpath would be
//form[@id='batch-action-form']/table/tbody/tr/td/h2[contains(text(),'This is a test')]/../../td/input[@type='checkbox']

1. Download Firefox and it's addons firebug and xpath checker
2. Goto the page which has the table.
3. open the firebug and inspect the element
4. right click on the element and click View XPath
5. then play around with the xpath until you see the desired field shows up.
6. cut and paste that to the selenium script
7. for the above example: check | //form[@id='batch-action-form']/table/tbody/tr/td/h2[contains(text(),'This is a test')]/../../td/input[@type='checkbox']
That would check the appropriate checkbox for the row which has the text "This is a test"

Selenium: tinymce editor

Wednesday, September 9, 2009

 
If the tinymce editor has id "tinymce"

sel.type("document.getElementById('tinymce')", "This is a text")

Grinder Setup

Tuesday, September 15, 2009

setGrinderEnv.sh

export GRINDERPATH=/Users/jk/grinder-3.2
export GRINDERPROPERTIES=/Users/jk/tests/grinder.properties
export CLASSPATH=/Users/jk/grinder-3.2/lib/grinder.jar:$CLASSPATH
JAVA_HOME=/usr/bin/java
export PATH=$JAVA_HOME/bin:$PATH

startConsole.sh

./setGrinderEnv.sh
java net.grinder.Console

startAgent.sh

./setGrinderEnv.sh
java net.grinder.Grinder $GRINDERPROPERTIES


startProxy.sh

./setGrinderEnv.sh
java -cp $CLASSPATH net.grinder.TCPProxy -console -http > grinder.py

Testlink, fogbugz and Selenium RC

Monday, October 26, 2009

Yay! Made testlink, fogbugz and selenium work together :) Also, have screenshots for the failed testcases...

Selenium Screencapture

Wednesday, November 4, 2009


If you get this error: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsILocalFile.initWithPath] foll. is the solution:

selenium.capture_entire_page_screenshot works only with absolute path for eg.,

self.sel.capture_entire_page_screenshot("C:\\out.png,"background=#CCFFDD") - for windows

self.sel.capture_entire_page_screenshot("/Users/abc/tests/testresults/out.png,"background=#CCFFDD") - for Mac

Alternatively,capture_screenshot can be used which takes relative path. Tested the foll. in both Mac and windows. Drawback is, it doesn't get the entire page. Just gets the visible portion of the webpage :(

self.sel.capture_screenshot("testresults/out.png")

Python decorators to group tests

Thursday, February 18, 2010

The foll. code runs only the tests which has "regression" in the annotation.

decoratortest.py:
---------------

#!/usr/bin/env python
import unittest
import time

class decotest(unittest.TestCase):
def Tests(value):
def decorator(target):
target.attribute = value
if target.attribute.find('regression') != -1 :
print target.__name__ + ":" + target.attribute
return target
return decorator

@Tests('regression, acceptance')
def test_abc(self):
print "What's passed:" + self.test_abc.attribute
print "I'm test_abc"

@Tests('smoke, acceptance')
def test_cde(self):
print "I'm test_cde"

calldecotest.py:
-------------------

#!/usr/bin/env python

import unittest
from decoratortest import decotest

def main():
suite = unittest.TestSuite()
test_support.run_unittest(decotest)

if __name__ == "__main__":
main()