<?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>Ecommerce Ninja - The Zachary Fox Blog &#187; Testing</title>
	<atom:link href="http://www.zacharyfox.com/blog/category/testing/feed" rel="self" type="application/rss+xml" />
	<link>http://www.zacharyfox.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 18 Sep 2009 15:36:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Selenium RC With Multiple Users</title>
		<link>http://www.zacharyfox.com/blog/testing/selenium-rc-multiple-users</link>
		<comments>http://www.zacharyfox.com/blog/testing/selenium-rc-multiple-users#comments</comments>
		<pubDate>Thu, 13 Mar 2008 17:33:31 +0000</pubDate>
		<dc:creator>Zachary Fox</dc:creator>
				<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.zacharyfox.com/blog/testing/selenium-rc-multiple-users</guid>
		<description><![CDATA[So you may be testing with selenium already, you may even be using selenium RC to automate your testing and integrate it with your other unit tests, and you may already be doing so in a shared development environment, but if you aren&#8217;t using selenium RC with multiple users, you may not know that you [...]]]></description>
			<content:encoded><![CDATA[<p>So you may be <a href="http://pessoal.org/blog/2008/03/07/web-app-testing-with-selenium/">testing with selenium</a> already, you may even be using selenium RC to automate your testing and integrate it with your other unit tests, and you may already be doing so in a shared development environment, but if you aren&#8217;t using selenium RC with multiple users, you may not know that you can start the RC server on any port you wish, allowing multiple clients to connect at the same time.</p>
<p>To start the selenium RC server, you would typically run this command:</p>
<pre class="code">
java -jar selenium-server.jar</pre>
<p>Which will start it on the default port of 4444. If you want to start it on another port, simply add -port &lt;portnumber&gt; to the command like this:</p>
<pre class="code">
java -jar selenium-server.jar -port 1234</pre>
<p>This command would start the server on port 1234.</p>
<p><strong>Great, now I can  start the server on multiple ports, so what?</strong></p>
<p>So here is the good news for those of us in shared development environments. Say you have a windows virtual machine running selenium with your test browser installed. Things get complicated when multiple clients are testing at the same time. Tests can fail unexpectedly, developers begin fighting for time on the test server, and all hell breaks loose. By running multiple servers on different ports, we can avoid the third world war. Everyone can connect at the same time to their personal server, and we have peace and harmony in our testing environment.</p>
<p><strong>Wow, setting up a different port everytime must suck.</strong></p>
<p>Not really. There are many ways that you can automate the process so that it&#8217;s completely transparent to your development team. A lot will depend on your environment, but in our case, we created a .bat file that starts the servers in our virtual machine and placed it in the start-up folder.</p>
<pre class="vci_code">
<span class="c29">start</span> <span class="c27">&quot;Selenium </span><span class="c27">4444</span><span class="c27">&quot;</span> <span class="c28">/min</span> java.exe -jar selenium-server.jar -port <span class="c27">4444</span>
<span class="c29">start</span> <span class="c27">&quot;Selenium </span><span class="c27">4445</span><span class="c27">&quot;</span> <span class="c28">/min</span> java.exe -jar selenium-server.jar -port <span class="c27">4445</span>
<span class="c29">start</span> <span class="c27">&quot;Selenium </span><span class="c27">4446</span><span class="c27">&quot;</span> <span class="c28">/min</span> java.exe -jar selenium-server.jar -port <span class="c27">4446</span>
<span class="c29">start</span> <span class="c27">&quot;Selenium </span><span class="c27">4447</span><span class="c27">&quot;</span> <span class="c28">/min</span> java.exe -jar selenium-server.jar -port <span class="c27">4447</span>
</pre>
<p class="vci_info">HTML code generated by <a href="http://www.zacharyfox.com/blog/free-tools/vim-color-improved">vim-color-improved v.0.4.0.</a><strong>Download this code:</strong> <a href="http://www.zacharyfox.com/code/selenium/selenium.bat">selenium.bat</a></p>
<p>With this in place, we now have 4 selenium RC servers running at all times. If one or more crashes for any reason, running the batch file again will start any that are missing. The selenium RC server will not start if its port is in use, so only the ones missing will run, and you&#8217;ll have them all up and running again.</p>
<p><strong>Ok, what about the client side? I don&#8217;t want to have to edit another file in my development environment. </strong></p>
<p>On the client side, we are using phpunit with <a href="http://pear.php.net/package/Testing_Selenium/">Testing_Selenium</a>. Of course all of our selenium test classes extend a parent class, so it was easy enough for us to create some dynamic logic there to decide which port to use.</p>
<pre class="vci_code">
<span class="c28">&lt;?php</span>
<span class="c32">class</span> SeleniumTestHelper
<span class="c28">{</span>
    public <span class="c31">function</span> setup<span class="c28">()</span>
    <span class="c28">{</span>
        <span class="c30">$</span><span class="c29">ports</span> <span class="c30">=</span> <span class="c32">array</span><span class="c28">(</span>'<span class="c27">user1</span>' <span class="c30">=</span><span class="c30">&gt;</span> <span class="c27">4444</span>,
                       '<span class="c27">user2</span>' <span class="c30">=</span><span class="c30">&gt;</span> <span class="c27">4445</span>,
                       '<span class="c27">user3</span>' <span class="c30">=</span><span class="c30">&gt;</span> <span class="c27">4446</span>,
                       '<span class="c27">user4</span>' <span class="c30">=</span><span class="c30">&gt;</span> <span class="c27">4447</span><span class="c28">)</span>;
        <span class="c30">$</span><span class="c29">user</span> <span class="c30">=</span> someFunctionThatDeterminesUser<span class="c28">()</span>;
        <span class="c29">define</span><span class="c28">(</span>'<span class="c27">BROWSER</span>', '<span class="c27">*firefox</span>'<span class="c28">)</span>;
        <span class="c29">define</span><span class="c28">(</span>'<span class="c27">URL</span>', '<span class="c27">http://www.example.com</span>'<span class="c28">)</span>;
        <span class="c29">define</span><span class="c28">(</span>'<span class="c27">SERVER</span>', '<span class="c27">192.168.0.2</span>'<span class="c28">)</span>;
        <span class="c29">define</span><span class="c28">(</span>'<span class="c27">PORT</span>', <span class="c30">$</span><span class="c29">ports</span><span class="c28">[</span><span class="c30">$</span><span class="c29">user</span><span class="c28">])</span>;
        <span class="c30">$</span><span class="c29">this</span><span class="c32">-&gt;</span>selenium <span class="c30">=</span> <span class="c31">new</span> Testing_Selenium<span class="c28">(</span>BROWSER, URL, SERVER, PORT<span class="c28">)</span>;
    <span class="c28">}</span>
<span class="c28">}</span>
<span class="c28">?&gt;</span>
</pre>
<p class="vci_info">HTML code generated by <a href="http://www.zacharyfox.com/blog/free-tools/vim-color-improved">vim-color-improved v.0.4.0.</a><strong>Download this code:</strong> <a href="http://www.zacharyfox.com/code/selenium/SeleniumTestHelper.php">SeleniumTestHelper.php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zacharyfox.com/blog/testing/selenium-rc-multiple-users/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
