<?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>code-diesel &#187; selenium</title>
	<atom:link href="http://www.codediesel.com/tag/selenium/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codediesel.com</link>
	<description>/* PHP &#38; MySQL Journal */</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:19:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Selenium IDE: Pattern matching</title>
		<link>http://www.codediesel.com/testing/selenium-ide-pattern-matching/</link>
		<comments>http://www.codediesel.com/testing/selenium-ide-pattern-matching/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 04:01:01 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[testing]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2692</guid>
		<description><![CDATA[Patterns are bread and butter of Selenium tests. Many commands in Selenium take the pattern parameter. They enable you to match various content types on a web page – links, text, elements. There are chiefly three type of patterns you can use in your tests: globs, exact and regular expressions. Globs Globs or the verb [...]]]></description>
			<content:encoded><![CDATA[<p>Patterns are bread and butter of Selenium tests. Many commands in Selenium take the pattern parameter. They enable you to match various content types on a web page – links, text, elements. There are chiefly three type of patterns you can use in your tests: <em>globs</em>, <em>exact</em> and <em>regular expressions</em>.<br />
<span id="more-2692"></span></p>
<h4>Globs</h4>
<p><strong>Globs</strong> or the verb <strong>Globbing</strong> is familiar to most people who have ever used file matching patterns. If you have ever searched for a file in Linux or DOS using a line like <em>*.exe</em> or <em>photos*</em>, then you have used globs.  But globbing in Selenium is not as rich as the one in Linux – it supports only three  special characters: <strong>*</strong>, <strong>?</strong> and <strong>[ ]</strong>.</p>
<p> <strong>*</strong> matches any number of characters, by any we mean ‘nothing’, ‘a single character’ or ‘many characters’.</p>
<p><strong>?</strong> , matches a single character.</p>
<p><strong>[ ]</strong> , called a character class, lets you match any single character found within the brackets. e.g</p>
<p><strong>[0-9]</strong> matches any digit<br />
<strong>[a-zA-Z]</strong> matches any alphabet, regardless of case</p>
<p>To specify a glob in a selenium command, prefix the pattern with the <em>glob:</em> string. For example if you would like to search for the texts <em>color</em> or <em>colour</em> then you can use the <em>colo*r</em> glob as shown below.</p>
<table class="posts_table">
<colgroup>
<col width="36%" />
<col width="38%" />
<col width="26%" />
</colgroup>
<thead valign="bottom">
<tr>
<th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr>
<td>clickAndWait</td>
<td>link=search</td>
<td>&nbsp;</td>
<tr>
<td>verifyTextPresent</td>
<td>glob: colo*r</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>However you are free to eliminate the <em>glob:</em> prefix and only specify the text pattern because globbing patterns are the default in Selenium.</p>
<h4>Regular Expression patterns</h4>
<p>Of the three type of patterns, Regular Expressions are the one that are the most useful. Selenium supports the complete set of RegEx patterns that Javascript supports. So now you are not limited by the *,? And [] globbing patterns. To use RegEx patterns you need to prefix each RegEx with either <em>regexp:</em> or <em>regexpi:</em>, the latter being case-insensitive.</p>
<p>For example the following will test if a input field with the id &#8216;name&#8217; contains the string &#8216;javascript&#8217;, &#8216;JavaScript&#8217; or &#8216;Javascript&#8217;.</p>
<table class="posts_table">
<colgroup>
<col width="36%" />
<col width="38%" />
<col width="26%" />
</colgroup>
<thead valign="bottom">
<tr>
<th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr>
<td>clickAndWait</td>
<td>link=search</td>
<td>&nbsp;</td>
<tr>
<td>verifyValue</td>
<td>id=name</td>
<td>regexp:[Jj]ava([Ss]cript)</td>
</tr>
</tbody>
</table>
<p>Below are a few common regular expression patterns:</p>
<p><strong>regexp:(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d</strong><br />
:match a date in &#8216;mm/dd/yyyy&#8217; format with any of the &#8216;-&#8217;, &#8216;/&#8217;, &#8216;.&#8217;  as separators.</p>
<p><strong>regexpi:^[A-Z0-9+_.-]+@[A-Z0-9.-]+$</strong><br />
:match a generic email address.</p>
<p><strong>regexp:^[0-9]{5}(?:-[0-9]{4})?$</strong><br />
:match a ZIP code (U.S. postal code), allowing both the five-digit and nine-digit (ZIP + 4) formats.</p>
<p><strong>regexp:^(?!000|666)(?:[0-6][0-9]{2}|7(?:[0-6][0-9]|7[0-2]))-?(?!00)[0-9]{2}-(?!0000)[0-9]{4}$</strong><br />
:match U.S Social Security numbers in the in the AAA-GG-SSSS format.</p>
<p><strong>regexp:^(https?|ftp|file)://.+$</strong><br />
:match almost any url.</p>
<p></strong><br />
<h4>Exact Patterns</h4>
<p>Patterns with the prefix &#8216;exact:&#8217; will match the given text as it is.  For example if you give the search pattern as below, then it will match a glob pattern &#8216;*&#8217; or &#8216;*.java&#8217;.</p>
<table class="posts_table">
<colgroup>
<col width="36%" />
<col width="38%" />
<col width="26%" />
</colgroup>
<thead valign="bottom">
<tr>
<th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr>
<td>clickAndWait</td>
<td>link=search</td>
<td>&nbsp;</td>
<tr>
<td>verifyValue</td>
<td>glob: *.java</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>But if you want an exact match with the value string, i.e without the glob operator doing its work, you use the &#8216;exact&#8217; pattern as below. In this example the &#8216;*&#8217; (asterisk) will work as a normal character rather then a pattern-matching wildcard character.</p>
<table class="posts_table">
<colgroup>
<col width="36%" />
<col width="38%" />
<col width="26%" />
</colgroup>
<thead valign="bottom">
<tr>
<th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr>
<td>clickAndWait</td>
<td>link=search</td>
<td>&nbsp;</td>
<tr>
<td>verifyValue</td>
<td>exact: *.java</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>In conclusion the <em>glob:</em> and the <em>exact:</em> pattern are the subsets of the Regular Expression pattern matcher. Everything you can do with glob: or exact: you can accomplish with RegExp.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/testing/selenium-ide-pattern-matching/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Adding custom commands to Selenium</title>
		<link>http://www.codediesel.com/testing/adding-custom-commands-to-the-selenium-ide/</link>
		<comments>http://www.codediesel.com/testing/adding-custom-commands-to-the-selenium-ide/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 09:44:35 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[testing]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/sql/extending-selenium-ide/</guid>
		<description><![CDATA[how to extend and add your own commands to the selenium ide]]></description>
			<content:encoded><![CDATA[<p>In the previous <a href="http://www.codediesel.com/php/selenium-ide-tutorial-part-1/">Selenium posts</a> we saw how to use the selenium IDE for testing web pages. In this post we will see how to extend the Selenium IDE by adding our own custom commands. </p>
<p>Selenium IDE offers many useful commands (often called Selenese) for testing purposes. You use this sequence of commands to create various tests. But many times these commands are not sufficient and you need to add your own custom commands. For example a reader recently requested on how to input unique email ids for testing. Of course you can easily do this using the Selenium RC server and a language like PHP or Java. But we want to accomplish this in the IDE itself.<br />
<span id="more-2307"></span></p>
<h4>Types of Selenium commands</h4>
<p>Selenium commands come in three varieties : Actions, Accessors and Assertions. Each Selenium command being given in the format below:</p>
<table style="background-color: #FDF7E7; height: 20px; width: 230px; border: 1px solid #c0c0c0;">
<tr>
<td style="border-right: 1px solid #c0c0c0;">command</td>
<td style="border-right: 1px solid #c0c0c0;">target</td>
<td>value</td>
</tr>
</table>
<p><strong>Actions</strong> are commands which in general modify the state of the application; <em>click</em>, <em>typeKeys</em>, <em>deleteCookie</em> etc. are all actions. Many actions also come with a sibling with a &#8220;AndWait&#8221; suffix added; e.g. ‘typeKeysAndWait’. This tells Selenium to wait until the page loads after performing the particular action.</p>
<p><strong>Accessors</strong> examine the state of the application and store the results in variables, e.g. &#8220;storeLocation&#8221;. </p>
<p><strong>Assertions</strong> are like Accessors, but they verify that the state of the application conforms to what is expected</p>
<p>In this post we will see how to write Selenium Action command using a simple example.</p>
<h4>Writing your first custom Selenium Action Command</h4>
<p>In the following example we will add a new action, ‘typeRandomEmail’, which generates a random email address and types it in an input field.</p>
<p>Every Selenium Action command starts with a &#8216;do&#8217; prefix. The corresponding action comprising &#8216;AndWait&#8217; is automatically registered.  e.g when we create the &#8216;typeRandomEmail&#8217; action, the &#8216;typeRandomEmailAndWait’ command is automatically added to the command list. An action command takes up to two parameters, which will be passed the second and third column values in the test table. In our example we will be using only one parameter &#8211; the locator id where the random email will be typed.</p>
<p>The following shows the code for the <em>typeRandomEmail</em> action.</p>

<div class="wp_codebox"><table><tr id="p23071"><td class="code" id="p2307code1"><pre class="javascript" style="font-family:monospace;">&nbsp;
Selenium.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">doTypeRandomEmail</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>locator<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">/**
    * Sets the value of an input field to a random email id, 
    * as though you typed it in.
    *
    * @param locator an &lt;a href=&quot;#locators&quot;&gt;element locator&lt;/a&gt;
    */</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// All locator-strategies are automatically handled by &quot;findElement&quot;</span>
    <span style="color: #003366; font-weight: bold;">var</span> element <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">page</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">findElement</span><span style="color: #009900;">&#40;</span>locator<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009966; font-style: italic;">/* The following block generates a random email string */</span>
    <span style="color: #003366; font-weight: bold;">var</span> allowedChars <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;abcdefghiklmnopqrstuvwxyz&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> stringLength <span style="color: #339933;">=</span> <span style="color: #CC0000;">8</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> randomstring <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>stringLength<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> rnum <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> allowedChars.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        randomstring <span style="color: #339933;">+=</span> allowedChars.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span>rnum<span style="color: #339933;">,</span>rnum<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Append a domain name</span>
    randomstring <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;@somedomain.com&quot;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Replace the element text with the new text</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">browserbot</span>.<span style="color: #660066;">replaceText</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> randomstring<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Importing your custom commands in Selenium</h4>
<p>Now that we have completed writing our own action command, it is time to import it to the Selenium IDE. Your custom commands are usually added to the file ‘user-extensions.js’. By default the ‘user-extensions.js’ file does not exist, so you need to first create a blank file into which you will add the above code. Once that is done you then need to tell Selenium to load the particular extension file from the ‘Options’ menu.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2010/01/selenium_options1.gif"><img src="http://www.codediesel.com/wp-content/uploads/2010/01/selenium_options1.gif" alt="selenium_options_page" title="selenium_options_page" width="428" height="376" class="size-full wp-image-2313" /></a></p>
<p>Once you have added the file to the options page you need to restart the Selenium IDE for the changes to take effect.</p>
<p><strong>Whenever you add some new code or make changes to the exiting one in the ‘user-extensions.js’, you need to restart the Selenium IDE for the changes to take effect.</strong></p>
<p>Now once you have restarted the IDE, you can see that your command has been added to the drop-down.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2010/01/selenium_options_2.gif"><img src="http://www.codediesel.com/wp-content/uploads/2010/01/selenium_options_2.gif" alt="selenium_ide" title="selenium_ide" width="398" height="516" class="aligncenter size-full wp-image-2319" /></a></p>
<h4>Writing other Action commands</h4>
<p>You may be wondering how to go about writing other Selenium Action commands; what the <em>this.browserbot</em> object means and where it is defined. Although no clear documentation exists, the Selenium source code can itself be a valuable tool. All the Selenium commands are stored in the &#8216;selenium-api.js&#8217; file. I have included it <a href="http://www.codediesel.com/data/code/selenium-api.js">here</a> for easy download and reference. The original source file and other support files are located in the &#8216;selenium-ide.jar&#8217; file in your Selenium installation directory. Unzip that file and you have all the Selenium source code at your disposal.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/testing/adding-custom-commands-to-the-selenium-ide/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Running Selenium TestRunner slowly</title>
		<link>http://www.codediesel.com/testing/running-selenium-testrunner-slowly/</link>
		<comments>http://www.codediesel.com/testing/running-selenium-testrunner-slowly/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 04:43:39 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[testing]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/sql/running-selenium-testrunner-slowly/</guid>
		<description><![CDATA[slow down the fast execution of selenium testrunner]]></description>
			<content:encoded><![CDATA[<p>By default Selenium TestRunner executes the test blindingly fast. You can however slow down the execution by using the speed controller slider in the right pane, which adds a maximum delay of 1 second after every command execution. But you have to do that manually for every test, and the maximum delay you get is 1 second. You can however increase the delay and also set the default delay rate by editing the <em>selenium-testrunner.js</em> file.<br />
<span id="more-2014"></span></p>
<h4>Editing the selenium-testrunner.js file</h4>
<p>First you have to find the &#8216;selenium-testrunner.js&#8217; file. It is located in your &#8216;Windows\Application Data&#8217; directory. The rough path is given below:</p>

<div class="wp_codebox"><table><tr id="p20142"><td class="code" id="p2014code2"><pre class="text" style="font-family:monospace;">Documents and Settings\Application Data\Mozilla\Firefox\
Profiles\extensions\{a6fd85ed-t567-s34f-a5af-ddf48bda539f}\content-files</pre></td></tr></table></div>

<p>Your exact directory path will be different. It is best do do a search for the file in your &#8216;Mozilla&#8217; directory. Once you have found it, you can look for the following lines of code:</p>

<div class="wp_codebox"><table><tr id="p20143"><td class="code" id="p2014code3"><pre class="javascript" style="font-family:monospace;">reset<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">runInterval</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">speedController</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">this</span>._switchContinueButtonToPause<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span></pre></td></tr></table></div>

<p>and replace it with:</p>

<div class="wp_codebox"><table><tr id="p20144"><td class="code" id="p2014code4"><pre class="javascript" style="font-family:monospace;">reset<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">runInterval</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">2000</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">this</span>._switchContinueButtonToPause<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span></pre></td></tr></table></div>

<p>This will by default add a 2 second delay after every command execution. Note that as we have made hardcoded changes to the speed variables, the speed slider in the TestRunner window will no longer have any effect on the execution.</p>
<h4>Setting the default speed controller delay to a high value</h4>
<p>In view of a recent comment, you can also set the default high delay for your slider by replacing the following lines in &#8216;selenium-testrunner.js&#8217;.</p>

<div class="wp_codebox"><table><tr id="p20145"><td class="code" id="p2014code5"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">speedController</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Control.<span style="color: #660066;">Slider</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'speedHandle'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'speedTrack'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
            range<span style="color: #339933;">:</span> $R<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            onSlide<span style="color: #339933;">:</span> fnBindAsEventListener<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setRunInterval</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            onChange<span style="color: #339933;">:</span> fnBindAsEventListener<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setRunInterval</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>with</p>

<div class="wp_codebox"><table><tr id="p20146"><td class="code" id="p2014code6"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">speedController</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Control.<span style="color: #660066;">Slider</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'speedHandle'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'speedTrack'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
            range<span style="color: #339933;">:</span> $R<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            onSlide<span style="color: #339933;">:</span> fnBindAsEventListener<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setRunInterval</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            onChange<span style="color: #339933;">:</span> fnBindAsEventListener<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setRunInterval</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Which will set the default delay to 100 milliseconds and the maximum to 5 seconds. Now you can also use the speed slider.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/testing/running-selenium-testrunner-slowly/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Selenium IDE Tutorial &#8211; Part 2</title>
		<link>http://www.codediesel.com/php/selenium-ide-tutorial-part-2/</link>
		<comments>http://www.codediesel.com/php/selenium-ide-tutorial-part-2/#comments</comments>
		<pubDate>Sat, 22 Nov 2008 05:49:01 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=114</guid>
		<description><![CDATA[In part 1 of this tutorial you have seen how to write a simple web test using Selenium. In this part we will see how to use the test generated using the IDE with Selenium RC and PHPUnit. In this part we will use Delicious as our test target. I&#8217;ve already created a small Selenium [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "ca-pub-3476693800710463";
/* 468x60, created 6/14/10 */
google_ad_slot = "3005910052";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>In <a title="selenium tutorial part 1" href="http://www.codediesel.com/php/selenium-ide-tutorial-part-1/" target="_self">part 1</a> of this tutorial you have seen how to write a simple web test using Selenium. In this part we will see how to use the test generated using the IDE with Selenium RC and PHPUnit.<br />
<span id="more-114"></span><br />
In this part we will use Delicious as our test target. I&#8217;ve already created a small Selenium test that you can use. You can download the HTML source from <a href="http://www.codediesel.com/data/scripts/delicious.html.txt">here</a>.</p>
<p><strong>Starting up.</strong><br />
Restart the Selenium IDE. In the source tab replace the default HTML with the one from the above file. Set the Base URL to http://delicious.com/. After doing this your IDE should like below.</p>
<p><a href='http://www.codediesel.com/wp-content/uploads/2008/11/selenium221.gif'><img src="http://www.codediesel.com/wp-content/uploads/2008/11/selenium221.gif" alt="selenium ide tutorial 2" title="selenium221" width="408" height="556" class="aligncenter size-full wp-image-132" /></a></p>
<p>If you are on a slow internet connection than it may help to slow the test speed.</p>
<p><a href='http://www.codediesel.com/wp-content/uploads/2008/11/selenium241.gif'><img src="http://www.codediesel.com/wp-content/uploads/2008/11/selenium241.gif"  style="border: 1px solid #c0c0c0;" alt="" title="selenium241" width="295" height="114" class="aligncenter size-full wp-image-135" /></a></p>
<p>So what exactly does this test do? Simple: </p>
<p>1. First it opens the delicious home page<br />
2. Then it searches by the keyword &#8216;selenium&#8217;<br />
3. Reads the total number of bookmarks from the results page as shown below</p>
<p><a href='http://www.codediesel.com/wp-content/uploads/2008/11/selenium23.gif'><img src="http://www.codediesel.com/wp-content/uploads/2008/11/selenium23.gif" style="border: 1px solid #c0c0c0;" alt="" title="selenium tutorial" width="500" height="255" class="aligncenter size-full wp-image-133" /></a></p>
<p>Now this may not look like a test for you , but it is just an exercise in using Selenium, you will surely apply it to a good test case. Onwards&#8230;</p>
<p>Before running this test make sure that you are logged out of Delicious.<br />
Now run the selenium IDE test. After the test is successfully completed this is what you should see in the log pane.</p>
<p><a href='http://www.codediesel.com/wp-content/uploads/2008/11/selenium25.gif'><img src="http://www.codediesel.com/wp-content/uploads/2008/11/selenium25.gif" alt="" title="selenium25" width="468" height="186" class="aligncenter size-full wp-image-136" /></a></p>
<p><strong>Is that all?</strong><br />
If this was all there was I wouldn&#8217;t be really writing this post. The interesting part comes now &#8211; running the same test from PHP. From the file menu select &#8216;Export Test Case As&#8230;&#8217; and as we are using PHP, select &#8216;PHP &#8211; Selenium RC&#8217;. Save the file by the name &#8216;Example.php&#8217;.</p>
<p><a href='http://www.codediesel.com/wp-content/uploads/2008/11/selenium26.gif'><img src="http://www.codediesel.com/wp-content/uploads/2008/11/selenium26.gif"  style="border: 1px solid #c0c0c0;" alt="" title="selenium26" width="469" height="363" class="aligncenter size-full wp-image-137" /></a></p>
<p>This is what we will get in the &#8216;Example.php&#8217; file.</p>

<div class="wp_codebox"><table><tr id="p11410"><td class="code" id="p114code10"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">'PHPUnit/Extensions/SeleniumTestCase.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Example <span style="color: #000000; font-weight: bold;">extends</span> PHPUnit_Extensions_SeleniumTestCase
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">function</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setBrowser</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;*chrome&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setBrowserUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://delicious.com/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">function</span> testMyTestCase<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">open</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;homepage-searchinput&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;selenium&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">click</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;homepage-searchsubmit&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">waitForPageToLoad</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;30000&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;xpath=/html/body[@id='index']/div
                         [@id='doc3']/div[@id='bd']/div
                         [@id='yui-main']/div[@id='content']/h3/div/em&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>A short notice.</strong><br />
Before we proceed a few points to consider. Make sure that the file name and the class name are the same, here &#8216;Example&#8217;. Say if you change the class name to &#8216;Delicious&#8217; make sure that you also change the file name to &#8216;Delicious.php&#8217;.</p>
<p>What the code basically does is it initializes the browser to &#8216;chrome&#8217; (you can set the browser to your preference by changing to &#8216;*iexplore&#8217; or &#8216;*firefox&#8217;);  sets the baseurl to &#8216;http://delicious.com/&#8217; and runs the test.</p>
<p><strong>Whats the complex looking line!?</strong><br />
Everything may look fine to you except maybe the last line &#8211; &#8216;$this->getText&#8230;&#8217;.  The function &#8216;getText&#8217; returns the text found at the element specified in the expression. The complex looking line is an xpath expression to the results element:</p>
<p><a href='http://www.codediesel.com/wp-content/uploads/2008/11/selenium27.gif'><img src="http://www.codediesel.com/wp-content/uploads/2008/11/selenium27.gif" style="border: 1px solid #c0c0c0;" alt="" title="selenium27" width="248" height="91" class="aligncenter size-full wp-image-138" /></a></p>
<p>You don&#8217;t have to rake your brains to find an xpath to an element. An easy way is to use the <a target="_blank" href="https://addons.mozilla.org/en-US/firefox/addon/1192">XPather </a>Firefox addon to get the xpath of any element on a page. After you download and install the addon, restart Firefox, right-click on any element and from the context menu select &#8216;Show in XPather&#8217;. XPather retrieves the xpath to the specified element, which you can than use in your test code.</p>
<p>Note: This site uses &#8216;delicious&#8217; as an example, so even some minor changes made by them to their site will render the xpath invalid, throwing an &#8216;element not found&#8217; error in selenium. If this happens please notify me or you can find the new xpath using the Xpather plugin.</p>
<p><strong>Downloading and installing Selenium RC</strong><br />
Selenium RC is a Java based command line server that starts browsers and runs commands you pass from your tests.</p>
<p>1. First make sure you have a Java runtime installed on your machine.<br />
2. Download Selenium RC from <a target="_blank" href="http://selenium-rc.seleniumhq.org/download.html">here</a>.<br />
3. After extracting the files from the archive copy the &#8216;selenium-server.jar&#8217; file to any directory you feel appropriate. I copied it to my PHP installations bin directory.<br />
4. Start the Selenium RC server from the command-line by issuing the following command:</p>
<p><em>java -jar selenium-server.jar</em></p>
<p>This will start the server on port 4444.<br />
5. Now the server is ready to accept test commands from your PHP script. Make sure you keep this server running till you finish testing.</p>
<p><strong>Installing PHPUnit</strong><br />
1. An easy way to install PHPUnit is to use the PEAR installer. The PEAR channel (pear.phpunit.de) is used to distribute PHPUnit so make sure that it is registered with your local PEAR environment: </p>
<p><em>pear channel-discover pear.phpunit.de</em></p>
<p>After the channel is registered install PHPUnit:</p>
<p><em>pear install phpunit/PHPUnit</em></p>
<p><strong>Actual testing</strong><br />
Now that PHPUnit is installed and the Selenium RC server is up and running, its time to run our test we saved before in our &#8216;Example.php&#8217; file. Type the following on your command-line:</p>
<p><em>phpunit Example</em></p>
<p>This will start the test. The PHPUnit Selenium driver will execute each test command from your file and send it to the Selenium server, which does the job of launching the appropriate browser, opening web pages, and performing various specified actions; and closing the browser after the test completes.</p>
<p>Now the above test does basically nothing important. So we will add some simple conditional statements to the code.</p>

<div class="wp_codebox"><table><tr id="p11411"><td class="code" id="p114code11"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">.</span>
<span style="color: #339933;">.</span>
    <span style="color: #000088;">$bookmarks</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;xpath=/html/body[@id='index']/div
                       [@id='doc3']/div[@id='bd']/div
                       [@id='yui-main']/div[@id='content']/h3/div/em&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$bookmarks</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">3000</span><span style="color: #009900;">&#41;</span>? <span style="color: #0000ff;">&quot;On the top&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Still not there&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This is what PHPUnit has to say about the above test.</p>
<p><a href='http://www.codediesel.com/wp-content/uploads/2008/11/selenium28.gif'><img src="http://www.codediesel.com/wp-content/uploads/2008/11/selenium28.gif" style="border: 1px solid #c0c0c0;"  alt="" title="selenium28" width="477" height="244" class="aligncenter size-full wp-image-139" /></a></p>
<p>Or we can use an assertion as below, deliberately rigged to fail the test:</p>

<div class="wp_codebox"><table><tr id="p11412"><td class="code" id="p114code12"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">.</span>
<span style="color: #339933;">.</span>
    <span style="color: #000088;">$bookmarks</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;xpath=/html/body[@id='index']/div
                       [@id='doc3']/div[@id='bd']/div
                       [@id='yui-main']/div[@id='content']/h3/div/em&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertGreaterThan</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">33000</span><span style="color: #339933;">,</span> <span style="color: #000088;">$bookmarks</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Now PHPUnit will shout failure:</p>
<p><a href='http://www.codediesel.com/wp-content/uploads/2008/11/selenium29.gif'><img src="http://www.codediesel.com/wp-content/uploads/2008/11/selenium29.gif" alt="" title="selenium29" width="500" height="269" class="aligncenter size-full wp-image-140" /></a></p>
<p>You can look at more functions to implement in your tests <a target="_blank" href="http://www.phpunit.de/wiki/Documentation">here</a> and <a target="_blank" href="http://selenium-core.seleniumhq.org/reference.html">here</a>. </p>
<p>This concludes the second part of the tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/selenium-ide-tutorial-part-2/feed/</wfw:commentRss>
		<slash:comments>61</slash:comments>
		</item>
		<item>
		<title>Selenium IDE Tutorial &#8211; Part 1</title>
		<link>http://www.codediesel.com/php/selenium-ide-tutorial-part-1/</link>
		<comments>http://www.codediesel.com/php/selenium-ide-tutorial-part-1/#comments</comments>
		<pubDate>Thu, 09 Oct 2008 06:34:32 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=105</guid>
		<description><![CDATA[Selenium IDE tutorial for php programmers]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "ca-pub-3476693800710463";
/* 468x60, created 6/14/10 */
google_ad_slot = "3005910052";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p><strong>Selenium IDE</strong> is an integrated development environment for performing <a href="http://www.openqa.org/selenium/">Selenium</a> tests.  Selenium tests can be written as HTML tables or coded in various languages like C#, PHP, Perl, Python and can be run directly in most modern browsers.The IDE can help you to record, edit and debug tests. Currently the IDE is only available for Firefox (as if we developers will use any other) as a addon.</p>
<p>Here is a possible scenario for using Selenium. Imagine you have created a HTML form with about twenty fields and you have to repeatedly test the form. Filling the form every time can quickly become tedious. With Selenium you can automate the whole process and run the test as required. In this part we will see how to create a simple test in Selenium. So let&#8217;s get started.<br />
<span id="more-105"></span><br />
<strong>STEP 1 &#8211; installation :</strong></p>
<p>You can download Selenium IDE from this locations.<br />
<a title="selenium ide" href="http://selenium-ide.openqa.org/download.jsp" target="_blank">http://selenium-ide.openqa.org/download.jsp</a><br />
<a title="selenium ide" href="https://addons.mozilla.org/en-US/firefox/addon/2079" target="_blank">https://addons.mozilla.org/en-US/firefox/addon/2079</a><br />
Once the addon is installed make sure you do not forget to restart Firefox.</p>
<p><strong>STEP 2 &#8211; running a simple test : </strong></p>
<p>a. Start Selenium IDE  in Firefox: <em>Tools-&gt;Selenium IDE</em>. You will see the following popup.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2008/10/selenium1.gif"><img class="aligncenter size-full wp-image-107" title="selenium1" src="http://www.codediesel.com/wp-content/uploads/2008/10/selenium1.gif" alt="selenium" /></a></p>
<p>b. Click on the red record button on the right.<br />
c. Browse to Google.com and enter &#8216;selenium&#8217; in the search box and click enter.<br />
d. Click on the first result, which is that of selenium.openqa.org.<br />
e. Stop the recording by clicking on the record button.</p>
<p>You should see something like below. If you click on the &#8216; Source&#8217; tab you can see the test html generated by selenium.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2008/10/selenium2.gif"><img class="aligncenter size-full wp-image-108" title="selenium2" src="http://www.codediesel.com/wp-content/uploads/2008/10/selenium2.gif" alt="selenium ide" width="403" height="521" /></a></p>
<p>The &#8216;table&#8217; tab shows the commands recorded by Selenium.</p>
<p>f. Open a new tab in Firefox and click on the Selenium IDE&#8217;s play button to run the recorded test.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2008/10/selenium3.gif"><img class="aligncenter size-full wp-image-109" style="border:1px solid #c0c0c0;" title="selenium3" src="http://www.codediesel.com/wp-content/uploads/2008/10/selenium3.gif" alt="selenium ide" width="388" height="109" /></a></p>
<p>The IDE should play your recorded test. After the test is complete you should have landed on the selenium page (http://selenium.openqa.org/). The IDE after the test run is shown below. In the &#8216;Log section&#8217; you can see the various events run by the test. In the table tab you can see that all the rows are green, which means that the test ran successfully.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2008/10/selenium4.gif"><img class="aligncenter size-full wp-image-110" title="selenium4" src="http://www.codediesel.com/wp-content/uploads/2008/10/selenium4.gif" alt="selenium test run" width="399" height="521" /></a></p>
<p>Now lets add a small assertion to the above test.</p>
<p>a. Click on the blank line below after the last &#8216;clickAndWait&#8217; command and insert &#8216;assertTextPresent&#8217; command from the drop down box as shown below. You should see something like this.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2008/10/selenium51.gif"><img class="aligncenter size-full wp-image-112" title="selenium51" src="http://www.codediesel.com/wp-content/uploads/2008/10/selenium51.gif" alt="" width="437" height="366" /></a></p>
<p>This test checks to see if the text &#8216;Selenium News&#8217; is present in the last rendered page. Run the test again and you should see that the test has run successfully. No try replacing the text with something that is not present on the page, take for example &#8216;elvis&#8217; and run the test again. Now the test fails and you should get the screen below.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2008/10/selenium6.gif"><img class="aligncenter size-full wp-image-113" title="selenium6" src="http://www.codediesel.com/wp-content/uploads/2008/10/selenium6.gif" alt="" width="436" height="563" /></a></p>
<p>You have just completed your first test run. And it was so simple.</p>
<p>&#8216;assertTextPresent&#8217; is one of the hundreds of commands available for your testing needs. Just browse throught the command drop down to get a feel of what you can you get.</p>
<p>In the next part we will see more advanced features of Selenium.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/selenium-ide-tutorial-part-1/feed/</wfw:commentRss>
		<slash:comments>62</slash:comments>
		</item>
	</channel>
</rss>

