<?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; JSmin</title>
	<atom:link href="http://www.adamchristian.com/archives/tag/jsmin/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>
	</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:29:54 -->
