<?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>just_add_watir &#124; Advanced recipes for Watir &#187; testlink</title>
	<atom:link href="http://justaddwatir.com/tag/testlink/feed/" rel="self" type="application/rss+xml" />
	<link>http://justaddwatir.com</link>
	<description>Advanced recipes for Watir</description>
	<lastBuildDate>Wed, 21 Oct 2009 02:44:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Q. How do I integrate watir with TestLink?</title>
		<link>http://justaddwatir.com/2008/q-how-do-i-integrate-watir-with-testlink/</link>
		<comments>http://justaddwatir.com/2008/q-how-do-i-integrate-watir-with-testlink/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 11:11:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[firewatir]]></category>
		<category><![CDATA[watir]]></category>
		<category><![CDATA[testlink]]></category>

		<guid isPermaLink="false">http://justaddwatir.com/watir/?p=51</guid>
		<description><![CDATA[A. This requires several hacks and use of the developer API ...

The first step to integrating these products is to download and install
TestLink 1.8.0 BETA2
Once finished, add the TestLink API BETA
Their blog has installation instructions for both.
Regarding the API there are a number of changes you will need to ensure:
1. create api_developer_keys table using the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>A. This requires several hacks and use of the developer API ...</strong><br />
<span id="more-51"></span><br />
The first step to integrating these products is to download and install<br />
<a href="http://testlink.org/wordpress/download/">TestLink 1.8.0 BETA2</a><br />
Once finished, add the <a href="http://testlink.org/wordpress/2007/11/19/testlink-api-beta/">TestLink API BETA</a></p>
<p>Their blog has installation instructions for both.</p>
<p>Regarding the API there are a number of changes you will need to ensure:<br />
1. create <strong>api_developer_keys</strong> table using the <strong>api_sql_changes.sql</strong> included with the API<br />
2. create an api developer key in your new <strong>api_developer_keys</strong> table<br />
3. update the <strong>api.const.inc.php</strong> database constants<br />
4. <code>$ chmod -R 755 api/</code><br />
5. change the paths to relevant libraries in <strong>xmlrpc.php</strong>, mine looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">change xmlrpc<span style="color: #339933;">.</span>php
<span style="color: #009933; font-style: italic;">/**
 * IXR is the class used for the XML-RPC server
 */</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/../third_party/xml-rpc/class-IXR.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;api.const.inc.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// require_once(&quot;APIErrors.php&quot;);</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/../config.inc.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/../lib/functions/common.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/../lib/functions/testproject.class.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/../lib/functions/testcase.class.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/../lib/functions/testsuite.class.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You can be creative as you want with the API. The way I implemented this, was to change the test execution template to allow corresponding test cases to be executed within watir such that the following calls are made:</p>
<p>TestLink -> test_harness.php -> test_harness.rb -> test_suite.rb</p>
<p>I had to first modify the TestLink <strong>gui/templates/execute/execSetResults.tpl</strong> template as per the following (approx line 544):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">   <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <span style="color: #000088;">$tc_exec</span><span style="color: #339933;">.</span>can_be_executed<span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">include</span> <span style="color: #990000;">file</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;execute/inc_exec_controls.tpl&quot;</span>
               args_input_enable_mgmt<span style="color: #339933;">=</span><span style="color: #000088;">$input_enabled_disabled</span>
               args_tcversion_id<span style="color: #339933;">=</span><span style="color: #000088;">$tcversion_id</span>
               args_webeditor<span style="color: #339933;">=</span><span style="color: #000088;">$gui</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">exec_notes_editors</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$tc_id</span><span style="color: #009900;">&#93;</span>
               args_labels<span style="color: #339933;">=</span><span style="color: #000088;">$labels</span><span style="color: #009900;">&#125;</span>
      <span style="color: #339933;">&lt;!--</span>ADDED BY tim<span style="color: #339933;">.</span>koopmans<span style="color: #339933;">@</span>90kts<span style="color: #339933;">.</span>com<span style="color: #339933;">--&gt;</span>
      <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">include</span> <span style="color: #990000;">file</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;execute/inc_exec_watir.tpl&quot;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>I then added a new TestLink template in <strong>gui/templates/execute/inc_exec_watir.tpl</strong> as per the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009900;">&#123;</span><span style="color: #339933;">*</span>
TestLink Open Source Project <span style="color: #339933;">-</span> http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//testlink.sourceforge.net/</span>
<span style="color: #000088;">$Id</span><span style="color: #339933;">:</span> inc_exec_watir<span style="color: #339933;">.</span>tpl<span style="color: #339933;">,</span>v <span style="color:#800080;">0.1</span> <span style="color: #cc66cc;">2008</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">15</span> <span style="color: #208080;">05</span><span style="color: #339933;">:</span><span style="color: #208080;">03</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">53</span> $
Purpose<span style="color: #339933;">:</span> draw execution controls <span style="color: #b1b100;">for</span> watir based test cases
Author <span style="color: #339933;">:</span> tim<span style="color: #339933;">.</span>koopmans<span style="color: #339933;">@</span>90kts<span style="color: #339933;">.</span>com
<span style="color: #339933;">*</span><span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#123;</span>assign <span style="color: #000000; font-weight: bold;">var</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ResultsStatusCode&quot;</span> value<span style="color: #339933;">=</span><span style="color: #000088;">$tlCfg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">results</span><span style="color: #339933;">.</span>status_code<span style="color: #009900;">&#125;</span>
  		<span style="color: #339933;">&lt;</span>table <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;invisible&quot;</span><span style="color: #339933;">&gt;</span>
  		<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
  			<span style="color: #339933;">&lt;</span>th rowspan<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;2&quot;</span> style<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text-align: center;&quot;</span><span style="color: #339933;">&gt;</span>
  				<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #339933;">&gt;</span>Watir Test <span style="color: #b1b100;">Case</span> <span style="color: #009900;">&#123;</span><span style="color: #000088;">$tc_id</span><span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://localhost/~koops/testlink/watir/test_harness.php?name={<span style="color: #006699; font-weight: bold;">$tc_exec</span>.name}&amp;id=<span style="color: #006699; font-weight: bold;">{$gui-&gt;tcasePrefix}</span>{<span style="color: #006699; font-weight: bold;">$tc_exec</span>.tc_external_id}&amp;tcid=<span style="color: #006699; font-weight: bold;">{$tc_id}</span>&quot;</span><span style="color: #339933;">&gt;</span>Execute <span style="color: #339933;">&amp;</span>rarr<span style="color: #339933;">;&lt;/</span>a<span style="color: #339933;">&gt;</span>
  			<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
  			<span style="color: #339933;">&lt;</span>td valign<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;top&quot;</span> style<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;width: 30%;&quot;</span><span style="color: #339933;">&gt;</span>
    			<span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
    		<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
  		<span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span></pre></div></div>

<p>This essentially adds a new link to the test execution screen which will call a test_harness from PHP using a system call. The screen mod looks like this:<br />
<a href='http://justaddwatir.com/watir/wp-content/uploads/2008/10/exectest.png'><img src="http://justaddwatir.com/watir/wp-content/uploads/2008/10/exectest.png" alt="" title="exectest" width="500" height="245" class="alignleft size-full wp-image-52" /></a> The PHP harness which it calls is located in <strong>watir/test_harness.php</strong> and looks like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;tcid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$tcid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;tcid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Executing watir test case id: <span style="color: #006699; font-weight: bold;">$tcid</span>&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">system</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ruby /Users/koops/Sites/testlink/watir/test_harness.rb <span style="color: #006699; font-weight: bold;">$id</span> <span style="color: #006699; font-weight: bold;">$tcid</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The purpose of this is to launch a test_harness client in Ruby passing it the client ID and test case ID required for execution. This client is based on the API examples and it could have been written in PHP, but I felt more comfortable with Ruby. So there is a little double handling here which could be improved... The Ruby harness it calls is located in <strong>watir/test_harness.rb</strong> and looks like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'xmlrpc/client'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> TestlinkAPIClient
  <span style="color:#008000; font-style:italic;"># substitute your server URL Here</span>
  SERVER_URL = <span style="color:#996600;">&quot;http://localhost/~koops/testlink/api/xmlrpc.php&quot;</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>dev_key<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@server</span> = <span style="color:#6666ff; font-weight:bold;">XMLRPC::Client</span>.<span style="color:#9900CC;">new2</span><span style="color:#006600; font-weight:bold;">&#40;</span>SERVER_URL<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@devKey</span> = dev_key
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> reportTCResult<span style="color:#006600; font-weight:bold;">&#40;</span>tcid, tpid, status<span style="color:#006600; font-weight:bold;">&#41;</span>
    args = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;devKey&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>@devKey, <span style="color:#996600;">&quot;tcid&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>tcid, <span style="color:#996600;">&quot;tpid&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>tpid, <span style="color:#996600;">&quot;status&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>status<span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#0066ff; font-weight:bold;">@server</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;tl.reportTCResult&quot;</span>, args<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> getProjectIDByClientID<span style="color:#006600; font-weight:bold;">&#40;</span>clientid<span style="color:#006600; font-weight:bold;">&#41;</span>
    args = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;devKey&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>@devKey<span style="color:#006600; font-weight:bold;">&#125;</span>
    result = <span style="color:#0066ff; font-weight:bold;">@server</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;tl.getProjects&quot;</span>, args<span style="color:#006600; font-weight:bold;">&#41;</span>
    result.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>project<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#0000FF; font-weight:bold;">return</span> projectid = project<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;id&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">if</span> project<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;name&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> =~ <span style="color:#006600; font-weight:bold;">/</span><span style="color:#008000; font-style:italic;">#{clientid}/</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#996600;">'ERROR: Unable to find project by client id: '</span> <span style="color:#006600; font-weight:bold;">+</span> clientid
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> getProjectTestPlanIDByName<span style="color:#006600; font-weight:bold;">&#40;</span>testprojectid, testplanname<span style="color:#006600; font-weight:bold;">&#41;</span>
    args = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;devKey&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>@devKey, <span style="color:#996600;">&quot;testprojectid&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>testprojectid<span style="color:#006600; font-weight:bold;">&#125;</span>
    result = <span style="color:#0066ff; font-weight:bold;">@server</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;tl.getProjectTestPlans&quot;</span>, args<span style="color:#006600; font-weight:bold;">&#41;</span>
    result.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>testplanid, values<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#CC0066; font-weight:bold;">p</span> values
      <span style="color:#0000FF; font-weight:bold;">return</span> testplanid <span style="color:#9966CC; font-weight:bold;">if</span> values<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;name&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> =~ <span style="color:#006600; font-weight:bold;">/</span><span style="color:#008000; font-style:italic;">#{testplanname}/</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#996600;">'ERROR: Unable to find test plan name by test project id '</span> <span style="color:#006600; font-weight:bold;">+</span> testprojectid
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> getProjectTestPlanID<span style="color:#006600; font-weight:bold;">&#40;</span>testprojectid<span style="color:#006600; font-weight:bold;">&#41;</span>
    args = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;devKey&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>@devKey, <span style="color:#996600;">&quot;testprojectid&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>testprojectid<span style="color:#006600; font-weight:bold;">&#125;</span>
    result = <span style="color:#0066ff; font-weight:bold;">@server</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;tl.getProjectTestPlans&quot;</span>, args<span style="color:#006600; font-weight:bold;">&#41;</span>
    result.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>testplanid, values<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#0000FF; font-weight:bold;">return</span> testplanid
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#996600;">'ERROR: Unable to find test plan id '</span> <span style="color:#006600; font-weight:bold;">+</span> testprojectid
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> getTestCaseIDByName<span style="color:#006600; font-weight:bold;">&#40;</span>testcasename<span style="color:#006600; font-weight:bold;">&#41;</span>
    args = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;devKey&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>@devKey, <span style="color:#996600;">&quot;testcasename&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>testcasename<span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#0066ff; font-weight:bold;">@server</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;tl.getTestCaseIDByName&quot;</span>, args<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># param args</span>
watirid  = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#996600;">&quot;ID74278-1&quot;</span>
tcid     = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#006666;">62</span>
clientid = watirid<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#91;</span>\w\d<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+/</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># execute watir test suite</span>
stdout = <span style="color:#006600; font-weight:bold;">%</span>x<span style="color:#006600; font-weight:bold;">&#91;</span>ruby <span style="color:#006600; font-weight:bold;">/</span>Users<span style="color:#006600; font-weight:bold;">/</span>koops<span style="color:#006600; font-weight:bold;">/</span>Sites<span style="color:#006600; font-weight:bold;">/</span>testlink<span style="color:#006600; font-weight:bold;">/</span>watir<span style="color:#006600; font-weight:bold;">/</span>test_suite.<span style="color:#9900CC;">rb</span> <span style="color:#006600; font-weight:bold;">--</span>name test_<span style="color:#008000; font-style:italic;">#{tcid}]</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> stdout
status = <span style="color:#996600;">&quot;f&quot;</span>
status = <span style="color:#996600;">&quot;p&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> stdout =~ <span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">0</span> errors<span style="color:#006600; font-weight:bold;">/</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># substitute your Dev Key Here</span>
client = TestlinkAPIClient.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;f2a979d533cdd9761434bba60a88e4d8&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># find a project id by client id [custom]</span>
projectid = client.<span style="color:#9900CC;">getProjectIDByClientID</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Client #{clientid}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># find the first test plan id for a given project id [native]</span>
tpid = client.<span style="color:#9900CC;">getProjectTestPlanID</span><span style="color:#006600; font-weight:bold;">&#40;</span>projectid<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
result = client.<span style="color:#9900CC;">reportTCResult</span><span style="color:#006600; font-weight:bold;">&#40;</span>tcid.<span style="color:#9900CC;">to_i</span>, tpid, status<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Run ID: &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> result<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;id&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;&lt;br/&gt;&quot;</span></pre></div></div>

<p>This harness essentially calls  a corresponding Test::Unit test suite (by test case ID) and returns the results using the XML-RPC client back into TestLink.<br />
To give you an idea, my example test suite looked like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'test/unit'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'firewatir'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">include</span> FireWatir
<span style="color:#9966CC; font-weight:bold;">class</span> TestSuite <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">Test::Unit::TestCase</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> setup
    <span style="color:#0066ff; font-weight:bold;">@b</span>=Firefox.<span style="color:#9900CC;">new</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> test_62
    <span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">goto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'http://www.google.com'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>So, stitching it all together, TestLink can call watir test cases using the test case ID which is unique to TestLink and passing it to the relevant test runner or harness in Ruby. Ruby then does the execution and feeds the results (pass/fail) using the XML-RPC client API back into TestLink. You end up with test results being tracked in TestLink and presented (in progress) like this:<br />
<a href='http://justaddwatir.com/watir/wp-content/uploads/2008/10/testcaseexecution.png'><img src="http://justaddwatir.com/watir/wp-content/uploads/2008/10/testcaseexecution.png" alt="" title="testcaseexecution" width="500" height="291" class="alignnone size-full wp-image-53" /></a><br />
It's all a bit hacky and would be happy for others to progress with this. Just some ideas to get you started =)</p>
]]></content:encoded>
			<wfw:commentRss>http://justaddwatir.com/2008/q-how-do-i-integrate-watir-with-testlink/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
