<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>page-object-model &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/page-object-model/</link>
	<description>Feed of posts on WordPress.com tagged "page-object-model"</description>
	<pubDate>Wed, 22 May 2013 13:33:34 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Using WebDriver to automatically check for JavaScript errors on every page]]></title>
<link>http://watirmelon.com/2012/12/19/using-webdriver-to-automatically-check-for-javascript-errors-on-every-page/</link>
<pubDate>Wed, 19 Dec 2012 11:51:10 +0000</pubDate>
<dc:creator>Alister Scott</dc:creator>
<guid>http://watirmelon.com/2012/12/19/using-webdriver-to-automatically-check-for-javascript-errors-on-every-page/</guid>
<description><![CDATA[One of the benefits of using a page-object model is that you can perform certain actions on every pa]]></description>
<content:encoded><![CDATA[<p>One of the benefits of using a page-object model is that you can perform certain actions on every page in your application that you visit, such as checking for accessibility.</p>
<p>One such check is automatically checking for JavaScript errors on page load. There&#8217;s a couple of approaches out there, <a href="http://mguillem.wordpress.com/2011/10/11/webdriver-capture-js-errors-while-running-tests/">one</a> involves copying and pasting a small snippet of JavaScript into each page. Since our application we are working on uses a standard template for every page, we simply add some JavaScript to the common page header that is the first thing to load on the page, and catches any JavaScript errors that occur:</p>
<pre class="brush: jscript; title: ; notranslate" title="">
define([&#34;amdUtils/string/interpolate&#34;], function(interpolate) {
    window.jsErrors = [];

    window.onerror = function (errorMessage, url, lineNumber) {
        var message = interpolate(&#34;Error: [{{0}}], url: [{{1}}], line: [{{2}}]&#34;, [errorMessage, url, lineNumber]);
        window.jsErrors.push(message);
        return false;
    };
});
</pre>
<p>It&#8217;s then a matter of checking the jsErrors each time we visit a page, this is example C# code we use in the base page class for every page.</p>
<pre class="brush: csharp; title: ; notranslate" title="">
var js = driver as IJavaScriptExecutor;
ICollection javascriptErrors = null;
for (var i = 0; i &#60; 20; i++)
{
  javascriptErrors = js.ExecuteScript(&#34;return window.jsErrors&#34;) as ICollection;
  if (javascriptErrors != null) break;
  System.Threading.Thread.Sleep(1000);
}
Assert.IsNotNull(javascriptErrors, &#34;Can't seem to load JavaScript on the page to find JavaScript errors. Check that JavaScript is enabled.&#34;);
var javaScriptErrorsAsString = javascriptErrors.Cast&#60;string&#62;().Aggregate(&#34;&#34;, (current, error) =&#62; current + (error + &#34;, &#34;));
Assert.AreEqual(&#34;&#34;, javaScriptErrorsAsString, &#34;Found JavaScript errors on page load: &#34; + javaScriptErrorsAsString);
</pre>
<p>This code waits until it can read the jsErrors on the page. If it can&#8217;t, it means that JavaScript didn&#8217;t load and this is an error. Once it gets the jsErrors, it checks that there are none.</p>
<p>This code has been very useful for us. It has caught a number of JavaScript errors, and is especially great for finding cross browser JavaScript issues, as we run our acceptance tests in 5 different browsers.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Sample Page Object Model for Watir-WebDriver]]></title>
<link>http://raveendran.wordpress.com/2011/05/31/page-object-model-for-watir-webdriver/</link>
<pubDate>Tue, 31 May 2011 10:37:57 +0000</pubDate>
<dc:creator>raveendran</dc:creator>
<guid>http://raveendran.wordpress.com/2011/05/31/page-object-model-for-watir-webdriver/</guid>
<description><![CDATA[This is the sample code for creating the page objects in separate file. page_object_sample.rb def co]]></description>
<content:encoded><![CDATA[<p>This is the sample code for creating the page objects in separate file.</p>
<p><span style="text-decoration:underline;"><strong>page_object_sample.rb</strong></span></p>
<pre>def config
  #common Settings
  @browser="ie"
end

def google_homepage
  #Web Application URL details
  @url="http://google.com"
  #Google Homepage Page Object Models
  @search_field=$browser.text_field(:name,'q')
  @search_button=$browser.button(:name =&#62; 'btnG')
end

def bing_homepage
  @url = "http://bing.com"
  @search_field=$browser.text_field(:id,'sb_form_q')
  @search_button=$browser.button(:name =&#62; 'go')
end</pre>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p><span style="text-decoration:underline;"><strong>Code.rb</strong></span></p>
<pre>require 'watir-webdriver'
require 'd:\\page_object_sample.rb'

config
  $browser = Watir::Browser.new @browser.to_sym
google_homepage
  $browser.goto @url
  @search_field.set("Raveendran - Watir Webdriver")
  @search_button.click
  puts $browser.title

bing_homepage
  $browser.goto @url
  @search_field.set("Raveendran - Watir Webdriver")
  @search_button.click
  puts $browser.title

  $browser.close

NOTE:

a. We can create the page object model with,
     1. IE Developer tool bar for IE browser
     2. Firebug for Firefox browser.
b.  This is the sample and basic page object model code. 
We can customize/develop depends up on our requirement.

c. If the page object will change in future then No need
 to worry about the actual script. Just updating the page
 object model will fix those kind of issues.</pre>
]]></content:encoded>
</item>

</channel>
</rss>
