<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>amit klein &#187; selenium</title>
	<atom:link href="http://amitklein.com/tag/selenium/feed/" rel="self" type="application/rss+xml" />
	<link>http://amitklein.com</link>
	<description>an american in bombay working on improving the web</description>
	<lastBuildDate>Sun, 18 Jul 2010 16:25:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Functional Web Application Testing with Selenium IDE and RC</title>
		<link>http://amitklein.com/2008/02/26/functional-web-application-testing-with-selenium-ide-and-rc/</link>
		<comments>http://amitklein.com/2008/02/26/functional-web-application-testing-with-selenium-ide-and-rc/#comments</comments>
		<pubDate>Tue, 26 Feb 2008 14:50:01 +0000</pubDate>
		<dc:creator>amit</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://amitklein.com/?p=124</guid>
		<description><![CDATA[Introduction (How can testing make our lives easier) What is Selenium? Selenium IDE Trivial Example A Less Trivial Test Case (and some useful commands) Selenium RC Setup An example using Python The Future Additional Resources Reference Tutorials Testivus Introduction (How &#8230; <a href="http://amitklein.com/2008/02/26/functional-web-application-testing-with-selenium-ide-and-rc/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://amitklein.com/2008/02/26/testivus/' rel='bookmark' title='Permanent Link: Testivus'>Testivus</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div id="Table of Contents1" dir="ltr">
<ol>
<li><a href="#4.What is Selenium_|outline">Introduction (How can testing make our lives easier)</a></li>
<li><a href="#5.1.A Trivial Example |outline">What is Selenium?</a>
<ol>
<li><a href="#5.1.A Trivial Example |outline">Selenium IDE </a></li>
<li><a href="#5.1.A Trivial Example |outline">Trivial Example </a></li>
<li><a href="#5.2.A Less Trivial Test Case (and some useful commands)|outline">A Less Trivial Test Case (and some useful commands) </a></li>
</ol>
</li>
<li><a href="#6.Selenium RC|outline">Selenium RC </a>
<ol>
<li><a href="#6.1.Setup|outline">Setup </a></li>
<li><a href="#6.2.An example using Python|outline">An example using Python </a></li>
</ol>
</li>
<li><a href="#7.The Future|outline">The Future </a></li>
<li><a href="#8.Additional Resources|outline">Additional Resources </a>
<ol>
<li><a href="#8.1.Reference|outline">Reference </a></li>
<li><a href="#8.3.Tutorials|outline">Tutorials </a></li>
<li><a href="#8.4.Testivus|outline">Testivus </a></li>
</ol>
</li>
</ol>
</div>
<h2><a name="4.Introduction (How can testing make our lives easier)|outline"></a><br />
Introduction (How can testing make our lives easier)</h2>
<p>Testing is important, saves time, and makes our life easier.  Imagine a world where you can easily identify when changing code breaks existing functionality.  With Selenium we can write test suites for projects that can be automatically executed prior to code pushes, in this way we can have a high level of confidence that changes to a code base don’t have any unintentional consequences.</p>
<p>Functional testing of web applications isn’t easy, different browser/OS combinations all react differently, and now with the proliferation of Ajax, traditional testing methods no longer apply.  Selenium is great because it allows you to wait for and verify that certain Ajaxy conditions are met.  Additionally you can write one test script and run it on all browser/OS combinations.</p>
<p>This document is not intended to be a complete reference guide or tutorial (since there are many already available on the web including: <a href="http://www.devchix.com/2007/02/19/an-introduction-to-selenium-ide/">http://www.devchix.com/2007/02/19/an-introduction-to-selenium-ide/</a>, <a href="http://selenium-rc.openqa.org/tutorial.html">http://selenium-rc.openqa.org/tutorial.html</a>, <a href="http://www.infoq.com/articles/testing-ajax-selenium">http://www.infoq.com/articles/testing-ajax-selenium</a>).  Instead, the goal is to introduce Selenium, discuss the importance of testing, and provide some information specific to our process to help us improve the quality of the sites we develop.</p>
<h2><a name="4.What is Selenium_|outline"></a>What is Selenium?</h2>
<p>“Selenium is a test tool for web applications.  Selenium tests run directly in a browser, just as real users do.  And they run in Internet Explorer, Mozilla and Firefox on Windows, Linux, and Macintosh. (<a href="http://selenium.openqa.org/">http://selenium.openqa.org/</a>)”  Selenium comes in a few different flavors: the Firefox IDE (integrated development environment), Selenium Core, Selenium RC, Selenium Grid and Selenium on Rails.  Selenium IDE and RC are discussed below.</p>
<h2><a name="5.Selenium IDE|outline"></a>Selenium IDE</h2>
<p align="center"><img class="alignright size-full wp-image-125" title="selenium-ide" src="http://amitklein.com/wp-content/uploads/2008/09/selenium-ide.png" alt="selenium ide Functional Web Application Testing with Selenium IDE and RC" width="400" height="520" /></p>
<p>“Selenium IDE is an integrated development environment for Selenium tests. It is implemented as a Firefox extension, and allows you to record, edit, and debug tests. Selenium IDE … allow[s] you to easily and quickly record and play back tests in the actual environment that</p>
<p>they will run. (<a href="http://selenium-ide.openqa.org/">http://selenium-ide.openqa.org/</a>)”  Selenium IDE is written entirely in Javascript and has hooks for exporting test cases in your favorite language (Java, Ruby, Python, Perl, and PHP).</p>
<p>Clicking the record button (top right corner) allows you to execute commands in your browser to create a Selenium test.   When you have executed all the commands in your browser, you can use an assert command to verify that a certain condition has been met.</p>
<p>Although the IDE does not compare Visual Studio or Eclipse, you are still able to step through commands, set breakpoints, view debug output, and double click commands to see them execute in the browser.</p>
<h2><a name="5.1.A Trivial Example |outline"></a>A Trivial Example</h2>
<ul>
<li> Download the Selenium IDE (<a href="http://selenium-ide.openqa.org/">http://selenium-ide.openqa.org/</a>)</li>
<li>Launch the IDE from the Firefox Toolbar:</li>
</ul>
<p style="text-align: center;"><img class="alignnone size-full wp-image-126" title="firefox-toolbar" src="http://amitklein.com/wp-content/uploads/2008/09/firefox-toolbar.png" alt="firefox toolbar Functional Web Application Testing with Selenium IDE and RC"  /></p>
<ul>
<li>Click record:</li>
</ul>
<p style="text-align: center;"><img class="alignnone size-full wp-image-127" style="font-size: 19.5px; line-height: 28.5px;" title="record" src="http://amitklein.com/wp-content/uploads/2008/09/record.png" alt="record Functional Web Application Testing with Selenium IDE and RC" width="547" height="124" /></p>
<ul>
<li>In Firefox, go through the series of steps you need to accomplish to verify that a condition has been met:</li>
</ul>
<p style="text-align: center;"><img class="size-full wp-image-128 aligncenter" style="font-size: 19.5px; line-height: 28.5px;" title="sample-test" src="http://amitklein.com/wp-content/uploads/2008/09/sample-test.png" alt="sample test Functional Web Application Testing with Selenium IDE and RC" width="571" height="438" /></p>
<ul>
<li>Walking through each of the commands in the test above:</li>
<li>Open: Opens the base URL above (<a href="http://www.google.com/">www.google.com</a>) with the extention /ig?hl=en (the default when I go to Google):</li>
</ul>
<p><img class="alignnone size-full wp-image-129" title="google-firebug" src="http://amitklein.com/wp-content/uploads/2008/09/google-firebug.png" alt="google firebug Functional Web Application Testing with Selenium IDE and RC" width="791" height="381" /></p>
<ul>
<li>Type: target=q, value=mets best in NL.  In this step, the value of the search bar has an html id of “q” (you can verify this using firebug, see the image below).  By selecting target=q, it selects the search bar, and types in the value “mets best in nl.”</li>
<li>clickAndWait: target=btnG.  Click on Google Search.  Using firebug you can also verify that the Google Search button has the id=”btnG”  Wait till the resulting page is loaded.</li>
<li>clickAndWait: target(link=ABC News: Santana Deal Makes Mets…)  So not only can you target elements by their ID, you can also reference links by their display text:</li>
</ul>
<p style="text-align: center;"><img class="size-full wp-image-130 aligncenter" style="font-size: 19.5px; line-height: 28.5px;" title="mets-best" src="http://amitklein.com/wp-content/uploads/2008/09/mets-best.png" alt="mets best Functional Web Application Testing with Selenium IDE and RC"  /></p>
<ul>
<li>assertTextPresent:  Santana Makes Mets NL Favorite.  This final step creates a true/false condition at the end of the test.  If that link is clicked and the text is present on the following page, then the test case passes with a value of True, otherwise False.</li>
</ul>
<h2><a name="5.2.A Less Trivial Test Case (and some useful commands)|outline"></a>A Less Trivial Test Case (and some useful commands)</h2>
<p><span style="text-decoration: line-through;">The following test case goes to the Shop Dev environment, adds a few products to the cart, goes through the checkout process, and asserts that checkout has successfully completed.  In order to run this test you must be connected to the Shop VPN.</span> Please note that I have removed the aforementioned example because of security issues.  I plan to include another one soon.</p>
<p>Let’s review some of the more useful commands used in this test case:</p>
<ul>
<li>waitForElementPresent &#8211;  Verifies that the specified element is somewhere on the page.  If you try using the recorder to generate test cases, you will find that in most cases, it executes them too quickly.  waitForElementPresent allows you to use an id, name, javascript expression, xpath or link as an input.  For more info see: <a href="http://release.openqa.org/selenium-core/0.8.0/reference.html">http://release.openqa.org/selenium-core/0.8.0/reference.html</a>.  This is especially useful when waiting for certain conditions to be met, like waiting for a layer to pop-up (shopping cart), or waiting for the content on screen to change (like checkout).</li>
<li>assertVisable &#8211; Determines if the specified element is visible. An element can be rendered invisible by setting the CSS &#8220;visibility&#8221; property to &#8220;hidden&#8221;, or the &#8220;display&#8221; property to &#8220;none&#8221;, either for the element itself or one if its ancestors. This method will fail if the element is not present.  In this particular case we end our test with asserting that id=successResponse is visable and failureResponse is not.</li>
</ul>
<h2><a name="6.Selenium RC|outline"></a>Selenium RC</h2>
<p>While the IDE is great for writing test cases, you can only write test cases in Selenese (the HTML table format), tests can only be executed in Firefox, and you don’t have the ability to kick off a series of tests.  Enter Selenium RC.</p>
<p>&#8220;Selenium Remote Control provides a Selenium Server, which can automatically start/stop/control any supported browser. It works by using <a href="http://www.openqa.org/selenium/">Selenium Core</a> a pure-HTML+JS library that performs automated tasks in JavaScript.</p>
<p>The Selenium Server communicates directly with the browser using AJAX (XmlHttpRequest). You can send commands directly to the Server using simple HTTP GET/POST requests; that means that you can use any programming language that can make HTTP requests to automate Selenium tests on the browser. To further ease this process, we provide wrapper objects for a number of mainstream programming languages (Java, .NET, Perl, Python, and Ruby).</p>
<p>Finally, the Selenium Server acts as a client-configured HTTP proxy, to stand in between the browser and your website. This allows a Selenium-enabled browser to run JavaScript on arbitrary websites. (<a href="http://selenium-rc.openqa.org/">http://selenium-rc.openqa.org/</a>)</p>
<h3><a name="6.1.Setup|outline"></a>Setup</h3>
<ul>
<li>Download Selenium RC (<a href="http://selenium-rc.openqa.org/download.jsp">http://selenium-rc.openqa.org/download.jsp</a>)</li>
<li>We made a modification to the Selenium Server Jar file to allow us to verify text is present in XML (thanks Nicholas and Sudhakar!)  Download the updated jar file here: <a href="http://extranet.ipartners.com/selenium/selenium-server.jar">http://extranet.ipartners.com/selenium/selenium-server.jar</a></li>
<li>Start  the Selenium Server:</li>
</ul>
<p style="padding-left: 60px;"><em>java -jar selenium-server.jar -interactive</em></p>
<p style="padding-left: 60px;">Test it out by trying to open Google in Firefox:</p>
<p style="padding-left: 60px;"><em>cmd=getNewBrowserSession&amp;1=*firefox&amp;2=http://www.google.com<em></em></em></p>
<h3>An example using Python</h3>
<ul>
<li>If you don’t have it already download Python <a href="http://www.python.org/">http://www.python.org/</a>)</li>
<li><span style="text-decoration: line-through;">Download the following files into the selenium-python-client folder:<br />
selenium-python-client folder:</span> Again because of security reasons I had to remove this example, I will post a new one soon.</li>
</ul>
<h2>The Future</h2>
<p>Eventually we hope to integrate testing more deeply in our process.  One day as part of any code  push automated test scripts will run and code will only get pushed if these tests pass in the target environment.  Once we have a core framework in place, we can automate the process of nightly builds and testing.  See tools like <a href="http://cruisecontrol.sourceforge.net/">http://cruisecontrol.sourceforge.net/</a><a href="http://www.jsunit.net/">http://www.jsunit.net/</a></p>
<p>In the near future we will need to centralize test machines.  For now having one test machine with virtual instances with different browser combinations will work.  In the long term <a href="http://selenium-grid.openqa.org/">Selenium Grid</a> will work till we get into <a href="http://www.amazon.com/gp/browse.html?node=201590011">Cloud Computing</a></p>
<p>A few more long term goals:</p>
<ul>
<li>Continuous Integration:<a href="http://www.martinfowler.com/articles/continuousIntegration.html">http://www.martinfowler.com/articles/continuousIntegration.html</a></li>
<li>Test Drive Deployment:<a href="http://www.martinfowler.com/bliki/TestDrivenDevelopment.html">http://www.martinfowler.com/bliki/TestDrivenDevelopment.html</a></li>
<li>XP:<a href="http://www.extremeprogramming.org/">http://www.extremeprogramming.org/</a></li>
</ul>
<h2><a name="8.Additional Resources|outline"></a>Additional Resources</h2>
<h3><a name="8.1.Reference|outline"></a>Reference</h3>
<ul>
<li><a href="http://release.openqa.org/selenium-core/0.8.0/reference.html">http://release.openqa.org/selenium-core/0.8.0/reference.html</a></li>
<li><a href="http://agiletesting.blogspot.com/2006/01/useful-tools-for-writing-selenium.html">http://agiletesting.blogspot.com/2006/01/useful-tools-for-writing-selenium.html</a></li>
<li><a href="http://ttwhy.org/home/blog/2007/05/12/selenium-ui-element-locator/">http://ttwhy.org/home/blog/2007/05/12/selenium-ui-element-locator/</a></li>
</ul>
<h3><a name="8.3.Tutorials|outline"></a>Tutorials</h3>
<ul>
<li><a href="http://www.devchix.com/2007/02/19/an-introduction-to-selenium-ide/">http://www.devchix.com/2007/02/19/an-introduction-to-selenium-ide/</a><a href="http://selenium-rc.openqa.org/tutorial.html">http://selenium-rc.openqa.org/tutorial.html</a></li>
<li><a href="http://www.infoq.com/articles/testing-ajax-selenium">http://www.infoq.com/articles/testing-ajax-selenium</a></li>
</ul>
<h3><a name="8.4.Testivus|outline"></a>Testivus</h3>
<ul>
<li><a href="http://www.developertesting.com/archives/month200705/20070502-000424.html">http://www.developertesting.com/archives/month200705/20070502-000424.html</a></li>
</ul>


<p>Related posts:<ol><li><a href='http://amitklein.com/2008/02/26/testivus/' rel='bookmark' title='Permanent Link: Testivus'>Testivus</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://amitklein.com/2008/02/26/functional-web-application-testing-with-selenium-ide-and-rc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
