<?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>Cloud Testing Blog &#187; Javascript</title>
	<atom:link href="http://www.cloudtesting.com/blog/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cloudtesting.com/blog</link>
	<description>Automated Functional, Cross Browser and Load Testing for Websites</description>
	<lastBuildDate>Tue, 23 Aug 2011 18:41:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Processing Javascript with Selenium</title>
		<link>http://www.cloudtesting.com/blog/2009/12/03/processing-javascript-with-selenium/</link>
		<comments>http://www.cloudtesting.com/blog/2009/12/03/processing-javascript-with-selenium/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 10:34:49 +0000</pubDate>
		<dc:creator>Matt Rees - Cloud Testing</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[Selenium RC]]></category>

		<guid isPermaLink="false">http://www.cloudtesting.com/blog/?p=1042</guid>
		<description><![CDATA[To allow you to create dynamic testing scripts, i.e. ones where the information entered onto forms, such as dates change over time, Cloud Testing has implemented the processing of JavaScript. Stored Variables The commands store, storeValue and storeText can be used to store a variable value for later. Store javascript{var d=new Date(); d.toString()} dateToday Store [...]]]></description>
			<content:encoded><![CDATA[<p>To allow you to create dynamic testing scripts, i.e. ones where the information entered onto forms, such as dates change over time, Cloud Testing has implemented the processing of JavaScript.</p>
<h2>Stored Variables</h2>
<p>The commands <em>store</em>, <em>storeValue</em> and <em>storeText</em> can be used to store a variable value for later.</p>
<table style="height: 154px;" border="1" width="637">
<colgroup>
<col width="18%"></col>
<col width="36%"></col>
<col width="45%"></col>
</colgroup>
<tbody>
<tr>
<td>Store</td>
<td><span id="showArg1_2">javascript{var d=new Date(); d.toString()} </span></td>
<td><span id="showArg2_2">dateToday </span></td>
</tr>
<tr>
<td>Store</td>
<td><span id="showArg1_3">javascript{var d=new Date(); d.setDate(d.getDate() + 1); d.toDateString();}</span></td>
<td><span id="showArg2_3">dateTomorrow </span></td>
</tr>
<tr>
<td>Store</td>
<td><span id="showArg1_4">javascript{var d=new Date(); d.setDate(d.getDate() + 40); d.toDateString();} </span></td>
<td>date40days</td>
</tr>
<tr>
<td>Store</td>
<td>Plain text string</td>
<td>variableName</td>
</tr>
</tbody>
</table>
<p>These variables are stored internally in a map called &#8220;storedVars&#8221;, with values keyed by the variable name, which can be accessed as follows:</p>
<pre style="padding-left: 30px;">storedVars['date40days']</pre>
<h2>JavaScript</h2>
<p>All parameters or arguments for Selenium commands can be constructed using both simple 	variable substitution as well as full JavaScript. They both have access to the variables stored above, but in different ways:</p>
<h3>Full JavaScript &#8211; javascript{&#8230;}</h3>
<p>Javascript evaluation provides the full power of JavaScript when constructing a parameter or argument for a Selenium command. 	To use this mechanism, the <em>entire</em> parameter value must be prefixed by &#8216;javascript{&#8216; with a trailing &#8216;}&#8217;. The text inside the braces is evaluated as a JavaScript expression, and can access previously stored variables using the <em>storedVars</em> map detailed above.</p>
<p>Note that variable substitution cannot be combined with JavaScript evaluation.</p>
<table style="height: 154px;" border="1" width="638">
<colgroup>
<col width="18%"></col>
<col width="36%"></col>
<col width="45%"></col>
</colgroup>
<tbody>
<tr>
<td>Echo</td>
<td><span id="showArg1_16">javascript{storedVars['dateTomorrow']} </span></td>
<td></td>
</tr>
<tr>
<td>Type</td>
<td>textField</td>
<td><span id="showArg1_16">javascript{&#8216;Tomorrow=&#8217; + storedVars['dateTomorrow']} </span></td>
</tr>
<tr>
<td>Echo</td>
<td><span id="showArg1_16">javascript{&#8216;Tomorrow=&#8217; + storedVars['dateTomorrow']} </span></td>
<td></td>
</tr>
<tr>
<td>Type</td>
<td>fullName</td>
<td>javascript{storedVars['fullName'].toUpperCase()}</td>
</tr>
</tbody>
</table>
<h3>Simple variable substitution &#8211; ${&#8230;}</h3>
<p>Variable substitution provides a simple way to use a previously stored variable in a command parameter. The variable to substitute is indicated by ${variableName}. Multiple variables can be substituted, and intermixed with static text.</p>
<table style="height: 154px;" border="1" width="634">
<colgroup>
<col width="18%"></col>
<col width="36%"></col>
<col width="45%"></col>
</colgroup>
<tbody>
<tr>
<td>Echo</td>
<td>${dateTomorrow}</td>
<td></td>
</tr>
<tr>
<td>Type</td>
<td>textField</td>
<td><span id="showArg2_13">Today: ${dateToday} Tomorrow: ${dateTomorrow} </span></td>
</tr>
<tr>
<td>Echo</td>
<td>${variableName}</td>
<td></td>
</tr>
<tr>
<td>Type</td>
<td>fullName</td>
<td>$(title} ${firstName} ${lastName}</td>
</tr>
</tbody>
</table>
<h2>Example in Cloud Testing</h2>
<p>The following example from Cloud Testing shows what can be done.</p>
<p><img class="alignnone size-full wp-image-1082" style="border: 1px solid black;" title="JavaScript - settings" src="http://www.cloudtesting.com/blog/wp-content/uploads/2009/12/JavaScript-settings.png" alt="JavaScript - settings" width="693" height="518" /></p>
<p>The example script is available to view in the &#8216;Live Demo&#8217; account is available via the <a href="http://www.cloudtesting.com/live_demo.php">Online demo</a> page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cloudtesting.com/blog/2009/12/03/processing-javascript-with-selenium/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing Pop-up Alerts and Confirmations with Selenium and Cloud Testing</title>
		<link>http://www.cloudtesting.com/blog/2009/07/17/processing-pop-up-alerts-and-confirmations-with-selenium-and-cloud-testing/</link>
		<comments>http://www.cloudtesting.com/blog/2009/07/17/processing-pop-up-alerts-and-confirmations-with-selenium-and-cloud-testing/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 14:11:18 +0000</pubDate>
		<dc:creator>Phil Smith - Cloud Testing</dc:creator>
				<category><![CDATA[Cloud Testing]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[Javascript Alerts]]></category>

		<guid isPermaLink="false">http://blog.cloudtesting.com/?p=462</guid>
		<description><![CDATA[This article covers the basics of how Selenium handles pop-ups, as well as how to test them using the Cloud Testing service. Future articles will cover the advanced details of handling Alerts and Confirmations. What are Alerts and Confirmations? The following very basic page will use Javascript to display either an Alert (which only has [...]]]></description>
			<content:encoded><![CDATA[<p>This article covers the basics of how Selenium handles pop-ups, as well as how to test them using the Cloud Testing service. Future articles will cover the advanced details of handling Alerts and Confirmations.</p>
<h2>What are Alerts and Confirmations?</h2>
<p>The following very basic page will use Javascript to display either an Alert (which only has an OK button), and a Confirmation (which has an OK and Cancel buttons), depending on which button is clicked on the page.</p>
<pre><span style="color:#0000ff;">&lt;html&gt;</span>
<span style="color:#0000ff;">&lt;head&gt;</span>
<span style="color:#0000ff;">&lt;title&gt;Cloud Testing Pop-up example&lt;/title&gt;</span>
<span style="color:#0000ff;">&lt;/head&gt;</span>
<span style="color:#0000ff;">&lt;body&gt;</span>
<span style="color:#0000ff;">
&lt;h1&gt;Cloud Testing Pop-up example&lt;/h1&gt;</span>
<span style="color:#0000ff;">&lt;form action=""&gt;</span>
<span style="color:#0000ff;">&lt;input type="submit" value="Display Alert"
    onClick="alert('Cloud Testing Alert')"&gt;</span>
<span style="color:#0000ff;">&lt;input type="submit" value="Display Confirmation"
    onClick="confirm('Cloud Testing Confirmation?')"&gt;</span>
<span style="color:#0000ff;">&lt;/form&gt;</span>
<span style="color:#0000ff;">&lt;/html&gt;
<span style="color:#000000;"> </span></span></pre>
<p style="text-align:center;"><em><span style="color:#000000;">Example Code 1</span></em></p>
<p><span style="color:#000000;">When displayed in a browser, the following web page is displayed:</span></p>
<p><span style="color:#0000ff;"><span style="color:#000000;"> </span></span></p>
<p style="text-align:center;"><span style="color:#000000;"><img class="aligncenter size-medium wp-image-465" title="Pop-up example page" src="http://cloudtesting.files.wordpress.com/2009/07/popup1.gif?w=300" alt="popup1" width="300" height="190" /></span></p>
<h3><span style="color:#000000;">Alert<br />
</span></h3>
<p><span style="color:#000000;">Clicking on the &#8216;Display Alert&#8217; button will result in the following Alert box being displayed:</span></p>
<p style="text-align:center;"><span style="color:#000000;"><img class="aligncenter size-full wp-image-466" title="Example of a Javascript Alert" src="http://cloudtesting.files.wordpress.com/2009/07/popup2.gif" alt="popup2" width="221" height="169" /></span></p>
<p><span style="color:#000000;">A single OK button is displayed, along with a warning triangle icon (with slightly different implementations in various browsers).<br />
</span></p>
<h3>Confirmation</h3>
<p><span style="color:#000000;">Clicking on the &#8216;Display Confirmation&#8217; button will result in the following Confirmation box being displayed:</span></p>
<p style="text-align:center;"><span style="color:#000000;"><img class="aligncenter size-full wp-image-467" title="Example of a Javascript Confirmation" src="http://cloudtesting.files.wordpress.com/2009/07/popup3.gif" alt="popup3" width="272" height="169" /></span><span style="color:#000000;">Two buttons are displayed &#8211; OK and Cancel, along with an information/question icon (with slightly different implementations in various browsers).</span></p>
<p><span style="color:#000000;"> </span></p>
<p><span style="color:#000000;"> </span></p>
<h2><span style="color:#000000;">Processing with Selenium</span></h2>
<p>The following commands are available within Selenium for processing Alerts:</p>
<ul>
<li> getAlert()</li>
<li>assertAlert()</li>
<li>assertAlertNotPresent()</li>
<li>assertAlertPresent()</li>
<li>storeAlert()</li>
<li>storeAlertPresent()</li>
<li>verifyAlert()</li>
<li>verifyAlertNotPresent()</li>
<li>verifyAlertPresent()</li>
<li>waitForAlert()</li>
<li>waitForAlertNotPresent()</li>
<li>waitForAlertPresent()</li>
</ul>
<p>The &#8230;AlertPresent() and &#8230;AlertNotPresent() functions check for the existence or not of an alert &#8211; regardless of it&#8217;s content.</p>
<p>The &#8230;Alert() functions allow the caller to specify a pattern which should be matched.</p>
<p>The getAlert() method also exists in Selenium RC, and returns the text from the previous Alert displayed.</p>
<p>Similar functions are also available for Confirmations.</p>
<p><strong>IMPORTANT NOTE: </strong></p>
<p>Because of the way that Selenium works, any alerts or confirmations that are displayed before the onLoad() method in the page cannot be caught. An example of this</p>
<pre><span style="color:#0000ff;">&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Cloud Testing Alert example&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

Displayed before the alert.

&lt;script&gt;
alert('Cloud Testing Alert');
&lt;/script&gt;

&lt;br /&gt;Displayed after someone clicks OK on the alert.

&lt;/body&gt;
&lt;/html&gt;</span>
<span style="color:#000000;">
</span></pre>
<p style="text-align:center;"><em><span style="color:#000000;">Example Code 2</span></em></p>
<p><span style="color:#000000;">When viewed in a browser &#8211; Google Chrome in this case, the Javascript that displays the alert is processed while the page is loading, and the page will not be fully displayed until the OK button is clicked and the dialog box dismissed.</span><span style="color:#000000;"> </span></p>
<p style="text-align:center;"><span style="color:#000000;"> </span><span style="color:#000000;"><img class="aligncenter size-medium wp-image-473" title="Pop-up example page 2 - alert displayed before page completely loaded" src="http://cloudtesting.files.wordpress.com/2009/07/popup4.gif?w=300" alt="popup4" width="300" height="256" /></span></p>
<p>The page can now be fully rendered, with the second line of text now displayed:</p>
<p style="text-align:center;"><span style="color:#000000;"><br />
<img class="aligncenter size-medium wp-image-475" title="Pop-up example page 2 - after alert dismissed" src="http://cloudtesting.files.wordpress.com/2009/07/popup51.gif?w=300" alt="popup5" width="300" height="255" /><br />
</span></p>
<h2>Processing with Cloud Testing</h2>
<p>To illustrate some of the features of the Cloud Testing service, I have created and uploaded the following script &#8211; click to see the full size version:</p>
<p style="text-align:center;"><a href="http://cloudtesting.files.wordpress.com/2009/07/popup6.gif" target="_blank"><img class="aligncenter size-medium wp-image-480" title="Cloud Testing Script for Pop-ups - click for full size image" src="http://cloudtesting.files.wordpress.com/2009/07/popup6.gif?w=300" alt="" width="300" height="108" /></a></p>
<p style="text-align:left;">When this script is run against the page in Example Code 1 above, we get the following results:</p>
<p style="text-align:center;"><a href="http://cloudtesting.files.wordpress.com/2009/07/popup7.gif" target="_blank"><img class="aligncenter size-medium wp-image-483" title="Results for pop-up test - click for full size image" src="http://cloudtesting.files.wordpress.com/2009/07/popup7.gif?w=300" alt="Results for pop-up test - click for full size image" width="300" height="238" /></a><strong> </strong></p>
<h3 style="text-align:left;">Explanation of the Test:</h3>
<p style="text-align:left;"><strong>Step 1:</strong></p>
<p style="text-align:left;">This opens the sample page &#8211; successfully.</p>
<p style="text-align:left;"><strong>Step 2:</strong></p>
<p style="text-align:left;">Click on the &#8216;Display Alert&#8217; button &#8211; again successfully.</p>
<p style="text-align:left;"><strong>Step 3:</strong></p>
<p style="text-align:left;">Producing a screenshot at this time will not show the Alert dialog box &#8211; it is intercepted by Selenium and never displayed.</p>
<p style="text-align:left;"><strong>Step 4:</strong></p>
<p style="text-align:left;">The &#8216;<em>Get Alert</em>&#8216; function returns the text of the last Alert &#8211; in this case &#8216;Cloud Testing Alert&#8217;, as displayed.</p>
<p style="text-align:left;"><strong>Step 5:</strong></p>
<p style="text-align:left;">The &#8216;<em>Verify Alert</em>&#8216; function fails at this point, as there are no outstanding Alerts &#8211; the previous call in effect clicked OK.</p>
<p style="text-align:left;"><strong>Step 6:</strong></p>
<p style="text-align:left;">Here we click the &#8216;Display Alert&#8217; button again, for the next part of the test.</p>
<p style="text-align:left;"><strong>Step 7:</strong></p>
<p style="text-align:left;">This time the &#8216;<em>Verify Alert</em>&#8216; function succeeds.</p>
<p style="text-align:left;"><strong>Step 8:</strong></p>
<p style="text-align:left;">Here we click the &#8216;Display Alert&#8217; button again, for the next part of the test.</p>
<p style="text-align:left;"><strong>Step 9:</strong></p>
<p style="text-align:left;">The &#8216;Verify Alert&#8217; function fails, as the expression we have passed (&#8216;Cloud Testing Confirmation&#8217;) is not what is present in the alert.</p>
<p style="text-align:left;">
<h2 style="text-align:left;">Further Information</h2>
<p style="text-align:left;">For further details of the Cloud Testing service visit the website at <a href="http://www.cloudtesting.com">www.cloudtesting.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cloudtesting.com/blog/2009/07/17/processing-pop-up-alerts-and-confirmations-with-selenium-and-cloud-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

