Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
763 lines (703 sloc) 43.3 KB
<a href="http://github.com/learnboost/soda"><img alt="Fork me on GitHub" id="ribbon" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a><html>
<head>
<title>Soda</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<style>body {
margin: 0;
padding: 0;
font: 14px/1.5 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
color: #252519;
}
a {
color: #252519;
}
a:hover {
text-decoration: underline;
color: #19469D;
}
p {
margin: 12px 0;
}
h1, h2, h3 {
margin: 0;
padding: 0;
}
table#source {
width: 100%;
border-collapse: collapse;
}
table#source td:first-child {
padding: 30px 40px 30px 40px;
vertical-align: top;
}
table#source td:first-child,
table#source td:first-child pre {
width: 450px;
}
table#source td:last-child {
padding: 30px 0 30px 40px;
border-left: 1px solid #E5E5EE;
background: #F5F5FF;
}
table#source tr {
border-bottom: 1px solid #E5E5EE;
}
table#source tr.filename {
padding-top: 40px;
border-top: 1px solid #E5E5EE;
}
table#source tr.filename td:first-child {
text-transform: capitalize;
}
table#source tr.filename td:last-child {
font-size: 12px;
}
table#source tr.filename h2 {
margin: 0;
padding: 0;
cursor: pointer;
}
table#source tr.code h1,
table#source tr.code h2,
table#source tr.code h3 {
margin-top: 30px;
font-family: "Lucida Grande", "Helvetica Nueue", Arial, sans-serif;
font-size: 18px;
}
table#source tr.code h2 {
font-size: 16px;
}
table#source tr.code h3 {
font-size: 14px;
}
table#source tr.code ul {
margin: 15px 0 15px 35px;
padding: 0;
}
table#source tr.code ul li {
margin: 0;
padding: 1px 0;
}
table#source tr.code ul li p {
margin: 0;
padding: 0;
}
table#source tr.code td:first-child pre {
padding: 20px;
}
#ribbon {
position: fixed;
top: 0;
right: 0;
}
code .string { color: #219161; }
code .regexp { color: #219161; }
code .keyword { color: #954121; }
code .number { color: #19469D; }
code .comment { color: #bbb; }
code .this { color: #19469D; }</style>
<script>
$(function(){
$('tr.code').hide();
$('tr.filename').toggle(function(){
$(this).nextUntil('.filename').fadeIn();
}, function(){
$(this).nextUntil('.filename').fadeOut();
});
});
</script>
</head>
<body>
<table id="source"><tbody><tr><td><h1>Soda</h1><p>The <em>Selenium Node Adapter</em> or <strong>Soda</strong> provides a unified client to both <a href="http://seleniumhq.org/projects/remote-control/">Selenium RC</a> and <a href="http://saucelabs.com/ondemand">Saucelabs OnDemand</a>.</p></td><td></td></tr><tr class="filename"><td><h2 id="lib/soda/client.js"><a href="#">client</a></h2></td><td>lib/soda/client.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
</p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>)
, <span class="variable">qs</span> = <span class="variable">require</span>(<span class="string">'querystring'</span>)
, <span class="class">EventEmitter</span> = <span class="variable">require</span>(<span class="string">'events'</span>).<span class="class">EventEmitter</span>;</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Initialize a <code>Client</code> with the given <code>options</code>.</p>
<h2>Options</h2>
<ul><li><code>host</code> Hostname defaulting to localhost</li><li><code>port</code> Port number defaulting to 4444</li><li><code>browser</code> Browser name</li><li><code>url</code> URL string</li></ul>
<h2></h2>
<ul><li><p><strong>params</strong>: <em>Object</em> options</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Client</span> = <span class="variable">exports</span> = <span class="variable">module</span>.<span class="variable">exports</span> = <span class="keyword">function</span> <span class="class">Client</span>(<span class="variable">options</span>) {
<span class="this">this</span>.<span class="variable">host</span> = <span class="variable">options</span>.<span class="variable">host</span> || <span class="string">'localhost'</span>;
<span class="this">this</span>.<span class="variable">port</span> = <span class="variable">options</span>.<span class="variable">port</span> || <span class="number integer">4444</span>;
<span class="this">this</span>.<span class="variable">browser</span> = <span class="variable">options</span>.<span class="variable">browser</span> || <span class="string">'firefox'</span>;
<span class="this">this</span>.<span class="variable">url</span> = <span class="variable">options</span>.<span class="variable">url</span>;
<span class="comment">// Allow optional &quot;*&quot; prefix</span>
<span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">browser</span>[<span class="number integer">0</span>] !== <span class="string">'*'</span>) {
<span class="this">this</span>.<span class="variable">browser</span> = <span class="string">'*'</span> + <span class="this">this</span>.<span class="variable">browser</span>;
}
<span class="class">EventEmitter</span>.<span class="variable">call</span>(<span class="this">this</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Interit from <code>EventEmitter</code>.
</p>
</td>
<td class="code">
<pre><code><span class="class">Client</span>.<span class="variable">prototype</span>.<span class="variable">__proto__</span> = <span class="class">EventEmitter</span>.<span class="variable">prototype</span>;</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Initialize a new session, then callback <code>fn(err, sid)</code></p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Client</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Client</span>.<span class="variable">prototype</span>.<span class="variable">session</span> = <span class="keyword">function</span>(<span class="variable">fn</span>){
<span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;
<span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">browser</span>) <span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="string">'browser required'</span>);
<span class="keyword">if</span> (!<span class="this">this</span>.<span class="variable">url</span>) <span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="string">'browser url required'</span>);
<span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">queue</span>) {
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">enqueue</span>(<span class="string">'getNewBrowserSession'</span>, [<span class="this">this</span>.<span class="variable">browser</span>, <span class="this">this</span>.<span class="variable">url</span>], <span class="keyword">function</span>(<span class="variable">body</span>){
<span class="variable">self</span>.<span class="variable">sid</span> = <span class="variable">body</span>;
});
} <span class="keyword">else</span> {
<span class="this">this</span>.<span class="variable">command</span>(<span class="string">'getNewBrowserSession'</span>, [<span class="this">this</span>.<span class="variable">browser</span>, <span class="this">this</span>.<span class="variable">url</span>], <span class="keyword">function</span>(<span class="variable">err</span>, <span class="variable">body</span>){
<span class="keyword">if</span> (<span class="variable">err</span>) <span class="keyword">return</span> <span class="variable">fn</span>(<span class="variable">err</span>);
<span class="variable">fn</span>(<span class="keyword">null</span>, <span class="variable">self</span>.<span class="variable">sid</span> = <span class="variable">body</span>);
});
}
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Execute the given <code>cmd</code> / <code>args</code>, then callback <code>fn(err, body, res)</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> cmd</p></li><li><p><strong>param</strong>: <em>Array</em> args</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Client</em> for chaining</p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Client</span>.<span class="variable">prototype</span>.<span class="variable">command</span> = <span class="keyword">function</span>(<span class="variable">cmd</span>, <span class="variable">args</span>, <span class="variable">fn</span>){
<span class="this">this</span>.<span class="variable">emit</span>(<span class="string">'command'</span>, <span class="variable">cmd</span>, <span class="variable">args</span>);
<span class="comment">// HTTP client</span>
<span class="keyword">var</span> <span class="variable">client</span> = <span class="variable">http</span>.<span class="variable">createClient</span>(<span class="this">this</span>.<span class="variable">port</span>, <span class="this">this</span>.<span class="variable">host</span>);
<span class="comment">// Path construction</span>
<span class="keyword">var</span> <span class="variable">path</span> = <span class="this">this</span>.<span class="variable">commandPath</span>(<span class="variable">cmd</span>, <span class="variable">args</span>);
<span class="comment">// Request</span>
<span class="keyword">var</span> <span class="variable">req</span> = <span class="variable">client</span>.<span class="variable">request</span>(<span class="string">'GET'</span>
, <span class="variable">path</span>
, { <span class="class">Host</span>: <span class="this">this</span>.<span class="variable">host</span> + (<span class="this">this</span>.<span class="variable">port</span> ? <span class="string">':'</span> + <span class="this">this</span>.<span class="variable">port</span> : <span class="string">''</span>) });
<span class="variable">req</span>.<span class="variable">on</span>(<span class="string">'response'</span>, <span class="keyword">function</span>(<span class="variable">res</span>){
<span class="variable">res</span>.<span class="variable">body</span> = <span class="string">''</span>;
<span class="variable">res</span>.<span class="variable">setEncoding</span>(<span class="string">'utf8'</span>);
<span class="variable">res</span>.<span class="variable">on</span>(<span class="string">'data'</span>, <span class="keyword">function</span>(<span class="variable">chunk</span>){ <span class="variable">res</span>.<span class="variable">body</span> += <span class="variable">chunk</span>; });
<span class="variable">res</span>.<span class="variable">on</span>(<span class="string">'end'</span>, <span class="keyword">function</span>(){
<span class="keyword">if</span> (<span class="variable">res</span>.<span class="variable">body</span>.<span class="variable">indexOf</span>(<span class="string">'ERROR'</span>) === <span class="number integer">0</span>) {
<span class="keyword">var</span> <span class="variable">err</span> = <span class="variable">res</span>.<span class="variable">body</span>.<span class="variable">replace</span>(<span class="regexp">/^ERROR: */</span>, <span class="string">''</span>);
<span class="variable">err</span> = <span class="variable">cmd</span> + <span class="string">'('</span> + <span class="variable">args</span>.<span class="variable">join</span>(<span class="string">', '</span>) + <span class="string">'): '</span> + <span class="variable">err</span>;
<span class="variable">fn</span>(<span class="keyword">new</span> <span class="class">Error</span>(<span class="variable">err</span>), <span class="variable">res</span>.<span class="variable">body</span>, <span class="variable">res</span>);
} <span class="keyword">else</span> {
<span class="keyword">if</span> (<span class="variable">res</span>.<span class="variable">body</span>.<span class="variable">indexOf</span>(<span class="string">'OK'</span>) === <span class="number integer">0</span>) {
<span class="variable">res</span>.<span class="variable">body</span> = <span class="variable">res</span>.<span class="variable">body</span>.<span class="variable">replace</span>(<span class="regexp">/^OK,?/</span>, <span class="string">''</span>);
}
<span class="variable">fn</span>(<span class="keyword">null</span>, <span class="variable">res</span>.<span class="variable">body</span>, <span class="variable">res</span>);
}
});
});
<span class="variable">req</span>.<span class="variable">end</span>();
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Construct a <code>cmd</code> path with the given <code>args</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>param</strong>: <em>Array</em> args</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Client</span>.<span class="variable">prototype</span>.<span class="variable">commandPath</span> = <span class="keyword">function</span>(<span class="variable">cmd</span>, <span class="variable">args</span>){
<span class="keyword">var</span> <span class="variable">obj</span> = { <span class="variable">cmd</span>: <span class="variable">cmd</span> };
<span class="comment">// Arguments by nth</span>
<span class="keyword">if</span> (<span class="variable">args</span>) {
<span class="variable">args</span>.<span class="variable">forEach</span>(<span class="keyword">function</span>(<span class="variable">arg</span>, <span class="variable">i</span>){
<span class="variable">obj</span>[<span class="variable">i</span>+<span class="number integer">1</span>] = <span class="variable">arg</span>;
});
}
<span class="comment">// Ignore session id for getNewBrowserSession</span>
<span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">sid</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">cmd</span> !== <span class="string">'getNewBrowserSession'</span>) {
<span class="variable">obj</span>.<span class="variable">sessionId</span> = <span class="this">this</span>.<span class="variable">sid</span>;
}
<span class="keyword">return</span> <span class="string">'/selenium-server/driver/?'</span> + <span class="variable">qs</span>.<span class="variable">stringify</span>(<span class="variable">obj</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Indicate that commands should be queued.</p>
<h2>Example</h2>
<pre><code> browser
.chain
.session()
.open('/')
.type('q', 'Hello World')
.clickAndWait('btnG')
.assertTitle('Hello World - Google')
.testComplete()
.end(function(err){ ... });</code></pre>
<ul><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Client</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'chain'</span>, <span class="keyword">function</span>(){
<span class="this">this</span>.<span class="variable">queue</span> = [];
<span class="keyword">return</span> <span class="this">this</span>;
});</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Callback <code>fn(err)</code> when the queue is complete, or
when an exception has occurred.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Client</span>.<span class="variable">prototype</span>.<span class="variable">end</span> = <span class="keyword">function</span>(<span class="variable">fn</span>){
<span class="this">this</span>.<span class="variable">_done</span> = <span class="variable">fn</span>;
<span class="this">this</span>.<span class="variable">queue</span>.<span class="variable">shift</span>()();
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Enqueue the given <code>cmd</code> and array of <code>args</code> for execution.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> cmd</p></li><li><p><strong>param</strong>: <em>Array</em> args</p></li><li><p><strong>return</strong>: <em>Client</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Client</span>.<span class="variable">prototype</span>.<span class="variable">enqueue</span> = <span class="keyword">function</span>(<span class="variable">cmd</span>, <span class="variable">args</span>, <span class="variable">fn</span>){
<span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>
, <span class="variable">len</span> = <span class="variable">args</span>.<span class="variable">length</span>;
<span class="comment">// Indirect callback support</span>
<span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">args</span>[<span class="variable">len</span> - <span class="number integer">1</span>] === <span class="string">'function'</span>) {
<span class="variable">fn</span> = <span class="variable">args</span>.<span class="variable">pop</span>();
}
<span class="this">this</span>.<span class="variable">queue</span>.<span class="variable">push</span>(<span class="keyword">function</span>(){
<span class="variable">self</span>.<span class="variable">command</span>(<span class="variable">cmd</span>, <span class="variable">args</span>, <span class="keyword">function</span>(<span class="variable">err</span>, <span class="variable">body</span>, <span class="variable">res</span>){
<span class="comment">// Callback support</span>
<span class="keyword">if</span> (!<span class="variable">err</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">fn</span>) {
<span class="keyword">try</span> {
<span class="variable">fn</span>(<span class="variable">body</span>, <span class="variable">res</span>);
} <span class="keyword">catch</span> (<span class="variable">err</span>) {
<span class="keyword">return</span> <span class="variable">self</span>.<span class="variable">_done</span>(<span class="variable">err</span>, <span class="variable">body</span>, <span class="variable">res</span>);
}
}
<span class="keyword">if</span> (<span class="variable">err</span>) {
<span class="variable">self</span>.<span class="variable">_done</span>(<span class="variable">err</span>, <span class="variable">body</span>, <span class="variable">res</span>);
} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">self</span>.<span class="variable">queue</span>.<span class="variable">length</span>) {
<span class="variable">self</span>.<span class="variable">queue</span>.<span class="variable">shift</span>()();
} <span class="keyword">else</span> {
<span class="variable">self</span>.<span class="variable">_done</span>(<span class="keyword">null</span>, <span class="variable">body</span>, <span class="variable">res</span>);
}
});
});
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Arbitrary callback <code>fn(this)</code> when using the chaining api.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Client</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Client</span>.<span class="variable">prototype</span>.<span class="variable">and</span> = <span class="keyword">function</span>(<span class="variable">fn</span>){
<span class="variable">fn</span>.<span class="variable">call</span>(<span class="this">this</span>, <span class="this">this</span>);
<span class="keyword">return</span> <span class="this">this</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Shortcut for <code>new soda.Client()</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Object</em> options</p></li><li><p><strong>return</strong>: <em>Client</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">createClient</span> = <span class="keyword">function</span>(<span class="variable">options</span>){
<span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Client</span>(<span class="variable">options</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Command names.</p>
<ul><li><p><strong>type</strong>: <em>Array</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">commands</span> = [
<span class="comment">// rc</span>
<span class="string">'getNewBrowserSession'</span>
, <span class="string">'setContext'</span>
, <span class="string">'testComplete'</span>
<span class="comment">// selenium actions</span>
, <span class="string">'addLocationStrategy'</span>
, <span class="string">'addScript'</span>
, <span class="string">'addSelection'</span>
, <span class="string">'allowNativeXpath'</span>
, <span class="string">'altKeyDown'</span>
, <span class="string">'altKeyUp'</span>
, <span class="string">'answerOnNextPrompt'</span>
, <span class="string">'assignId'</span>
, <span class="string">'break'</span>
, <span class="string">'captureEntirePageScreenshot'</span>
, <span class="string">'check'</span>
, <span class="string">'chooseCancelOnNextConfirmation'</span>
, <span class="string">'chooseOkOnNextConfirmation'</span>
, <span class="string">'click'</span>
, <span class="string">'clickAndWait'</span>
, <span class="string">'clickAt'</span>
, <span class="string">'clickAtAndWait'</span>
, <span class="string">'close'</span>
, <span class="string">'contextMenu'</span>
, <span class="string">'contextMenuAt'</span>
, <span class="string">'controlKeyDown'</span>
, <span class="string">'controlKeyUp'</span>
, <span class="string">'createCookie'</span>
, <span class="string">'deleteAllVisibleCookies'</span>
, <span class="string">'deleteCookie'</span>
, <span class="string">'deselectPopUp'</span>
, <span class="string">'doubleClick'</span>
, <span class="string">'doubleClickAt'</span>
, <span class="string">'dragAndDrop'</span>
, <span class="string">'dragAndDropToObject'</span>
, <span class="string">'echo'</span>
, <span class="string">'fireEvent'</span>
, <span class="string">'focus'</span>
, <span class="string">'goBack'</span>
, <span class="string">'highlight'</span>
, <span class="string">'ignoreAttributesWithoutValue'</span>
, <span class="string">'keyDown'</span>
, <span class="string">'keyPress'</span>
, <span class="string">'keyUp'</span>
, <span class="string">'metaKeyDown'</span>
, <span class="string">'metaKeyUp'</span>
, <span class="string">'mouseDown'</span>
, <span class="string">'mouseDownAt'</span>
, <span class="string">'mouseDownRight'</span>
, <span class="string">'mouseDownRightAt'</span>
, <span class="string">'mouseMove'</span>
, <span class="string">'mouseMoveAt'</span>
, <span class="string">'mouseOut'</span>
, <span class="string">'mouseOver'</span>
, <span class="string">'mouseUp'</span>
, <span class="string">'mouseUpAt'</span>
, <span class="string">'mouseUpRight'</span>
, <span class="string">'mouseUpRightAt'</span>
, <span class="string">'open'</span>
, <span class="string">'openWindow'</span>
, <span class="string">'refresh'</span>
, <span class="string">'removeAllSelections'</span>
, <span class="string">'removeScript'</span>
, <span class="string">'removeSelection'</span>
, <span class="string">'rollup'</span>
, <span class="string">'runScript'</span>
, <span class="string">'select'</span>
, <span class="string">'selectFrame'</span>
, <span class="string">'selectPopUp'</span>
, <span class="string">'selectWindow'</span>
, <span class="string">'setBrowserLogLevel'</span>
, <span class="string">'setCursorPosition'</span>
, <span class="string">'setMouseSpeed'</span>
, <span class="string">'setSpeed'</span>
, <span class="string">'setTimeout'</span>
, <span class="string">'shiftKeyDown'</span>
, <span class="string">'shiftKeyUp'</span>
, <span class="string">'submit'</span>
, <span class="string">'type'</span>
, <span class="string">'typeKeys'</span>
, <span class="string">'uncheck'</span>
, <span class="string">'useXpathLibrary'</span>
, <span class="string">'waitForCondition'</span>
, <span class="string">'waitForFrameToLoad'</span>
, <span class="string">'waitForPageToLoad'</span>
, <span class="string">'waitForPopUp'</span>
, <span class="string">'windowFocus'</span>
, <span class="string">'windowMaximize'</span>
];</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Accessor names.</p>
<ul><li><p><strong>type</strong>: <em>Array</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">accessors</span> = [
<span class="string">'ErrorOnNext'</span>
, <span class="string">'FailureOnNext'</span>
, <span class="string">'Alert'</span>
, <span class="string">'AllButtons'</span>
, <span class="string">'AllFields'</span>
, <span class="string">'AllLinks'</span>
, <span class="string">'AllWindowIds'</span>
, <span class="string">'AllWindowNames'</span>
, <span class="string">'AllWindowTitles'</span>
, <span class="string">'Attribute'</span>
, <span class="string">'AttributeFromAllWindows'</span>
, <span class="string">'BodyText'</span>
, <span class="string">'Confirmation'</span>
, <span class="string">'Cookie'</span>
, <span class="string">'CookieByName'</span>
, <span class="string">'CursorPosition'</span>
, <span class="string">'ElementHeight'</span>
, <span class="string">'ElementIndex'</span>
, <span class="string">'ElementPositionLeft'</span>
, <span class="string">'ElementPositionTop'</span>
, <span class="string">'ElementWidth'</span>
, <span class="string">'Eval'</span>
, <span class="string">'Expression'</span>
, <span class="string">'HtmlSource'</span>
, <span class="string">'Location'</span>
, <span class="string">'LogMessages'</span>
, <span class="string">'MouseSpeed'</span>
, <span class="string">'Prompt'</span>
, <span class="string">'SelectedId'</span>
, <span class="string">'SelectedIds'</span>
, <span class="string">'SelectedIndex'</span>
, <span class="string">'SelectedIndexes'</span>
, <span class="string">'SelectedLabel'</span>
, <span class="string">'SelectedLabels'</span>
, <span class="string">'SelectedValue'</span>
, <span class="string">'SelectedValues'</span>
, <span class="string">'SelectOptions'</span>
, <span class="string">'Speed'</span>
, <span class="string">'Table'</span>
, <span class="string">'Text'</span>
, <span class="string">'Title'</span>
, <span class="string">'Value'</span>
, <span class="string">'WhetherThisFrameMatchFrameExpression'</span>
, <span class="string">'WhetherThisWindowMatchWindowExpression'</span>
, <span class="string">'XpathCount'</span>
, <span class="string">'AlertPresent'</span>
, <span class="string">'Checked'</span>
, <span class="string">'ConfirmationPresent'</span>
, <span class="string">'CookiePresent'</span>
, <span class="string">'Editable'</span>
, <span class="string">'ElementPresent'</span>
, <span class="string">'ElementNotPresent'</span>
, <span class="string">'Ordered'</span>
, <span class="string">'PromptPresent'</span>
, <span class="string">'SomethingSelected'</span>
, <span class="string">'TextPresent'</span>
, <span class="string">'Visible'</span>
];</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Generate commands via accessors.</p>
<p>All accessors get prefixed with:</p>
<ul><li>get</li><li>assert</li><li>assertNot</li><li>verify</li><li>verifyNot</li><li>waitFor</li><li>waitForNot</li></ul>
<p>For example providing us with:</p>
<ul><li>getTitle</li><li>assertTitle</li><li>verifyTitle</li><li><p>...</p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">accessors</span>.<span class="variable">map</span>(<span class="keyword">function</span>(<span class="variable">cmd</span>){
<span class="variable">exports</span>.<span class="variable">commands</span>.<span class="variable">push</span>(
<span class="string">'get'</span> + <span class="variable">cmd</span>
, <span class="string">'assert'</span> + <span class="variable">cmd</span>
, <span class="string">'assertNot'</span> + <span class="variable">cmd</span>
, <span class="string">'verify'</span> + <span class="variable">cmd</span>
, <span class="string">'verifyNot'</span> + <span class="variable">cmd</span>
, <span class="string">'waitFor'</span> + <span class="variable">cmd</span>
, <span class="string">'waitForNot'</span> + <span class="variable">cmd</span>);
});</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Generate command methods.
</p>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">commands</span>.<span class="variable">map</span>(<span class="keyword">function</span>(<span class="variable">cmd</span>){
<span class="class">Client</span>.<span class="variable">prototype</span>[<span class="variable">cmd</span>] = <span class="keyword">function</span>(){
<span class="comment">// Queue the command invocation</span>
<span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">queue</span>) {
<span class="keyword">var</span> <span class="variable">args</span> = <span class="class">Array</span>.<span class="variable">prototype</span>.<span class="variable">slice</span>.<span class="variable">call</span>(<span class="variable">arguments</span>);
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">enqueue</span>(<span class="variable">cmd</span>, <span class="variable">args</span>);
<span class="comment">// Direct call</span>
} <span class="keyword">else</span> {
<span class="keyword">var</span> <span class="variable">len</span> = <span class="variable">arguments</span>.<span class="variable">length</span>
, <span class="variable">fn</span> = <span class="variable">arguments</span>[<span class="variable">len</span> - <span class="number integer">1</span>]
, <span class="variable">args</span> = <span class="class">Array</span>.<span class="variable">prototype</span>.<span class="variable">slice</span>.<span class="variable">call</span>(<span class="variable">arguments</span>, <span class="number integer">0</span>, <span class="variable">len</span> - <span class="number integer">1</span>);
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">command</span>(<span class="variable">cmd</span>, <span class="variable">args</span>, <span class="variable">fn</span>);
}
};
});</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/soda/index.js"><a href="#">index</a></h2></td><td>lib/soda/index.js</td></tr><tr class="code">
<td class="docs">
<p>Export all of ./client.
</p>
</td>
<td class="code">
<pre><code><span class="variable">exports</span> = <span class="variable">module</span>.<span class="variable">exports</span> = <span class="variable">require</span>(<span class="string">'./client'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Export sauce client.
</p>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="class">SauceClient</span> = <span class="variable">require</span>(<span class="string">'./sauce'</span>);
<span class="variable">exports</span>.<span class="variable">createSauceClient</span> = <span class="variable">require</span>(<span class="string">'./sauce'</span>).<span class="variable">createClient</span>;</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Library version.</p>
<ul><li><p><strong>type</strong>: <em>String</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">version</span> = <span class="string">'0.2.0'</span>;
</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/soda/sauce.js"><a href="#">sauce</a></h2></td><td>lib/soda/sauce.js</td></tr><tr class="code">
<td class="docs">
<p>Module dependencies.
</p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Client</span> = <span class="variable">require</span>(<span class="string">'./client'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Initialize a <code>SauceClient</code> with the given <code>options</code>. A suite of environment
variables are also supported in place of the options described below.</p>
<h2>Options</h2>
<ul><li><code>username</code> Saucelabs username</li><li><code>access-key</code> Account access key</li><li><code>os</code> Operating system ex "Linux"</li><li><code>browser</code> Browser name, ex "firefox"</li><li><code>browser-version</code> Browser version, ex "3.0.", "7."</li><li><code>max-duration</code> Maximum test duration in seconds, ex 300 (5 minutes)</li></ul>
<h2>Environment Variables</h2>
<ul><li><code>SAUCE_HOST</code> Defaulting to "saucelabs.com"</li><li><code>SAUCE_PORT</code> Defaulting to 4444</li><li><code>SAUCE_OS</code></li><li><code>SAUCE_BROWSER</code></li><li><code>SAUCE_USERNAME</code></li><li><code>SAUCE_ACCESS_KEY</code></li><li><code>SAUCE_BROWSER_VERSION</code></li></ul>
<h2></h2>
<ul><li><p><strong>params</strong>: <em>Object</em> options</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">SauceClient</span> = <span class="variable">exports</span> = <span class="variable">module</span>.<span class="variable">exports</span> = <span class="keyword">function</span> <span class="class">SauceClient</span>(<span class="variable">options</span>) {
<span class="variable">options</span> = <span class="variable">options</span> || {};
<span class="this">this</span>.<span class="variable">host</span> = <span class="variable">process</span>.<span class="variable">env</span>.<span class="class">SAUCE_HOST</span> || <span class="string">'saucelabs.com'</span>;
<span class="this">this</span>.<span class="variable">port</span> = <span class="variable">process</span>.<span class="variable">env</span>.<span class="class">SAUCE_PORT</span> || <span class="number integer">4444</span>;
<span class="comment">// Check sauce env variables, and provide defaults</span>
<span class="variable">options</span>.<span class="variable">os</span> = <span class="variable">options</span>.<span class="variable">os</span> || <span class="variable">process</span>.<span class="variable">env</span>.<span class="class">SAUCE_OS</span> || <span class="string">'Linux'</span>;
<span class="variable">options</span>.<span class="variable">url</span> = <span class="variable">options</span>.<span class="variable">url</span> || <span class="variable">process</span>.<span class="variable">env</span>.<span class="class">SAUCE_BROWSER_URL</span>;
<span class="variable">options</span>.<span class="variable">browser</span> = <span class="variable">options</span>.<span class="variable">browser</span> || <span class="variable">process</span>.<span class="variable">env</span>.<span class="class">SAUCE_BROWSER</span> || <span class="string">'firefox'</span>;
<span class="variable">options</span>.<span class="variable">username</span> = <span class="variable">options</span>.<span class="variable">username</span> || <span class="variable">process</span>.<span class="variable">env</span>.<span class="class">SAUCE_USERNAME</span>;
<span class="variable">options</span>[<span class="string">'access-key'</span>] = <span class="variable">options</span>[<span class="string">'access-key'</span>] || <span class="variable">process</span>.<span class="variable">env</span>.<span class="class">SAUCE_ACCESS_KEY</span>;
<span class="comment">// Allow users to specify an empty browser-version</span>
<span class="variable">options</span>[<span class="string">'browser-version'</span>] = <span class="variable">options</span>[<span class="string">'browser-version'</span>] == <span class="variable">undefined</span>
? (<span class="variable">process</span>.<span class="variable">env</span>.<span class="class">SAUCE_BROWSER_VERSION</span> || <span class="string">''</span>)
: (<span class="variable">options</span>[<span class="string">'browser-version'</span>] || <span class="string">''</span>);
<span class="this">this</span>.<span class="variable">url</span> = <span class="variable">options</span>.<span class="variable">url</span>;
<span class="this">this</span>.<span class="variable">username</span> = <span class="variable">options</span>.<span class="variable">username</span>;
<span class="this">this</span>.<span class="variable">accessKey</span> = <span class="variable">options</span>[<span class="string">'access-key'</span>];
<span class="this">this</span>.<span class="variable">options</span> = <span class="variable">options</span>;
<span class="this">this</span>.<span class="variable">browser</span> = <span class="class">JSON</span>.<span class="variable">stringify</span>(<span class="variable">options</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Interit from <code>Client</code>.
</p>
</td>
<td class="code">
<pre><code><span class="class">SauceClient</span>.<span class="variable">prototype</span>.<span class="variable">__proto__</span> = <span class="class">Client</span>.<span class="variable">prototype</span>;</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return saucelabs video flv url.</p>
<h2></h2>
<ul><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SauceClient</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'videoUrl'</span>, <span class="keyword">function</span>(){
<span class="keyword">return</span> <span class="variable">exports</span>.<span class="variable">url</span>(<span class="this">this</span>.<span class="variable">username</span>, <span class="this">this</span>.<span class="variable">sid</span>, <span class="string">'video.flv'</span>);
});</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return saucelabs log file url.</p>
<h2></h2>
<ul><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SauceClient</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'logUrl'</span>, <span class="keyword">function</span>(){
<span class="keyword">return</span> <span class="variable">exports</span>.<span class="variable">url</span>(<span class="this">this</span>.<span class="variable">username</span>, <span class="this">this</span>.<span class="variable">sid</span>, <span class="string">'selenium-server.log'</span>);
});</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return saucelabs video embed script.</p>
<h2></h2>
<ul><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">SauceClient</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'video'</span>, <span class="keyword">function</span>(){
<span class="keyword">return</span> <span class="variable">exports</span>.<span class="variable">video</span>(<span class="this">this</span>.<span class="variable">username</span>, <span class="this">this</span>.<span class="variable">accessKey</span>, <span class="this">this</span>.<span class="variable">sid</span>);
});</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Shortcut for <code>new soda.SauceClient()</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Object</em> options</p></li><li><p><strong>return</strong>: <em>Client</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">createClient</span> = <span class="keyword">function</span>(<span class="variable">options</span>){
<span class="keyword">return</span> <span class="keyword">new</span> <span class="class">SauceClient</span>(<span class="variable">options</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return saucelabs url to <code>jobId</code>'s <code>filename</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> username</p></li><li><p><strong>param</strong>: <em>String</em> jobId</p></li><li><p><strong>param</strong>: <em>String</em> filename</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">url</span> = <span class="keyword">function</span>(<span class="variable">username</span>, <span class="variable">jobId</span>, <span class="variable">filename</span>){
<span class="keyword">return</span> <span class="string">'https://saucelabs.com/rest/'</span>
+ <span class="variable">username</span> + <span class="string">'/jobs/'</span>
+ <span class="variable">jobId</span> + <span class="string">'/results/'</span>
+ <span class="variable">filename</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return saucelabs video embed script. </p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> username</p></li><li><p><strong>param</strong>: <em>String</em> accessKey</p></li><li><p><strong>param</strong>: <em>String</em> jobId</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">video</span> = <span class="keyword">function</span>(<span class="variable">username</span>, <span class="variable">accessKey</span>, <span class="variable">jobId</span>){
<span class="keyword">return</span> <span class="string">'&lt;script src=&quot;http://saucelabs.com/video-embed/'</span>
+ <span class="variable">jobId</span> + <span class="string">'.js?username='</span>
+ <span class="variable">username</span> + <span class="string">'&amp;access_key='</span>
+ <span class="variable">accessKey</span> + <span class="string">'&quot;/&gt;'</span>;
};</code></pre>
</td>
</tr> </body>
</html></tbody></table>