<?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>Adam Christian &#187; Python</title>
	<atom:link href="http://www.adamchristian.com/archives/tag/python/feed" rel="self" type="application/rss+xml" />
	<link>http://www.adamchristian.com</link>
	<description></description>
	<lastBuildDate>Wed, 08 Feb 2012 17:41:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>This thing I&#8217;m calling Windmill-Lite</title>
		<link>http://www.adamchristian.com/archives/102</link>
		<comments>http://www.adamchristian.com/archives/102#comments</comments>
		<pubDate>Wed, 14 Jan 2009 00:28:49 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Github]]></category>
		<category><![CDATA[JSmin]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Windmill]]></category>

		<guid isPermaLink="false">http://adamchristian.com/?p=102</guid>
		<description><![CDATA[In preparation for the Windmill 2 client side re-architecting, and an article I am writing about simulating user sessions with JavaScript, I decided it was time to go through the Windmill JavaScript source and pull out the pieces necessary to drive a user session in JavaScript. It turns out that it&#8217;s easily broken into a [...]]]></description>
			<content:encoded><![CDATA[<p>In preparation for the Windmill 2 client side re-architecting, and an article I am writing about simulating user sessions with JavaScript, I decided it was time to go through the Windmill JavaScript source and pull out the pieces necessary to drive a user session in JavaScript.</p>
<p>It turns out that it&#8217;s easily broken into a few pieces:</p>
<ul>
<li><strong>Events</strong>: Cross browser compatible event firing functionality</li>
<li><strong>ElementsLib</strong>: DOM element lookup functionality via many methods called &#8216;locators&#8217;</li>
<li><strong>Controller</strong>: The logic for firing the right events to simulate user actions such as &#8216;type&#8217;</li>
</ul>
<p>In order to test all the functionality I wrote a small runner implementation, which was actually pretty fun and interested because of the need for waits and sleeps. As I didn&#8217;t want to have a continuous loop running, which has been the standard solution up to this point I decided to go about mine using a execution queue instead.</p>
<p>By &#8216;queue&#8217; I mean that I&#8217;m using a JavaScript array with push and shift to keep track of what user actions need to be executed next. When a new action is pushed, if there is nothing in the stack it immediately executes, however if there are actions in the stack waiting those are then executed in order then it is executed. This works great, however there is one more level of complexity here involving sleeps and waits. If a sleep or wait is called a flag is set called &#8216;asleep&#8217;, that tells the executor to pop any new actions onto the stack instead of trying to execute them. When the sleep is done the asleep flag is turned off and all the actions in the stack that have been queued up are then executed in order.</p>
<p><strong>Tests are very simple.</strong><br />
<code><br />
var test_run = function(){<br />
wm.user('type',{'text':'testing', 'name':'q'});<br />
wm.user('waits.sleep', {'ms':5000});<br />
wm.user('type',{'text':'numbertwo', 'name':'q'});<br />
wm.user('asserts.assertValue', {'name':'q', 'validator':'numbertwo'})<br />
wm.user('waits.sleep', {'ms':3000});<br />
wm.user('type',{'text':'finally', 'name':'q'});<br />
wm.user('asserts.assertValue', {'name':'q', 'validator':'finally'})<br />
}<br />
</code></p>
<p>This test can be executed against the Google Home page, and it simply types text in to the search box, sleeps a few times and asserts that the value typed in is actually in the form field when it should be. wm is the windmill code namespace, and user is the dispatch function that takes the method to executed and it&#8217;s parameters as an object.</p>
<p>Obviously as this was all taken out of the Windmill source all of the JUM functions are also available in wm.ctrl.asserts if you would like to mix them into your test.</p>
<p><strong>So how would one use this?</strong></p>
<p>There are actually a couple ways, one is to include the source in the page you want to test:<br />
<code><br />
&lt;script src="http://adamchristian.com/wmlite/wm-lite.js" type="text/javascript"&gt;&lt;/script&gt;<br />
</code></p>
<p>or you can use the JavaScript Console to inject it into your page:<br />
<code><br />
x = document.createElement('script')<br />
x.src = "http://adamchristian.com/wmlite/wm-lite.js"<br />
document.body.appendChild(x)<br />
</code></p>
<p>There is code that is executed when this file is included that figures out if the page has been loaded, if it has it calls in init function to enable the key shortcut listeners. If the page hasn&#8217;t been loaded, the window onload is pointed at the init so you are sure to have the shortcuts available to access the UI.</p>
<p>The short-cut is ALT-T. I was thinking &#8216;test&#8217;, meta-t and ctrl-t are almost always assigned by the browser but alt appears to work in all my test cases.</p>
<p>&#8220;Windmill-Lite UI Screenshot&#8221;</p>
<p><img class="alignnone size-medium wp-image-103" title="Windmill Lite UI" src="http://www.adamchristian.com/wp-content/uploads/2009/01/picture-2-300x126.png" alt="Windmill Lite UI" width="300" height="126" /></p>
<p><strong>Why?</strong></p>
<p>I don&#8217;t have a specific use case for this code/project but I know there are many uses out there for the functionality in the libraries, and for a low overhead cross browser litmus test tool it has some serious potential&#8230; also, it was fun.</p>
<p><strong>Links</strong></p>
<ul>
<li><strong>GitHub:</strong> <a href="http://github.com/admc/windmill-lite/tree/master">http://github.com/admc/windmill-lite/tree/master</a></li>
<li><strong>Compressed: </strong><a href="http://adamchristian.com/wmlite/wm-lite.js">http://adamchristian.com/wmlite/wm-lite.js</a></li>
</ul>
<p><strong><br />
Additional Coolness</strong></p>
<p>I&#8217;m sure there is something like this out there, but I got pretty annoyed trying to use various JavaScript compressor tools to make a single minified file, so I hacked one together in Python called &#8216;compressjsdir&#8217;. It requires jsmin.py, and you can find a zip of everything required here: <a href="http://adamchristian.com/code/compressjsdir.zip">http://adamchristian.com/code/compressjsdir.zip</a>, or grab the source from github: <a href="http://github.com/admc/compressjsdir/tree/master">http://github.com/admc/compressjsdir/tree/master</a></p>
<p>To run it you can simply do the following (after you put the compressjsdir directory in your path):<br />
<code><br />
dhcp-10-10-9-230% cd directory_of_js_files<br />
dhcp-10-10-9-230% compressjsdir.py<br />
Reading and compressing...<br />
Writing file...<br />
</code></p>
<p>There should now be a file called out.js, which is composed of all the js files in the directory minified and concatted together. This is all based on the JS compressor code <a href="http://www.mikealrogers.com">Mikeal Rogers</a> wrote for Windmill in our quest for performance.</p>
<p>I will be adding a couple easy features in the next few days, one of course is to take a parameter used to name the output file, and the other argument will be a comma delimited list for ordering of the files as they are minified and appear in the result (in case  you have dependent files).</p>
<p><strong>More</strong></p>
<p>If you are interested in more related or similar projects, you may want to check out <a href="http://fireunit.org/">FireUnit</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamchristian.com/archives/102/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zero to Continuous Integration with Windmill</title>
		<link>http://www.adamchristian.com/archives/43</link>
		<comments>http://www.adamchristian.com/archives/43#comments</comments>
		<pubDate>Fri, 19 Sep 2008 02:29:58 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[Hudson]]></category>
		<category><![CDATA[Slide]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Windmill]]></category>
		<category><![CDATA[Windmill-dev]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[Continuous]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://adamchristian.com/?p=43</guid>
		<description><![CDATA[Following &#8216;automation&#8217; and &#8216;continuous integration&#8217; in the micro blogging world I have seen a major influx in people being super interested in functionally automating their web apps. I have seen a slew of things about Grid, and Selenium, and people hacking on Watir so I decided to show you from the ground up how incredibly [...]]]></description>
			<content:encoded><![CDATA[<p>Following &#8216;automation&#8217; and &#8216;continuous integration&#8217; in the micro blogging world I have seen a major influx in people being super interested in functionally automating their web apps. I have seen a slew of things about Grid, and Selenium, and people hacking on Watir so I decided to show you from the ground up how incredibly easy it is to get automated test running setup using <a href="http://www.getwindmill.com">Windmill</a> and <a href="http://hudson.gotdns.com/wiki/display/HUDSON/Meet+Hudson#Installation">Hudson</a>. I am not going to walk you through every detail, this is much more high level but I do plan to start a &#8216;continuous integration&#8217; page on getwindmill.com in the near future for those kinds of details.</p>
<p>The first step is to get a couple machines that you want use as slaves and a machine to run Hudson, our setup looks like this:</p>
<p><a href="http://adamchristian.com/wp-content/uploads/2008/09/arch.png"><img class="alignnone size-medium wp-image-44" title="Windmill/Hudson Arch" src="http://adamchristian.com/wp-content/uploads/2008/09/arch.png" alt="" width="291" height="191" /></a></p>
<p>Each of the machines with a different OS has <a href="http://www.getwindmill.com">Windmill</a> installed. To make them slaves you simply bring up the Hudson web page on the machine, and run the launcher.. now it&#8217;s a slave &#8212; crazy easy right?</p>
<p>Now to setup test runs for the machines, in Hudson you click: &#8220;New Job&#8221; on the left hand side and do something like the following:</p>
<p><strong>Tie this job to the slave you want it to run on (we can&#8217;t have IE runs happening on MacOSX):<br />
</strong><span style="color: #0000ee;"><span style="color: #000000;"><img class="alignnone size-full wp-image-55" title="tie_node" src="http://adamchristian.com/wp-content/uploads/2008/09/tie_node.png" alt="" width="500" height="55" /></span></span></p>
<p><strong>Tell this job to run 10 and 30 minutes after the hour:<br />
</strong><a href="http://adamchristian.com/wp-content/uploads/2008/09/build_periodic2.png"><img class="alignnone size-full wp-image-50" title="build_periodic2" src="http://adamchristian.com/wp-content/uploads/2008/09/build_periodic2.png" alt="" width="500" height="69" /></a></p>
<p><strong>The build steps to actually run the tests, the first kills any straggling processes (more details below):<br />
</strong><a href="http://adamchristian.com/wp-content/uploads/2008/09/build_steps1.png"><img class="alignnone size-full wp-image-51" title="build_steps" src="http://adamchristian.com/wp-content/uploads/2008/09/build_steps1.png" alt="" width="353" height="328" /></a></p>
<p>On the Mac for the Safari job, I want to make sure there aren&#8217;t any instances of Safari left hanging, or windmill processes sitting around so we do:<br />
<code>ps -ax | grep windmill | awk '{ print $1 }' | xargs kill  | true<br />
ps -ax | grep Safari | awk '{ print $1 }' | xargs kill | true<br />
</code></p>
<p>Then we want to grab the latest test code from svn and launch the windmill test:<br />
<code>svn up /Users/adam/Documents/main_bt/windmill/<br />
python /usr/local/bin/windmill safari http://www.facebook.com test=/Users/adam/Documents/main_bt/windmill/fb email=username@slide.com password=pass report=true exit<br />
rm /Users/adam/Library/Cookies/Cookies.plist<br />
</code></p>
<p>I am telling windmill to run a test against facebook.com, with the test hierarchy in the windmill/fb directory in Safari, with the provided email and password, then to report it&#8217;s results and exit.</p>
<p>The only thing different on our windows test runs is the way we kill the processes:<br />
Example:<br />
<code>taskkill /F /T /IM windmill.exe<br />
taskkill /F /T /IM firefox.exe<br />
</code></p>
<p>You might be asking how do I use those variables, check it out in my setup module:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> setup_module<span style="color: black;">&#40;</span>module<span style="color: black;">&#41;</span>:
    client = WindmillTestClient<span style="color: black;">&#40;</span>__name__<span style="color: black;">&#41;</span>
    client.<span style="color: #008000;">type</span><span style="color: black;">&#40;</span>text=functest.<span style="color: black;">registry</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'email'</span><span style="color: black;">&#93;</span>, <span style="color: #008000;">id</span>=u<span style="color: #483d8b;">'email'</span><span style="color: black;">&#41;</span>
    client.<span style="color: #008000;">type</span><span style="color: black;">&#40;</span>text=functest.<span style="color: black;">registry</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'password'</span><span style="color: black;">&#93;</span>, <span style="color: #008000;">id</span>=u<span style="color: #483d8b;">'pass'</span><span style="color: black;">&#41;</span>
    client.<span style="color: black;">click</span><span style="color: black;">&#40;</span><span style="color: #008000;">id</span>=u<span style="color: #483d8b;">'doquicklogin'</span><span style="color: black;">&#41;</span>
    client.<span style="color: black;">waits</span>.<span style="color: black;">forPageLoad</span><span style="color: black;">&#40;</span>timeout=u<span style="color: #483d8b;">'100000'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>You can also read a great entry about adding reporting to your tests on Mikeal Rogers blog, <a href="http://www.mikealrogers.com/archives/46">here.</a></p>
<p>And that last line removing Cookies.plist makes sure that the next test run starts without any cookies set to cause problems.</p>
<p><strong>Have Hudson keep you updated on Jabber:</strong></p>
<p><a href="http://adamchristian.com/wp-content/uploads/2008/09/jabber1.png"><img class="alignnone size-full wp-image-52" title="jabber1" src="http://adamchristian.com/wp-content/uploads/2008/09/jabber1.png" alt="" width="500" height="97" /></a></p>
<p><strong>Grab the generated XML output so you can view the test results in Hudson:</strong></p>
<p><img class="alignnone size-full wp-image-54" title="publish_junit" src="http://adamchristian.com/wp-content/uploads/2008/09/publish_junit.png" alt="" width="500" height="58" /></p>
<p><strong>Do this for each of the test runs you would like to have, and boom &#8212; continuous integration:</strong></p>
<p><a href="http://adamchristian.com/wp-content/uploads/2008/09/jobs_dash1.png"><img class="alignnone size-medium wp-image-53" title="jobs_dash" src="http://adamchristian.com/wp-content/uploads/2008/09/jobs_dash1-300x148.png" alt="" width="300" height="148" /></a></p>
<p>This is obviously a simple scenario, and you can do way, way more customization.. but this should get you off the ground. Happy testing!</p>
<p><span style="text-decoration: underline;"><br />
</span><br />
 </p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamchristian.com/archives/43/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: www.adamchristian.com @ 2012-02-09 11:42:27 -->
