<?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/"
	
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>igorbrejc.net &#187; Selenium</title>
	<atom:link href="http://igorbrejc.net/category/development/testing/selenium/feed" rel="self" type="application/rss+xml" />
	<link>http://igorbrejc.net</link>
	<description>Just another developer's weblog</description>
	<lastBuildDate>Sat, 12 Mar 2011 16:57:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Web Testing &amp; Gallio: A Little Helpful Trick</title>
		<link>http://igorbrejc.net/development/continuous-integration/web-testing-gallio-a-little-helpful-trick</link>
		<comments>http://igorbrejc.net/development/continuous-integration/web-testing-gallio-a-little-helpful-trick#comments</comments>
		<pubDate>Mon, 18 Oct 2010 05:59:08 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Gallio and MbUnit]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/?p=1290</guid>
		<description><![CDATA[When doing automatic testing of Web apps using unit testing frameworks, it can be a pain in the butt to pinpoint the proper HTML element. A lot of times tests will fail because you used a wrong locator, but since the browser will automatically close after the test, you don’t have an access to the [...]]]></description>
			<content:encoded><![CDATA[<p>When doing automatic testing of Web apps using unit testing frameworks, it can be a pain in the butt to pinpoint the proper HTML element. A lot of times tests will fail because you used a wrong locator, but since the browser will automatically close after the test, you don’t have an access to the HTML code of the page to look at what’s actually there.</p>

<p>Fortunately Gallio provides a class called <strong>TestContext</strong> which contains the current information about the running test and which you can use to determine if the latest test is successful or not. This can then be used to run your custom handling code during the test teardown:</p>

<p>
<pre class="brush: csharp; title: ; notranslate">
        [TearDown]
        protected virtual void Teardown()
        {
            if (TestContext.CurrentContext.Outcome.Status == TestStatus.Failed)
            {
                using (TestLog.BeginSection(&quot;Failed web page HTML&quot;))
                    TestLog.Write(WebDriver.PageSource);
            }
        }
</pre></p>

<p>In the above snippet, we record the current Web page’s HTML code into Gallio’s log (the <strong>TestLog</strong> class). To avoid spamming the log, we do this for failed tests only. </p>

<p>Gallio provides a powerful framework which I think is very much underused, mostly because the documentation is not very detailed (to say the least).</p>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/continuous-integration/web-testing-gallio-a-little-helpful-trick/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
	</item>
		<item>
		<title>Gallio: Starting And Stopping Selenium Server Automatically During Testing Using AssemblyFixture</title>
		<link>http://igorbrejc.net/development/cruisecontrolnet/gallio-starting-and-stopping-selenium-server-automatically-during-testing-using-assemblyfixture</link>
		<comments>http://igorbrejc.net/development/cruisecontrolnet/gallio-starting-and-stopping-selenium-server-automatically-during-testing-using-assemblyfixture#comments</comments>
		<pubDate>Tue, 16 Jun 2009 07:37:09 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[CruiseControl.NET]]></category>
		<category><![CDATA[Gallio and MbUnit]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/development/continuous-integration/gallio-starting-and-stopping-selenium-server-automatically-during-testing-using-assemblyfixture</guid>
		<description><![CDATA[UPDATE (June 17th): I&#8217;ve updated the code, see the reasons for it at the end of the post. In previous projects I worked on we made sure the Selenium Java server was running by manually starting it on our machines (both developers&#8217; and build ones). This was cumbersome: restarting the build server meant we had [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE (June 17th)</strong>: I&#8217;ve updated the code, see the reasons for it at the end of the post.</p>

<p>In previous projects I worked on we made sure the Selenium Java server was running by manually starting it on our machines (both developers&#8217; and build ones). This was cumbersome: restarting the build server meant we had to log on to the server after the reboot and run the Selenium server again. Of course, a lot of times we forgot to do this, which caused the build to fail.</p>

<p>This got me into thinking: is there a way in Gallio to specify some initialization (and cleanup) actions on the test assembly level? And of course, the answer is yes: using the <strong>AssemblyFixture</strong> attribute. This is what I like about Gallio/MbUnit: most of the time the feature requests I come up with are actually already implemented.</p>

<p>So anyway, you can specify this attribute on a class and then add <strong>FixtureSetUp</strong> and <strong>FixtureTearDown</strong> attributes on its methods. These will be executed on the test assembly-level: setup methods will be executed before any test fixtures have been run and teardown methods will be executed before the test assembly has been unloaded by the test runner.</p>

<p>I then used this nice feature to start the Selenium server and then dispose of it after tests:</p>

<div><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">[AssemblyFixture]
<span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> SeleniumTestingSetup : IDisposable
{
    [FixtureSetUp]
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Setup()
    {
        seleniumServerProcess = <span style="color: #0000ff">new</span> Process();
        seleniumServerProcess.StartInfo.FileName = <span style="color: #006080">"java"</span>;
        seleniumServerProcess.StartInfo.Arguments =
            <span style="color: #006080">"-jar ../../../lib/Selenium/selenium-server/selenium-server.jar -port 6371"</span>;
        seleniumServerProcess.Start();
    }

    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// Performs application-defined tasks associated with freeing, releasing, or</span>
    <span style="color: #008000">/// resetting unmanaged resources.</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Dispose()
    {
        Dispose(<span style="color: #0000ff">true</span>);
        GC.SuppressFinalize(<span style="color: #0000ff">this</span>);
    }

    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// Disposes the object.</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    <span style="color: #008000">/// &lt;param name="disposing"&gt;If &lt;code&gt;false&lt;/code&gt;, cleans up native resources. </span>
    <span style="color: #008000">/// If &lt;code&gt;true&lt;/code&gt; cleans up both managed and native resources&lt;/param&gt;</span>
    <span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">void</span> Dispose(<span style="color: #0000ff">bool</span> disposing)
    {
        <span style="color: #0000ff">if</span> (<span style="color: #0000ff">false</span> == disposed)
        {
            <span style="color: #0000ff">if</span> (disposing)
                DisposeOfSeleniumServer();

            disposed = <span style="color: #0000ff">true</span>;
        }
    }

    <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> DisposeOfSeleniumServer()
    {
        <span style="color: #0000ff">if</span> (seleniumServerProcess != <span style="color: #0000ff">null</span>)
        {
            <span style="color: #0000ff">try</span>
            {
                seleniumServerProcess.Kill();
                <span style="color: #0000ff">bool</span> result = seleniumServerProcess.WaitForExit(10000);
            }
            <span style="color: #0000ff">finally</span> 
            {
                seleniumServerProcess.Dispose();
                seleniumServerProcess = <span style="color: #0000ff">null</span>;
            }
        }
    }

    <span style="color: #0000ff">private</span> <span style="color: #0000ff">bool</span> disposed;
    <span style="color: #0000ff">private</span> Process seleniumServerProcess;
}</pre></div>

<p>Note that the class is <strong>disposable</strong> &#8211; this ensures the Selenium server is stopped even if you run tests in the debugger and then force the debugger to stop before finishing the work. The Dispose method calls DisposeOfSeleniumServer, which does the actual work of killing the process and disposing of the evidence.</p>

<p><strong>NOTE:</strong> This is a second version of the code. I needed to update the old one because I noticed that when running the tests in CruiseControl.NET, the Selenium server java process was not stopped properly. The only way I could stop it is by killing it, which in general isn&#8217;t a good practice. The unfortunate side effect of this &#8220;killing&#8221; is that the CruiseContol.NET service cannot be stopped normally &#8211; it also has to be killed when you need to restart it. I&#8217;ll try to solve this problem in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/cruisecontrolnet/gallio-starting-and-stopping-selenium-server-automatically-during-testing-using-assemblyfixture/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
	</item>
	</channel>
</rss>

