<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Use of variables, arrays and complex types in Generic Fixture</title>
	<atom:link href="http://anubhava.wordpress.com/2008/04/11/use-of-variables-arrays-and-complex-types-in-generic-fixture/feed/" rel="self" type="application/rss+xml" />
	<link>http://anubhava.wordpress.com/2008/04/11/use-of-variables-arrays-and-complex-types-in-generic-fixture/</link>
	<description>Generic Fixture, just a better FitNesse Fixture</description>
	<lastBuildDate>Wed, 28 Oct 2009 16:34:13 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: anubhava</title>
		<link>http://anubhava.wordpress.com/2008/04/11/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-108</link>
		<dc:creator>anubhava</dc:creator>
		<pubDate>Tue, 29 Sep 2009 21:33:24 +0000</pubDate>
		<guid isPermaLink="false">http://anubhava.wordpress.com/2008/01/28/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-108</guid>
		<description>Hi Michael,

Thanks for the nice words. 

Now regarding if, for, while, etc: I was initially using fit.decorator&#039;s loop fixture for looping support but since fit.decorator didn&#039;t have support of variables I had to modify it locally.

As a much better support of these constructs (if, for, while, etc) I have actually integrated bean shell interpreter via GenericFixture and DSLAdapter. I have yet to publish a Blog post on examples and how-to&#039;. 
But in summary:
1. Get bsh.jar and put it in FitNesse&#039;s classpath, using !path directive.
2. Then use a DSL like this anywhere in your scripts:
&lt;code&gt;!&#124; DSL Adapter &#124;
&#124; check if array &#124; % &#124; has &#124; % &#124; GenericFixture.bsh &#124; boolean has=false; if (java.util.Arrays.binarySearch({1}, &quot;{2}&quot;) &gt; 0) has=true; return has; &#124;
&#124; check if &#124; % &#124; is between &#124; % &#124; and &#124; % &#124; GenericFixture.bsh &#124; return {1} &gt; {2} &amp;&amp; {1} &lt;= {3}; &#124;&lt;/code&gt;
3. And finally call this DSL script like:
&lt;code&gt;&#124; check if &#124; someVar &#124; is between &#124; 4 &#124; and &#124; 7 &#124; &#124; true &#124;
&#124; check if array &#124; arr &#124; has &#124; indeed &#124; &#124; true &#124;&lt;/code&gt;

I know it wont&#039;s be very clear from this comment so please pardon me till I create a proper Blog post with full working examples and detailed instructions.

Cheers,
Anubhava

&lt;em&gt;PS; However as a matter of practice I don&#039;t recommend writing a complex test script with all kind ifs, whiles, dos etc. It makes it harder to maintain and less readable. I would rather create a helper class and do complex looping, branching, calculations inside that and then call helper class methods via Generic Fixture.
&lt;/em&gt;</description>
		<content:encoded><![CDATA[<p>Hi Michael,</p>
<p>Thanks for the nice words. </p>
<p>Now regarding if, for, while, etc: I was initially using fit.decorator&#8217;s loop fixture for looping support but since fit.decorator didn&#8217;t have support of variables I had to modify it locally.</p>
<p>As a much better support of these constructs (if, for, while, etc) I have actually integrated bean shell interpreter via GenericFixture and DSLAdapter. I have yet to publish a Blog post on examples and how-to&#8217;.<br />
But in summary:<br />
1. Get bsh.jar and put it in FitNesse&#8217;s classpath, using !path directive.<br />
2. Then use a DSL like this anywhere in your scripts:<br />
<code>!| DSL Adapter |<br />
| check if array | % | has | % | GenericFixture.bsh | boolean has=false; if (java.util.Arrays.binarySearch({1}, "{2}") &gt; 0) has=true; return has; |<br />
| check if | % | is between | % | and | % | GenericFixture.bsh | return {1} &gt; {2} &amp;&amp; {1} &lt;= {3}; |</code><br />
3. And finally call this DSL script like:<br />
<code>| check if | someVar | is between | 4 | and | 7 | | true |<br />
| check if array | arr | has | indeed | | true |</code></p>
<p>I know it wont&#39;s be very clear from this comment so please pardon me till I create a proper Blog post with full working examples and detailed instructions.</p>
<p>Cheers,<br />
Anubhava</p>
<p><em>PS; However as a matter of practice I don&#8217;t recommend writing a complex test script with all kind ifs, whiles, dos etc. It makes it harder to maintain and less readable. I would rather create a helper class and do complex looping, branching, calculations inside that and then call helper class methods via Generic Fixture.<br />
</em></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://anubhava.wordpress.com/2008/04/11/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-103</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Mon, 28 Sep 2009 21:28:21 +0000</pubDate>
		<guid isPermaLink="false">http://anubhava.wordpress.com/2008/01/28/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-103</guid>
		<description>Anubhava,

First of all I wanted to say thanks for putting this together.  It makes jumping into Fitnesse testing much easier.  I was curious if you had considered or implemented anything in the GenericFixture with regards to flow control (if, for, while, etc).  One of the powers of Fitnesse is the ability to define a table of values that you can have Fitnesse churn through via a fixture.  Just curious.

Thanks,
Michael</description>
		<content:encoded><![CDATA[<p>Anubhava,</p>
<p>First of all I wanted to say thanks for putting this together.  It makes jumping into Fitnesse testing much easier.  I was curious if you had considered or implemented anything in the GenericFixture with regards to flow control (if, for, while, etc).  One of the powers of Fitnesse is the ability to define a table of values that you can have Fitnesse churn through via a fixture.  Just curious.</p>
<p>Thanks,<br />
Michael</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anubhava</title>
		<link>http://anubhava.wordpress.com/2008/04/11/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-99</link>
		<dc:creator>anubhava</dc:creator>
		<pubDate>Tue, 15 Sep 2009 18:06:24 +0000</pubDate>
		<guid isPermaLink="false">http://anubhava.wordpress.com/2008/01/28/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-99</guid>
		<description>Dear Aristotelis,

There are couple of syntax errors in your DSL. As you are aware now that comma characters inside parameters need to be escaped out in DSL. Additionally you have used assignment(=) instead of comparison(==) in the 2nd condition of your Javascript.

Let me give you the syntax corrected definition:

&lt;code&gt;!&#124; DSL Adapter &#124;
&#124; wait for element with id &#124; % &#124; to not be visible &#124; waitForCondition &#124; window.document.evaluate( &quot;count(//node()[@id=&#039;{1}&#039;])&quot;\, document\, null\, XPathResult.NUMBER_TYPE\, null ).numberValue == 0 !-&#124;&#124;-! window.document.getElementById(&#039;{1}&#039;).scrollWidth == 1, 120000 &#124;&lt;/code&gt;

Please try it and see if it resolves your error. 

If not I would suggest to include this code in a small JUnit test case and call your Selenium server from there since you are getting this exception from Selenium API. Once working in JUnit code you can always translate it back to Generic Fixture&#039;s DSL.

Cheers,
Anubhava</description>
		<content:encoded><![CDATA[<p>Dear Aristotelis,</p>
<p>There are couple of syntax errors in your DSL. As you are aware now that comma characters inside parameters need to be escaped out in DSL. Additionally you have used assignment(=) instead of comparison(==) in the 2nd condition of your Javascript.</p>
<p>Let me give you the syntax corrected definition:</p>
<p><code>!| DSL Adapter |<br />
| wait for element with id | % | to not be visible | waitForCondition | window.document.evaluate( "count(//node()[@id='{1}'])"\, document\, null\, XPathResult.NUMBER_TYPE\, null ).numberValue == 0 !-||-! window.document.getElementById('{1}').scrollWidth == 1, 120000 |</code></p>
<p>Please try it and see if it resolves your error. </p>
<p>If not I would suggest to include this code in a small JUnit test case and call your Selenium server from there since you are getting this exception from Selenium API. Once working in JUnit code you can always translate it back to Generic Fixture&#8217;s DSL.</p>
<p>Cheers,<br />
Anubhava</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aristotelis</title>
		<link>http://anubhava.wordpress.com/2008/04/11/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-98</link>
		<dc:creator>Aristotelis</dc:creator>
		<pubDate>Tue, 15 Sep 2009 09:07:28 +0000</pubDate>
		<guid isPermaLink="false">http://anubhava.wordpress.com/2008/01/28/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-98</guid>
		<description>Hi Anubhava,

Thank you for your constant support.
Regarding the last issue I had mentioned, the escaping of the comma seems to work ok, but now we get another error that we can not resolve and I&#039;d like to ask for your help.

The  dsl is:
!&#124; DSL Adapter &#124;
&#124; wait for element with id &#124; % &#124; to not be visible &#124; waitForCondition &#124; window.document.evaluate( &quot;count(//node()[@id=&#039;{1}&#039;])&quot;, document, null, XPathResult.NUMBER_TYPE, null ).numberValue == 0 !-&#124;&#124;-! window.document.getElementById(’{1}’).scrollWidth =1, 120000 &#124;

And the error returned is the following:

com.thoughtworks.selenium.SeleniumException: Node cannot be used in a document other than the one in which it was created

We also tried using instead of window.document.
this:
selenium.browserbot.getCurrentWindow().document.
and this:
document.importNode(window.document\,true).

but none works.

any help would be greatly appreciated.

Thanks in advance.</description>
		<content:encoded><![CDATA[<p>Hi Anubhava,</p>
<p>Thank you for your constant support.<br />
Regarding the last issue I had mentioned, the escaping of the comma seems to work ok, but now we get another error that we can not resolve and I&#8217;d like to ask for your help.</p>
<p>The  dsl is:<br />
!| DSL Adapter |<br />
| wait for element with id | % | to not be visible | waitForCondition | window.document.evaluate( &#8220;count(//node()[@id='{1}'])&#8221;, document, null, XPathResult.NUMBER_TYPE, null ).numberValue == 0 !-||-! window.document.getElementById(’{1}’).scrollWidth =1, 120000 |</p>
<p>And the error returned is the following:</p>
<p>com.thoughtworks.selenium.SeleniumException: Node cannot be used in a document other than the one in which it was created</p>
<p>We also tried using instead of window.document.<br />
this:<br />
selenium.browserbot.getCurrentWindow().document.<br />
and this:<br />
document.importNode(window.document\,true).</p>
<p>but none works.</p>
<p>any help would be greatly appreciated.</p>
<p>Thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sérgio Correia</title>
		<link>http://anubhava.wordpress.com/2008/04/11/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-97</link>
		<dc:creator>Sérgio Correia</dc:creator>
		<pubDate>Tue, 08 Sep 2009 21:06:09 +0000</pubDate>
		<guid isPermaLink="false">http://anubhava.wordpress.com/2008/01/28/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-97</guid>
		<description>Hi Anubhava,
We&#039;ve tried your new genericfixture.jar and everything worked perfectly.

Thanks a lot for your help.

Cheers,
Sérgio</description>
		<content:encoded><![CDATA[<p>Hi Anubhava,<br />
We&#8217;ve tried your new genericfixture.jar and everything worked perfectly.</p>
<p>Thanks a lot for your help.</p>
<p>Cheers,<br />
Sérgio</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anubhava</title>
		<link>http://anubhava.wordpress.com/2008/04/11/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-96</link>
		<dc:creator>anubhava</dc:creator>
		<pubDate>Tue, 08 Sep 2009 18:16:41 +0000</pubDate>
		<guid isPermaLink="false">http://anubhava.wordpress.com/2008/01/28/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-96</guid>
		<description>Dear Sérgio,

Thanks for writing back to me.

Actually the problem was not the getParameters returning a list it was in fact the dilemma of resolving the variables either at &quot;DSL to Java translation&quot; stage or at execution stage. As you notice that a variable can store any object not just String or String compatible objects therefore I have decided to leave variable resolution at the late stage i.e. execution stage.

New genericfixture.jar has been uploaded to the sourceforge repository. Please download the latest jar file for your test. It should fix the problem for you.

cheers,
Anubhava</description>
		<content:encoded><![CDATA[<p>Dear Sérgio,</p>
<p>Thanks for writing back to me.</p>
<p>Actually the problem was not the getParameters returning a list it was in fact the dilemma of resolving the variables either at &#8220;DSL to Java translation&#8221; stage or at execution stage. As you notice that a variable can store any object not just String or String compatible objects therefore I have decided to leave variable resolution at the late stage i.e. execution stage.</p>
<p>New genericfixture.jar has been uploaded to the sourceforge repository. Please download the latest jar file for your test. It should fix the problem for you.</p>
<p>cheers,<br />
Anubhava</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sérgio Correia</title>
		<link>http://anubhava.wordpress.com/2008/04/11/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-95</link>
		<dc:creator>Sérgio Correia</dc:creator>
		<pubDate>Mon, 07 Sep 2009 10:51:03 +0000</pubDate>
		<guid isPermaLink="false">http://anubhava.wordpress.com/2008/01/28/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-95</guid>
		<description>Hi Anubhava,
With your fix we&#039;ve managed to solve the previous error, however a new one as come up.

The getParameters method in the DSL Adapter class has a return type of List.
This disallows the use of non String objects in the DSL such as the example I&#039;ve mentioned in a previous reply.

What happens now is that the ship object that is returned from:

&#124; create ship with imoNumber &#124; % &#124; and name &#124; % &#124; setUp &#124; shipFieldSetMapper , array:{1}\,{2}\,”\,” , array:ImoNumber\,Name\,NameEffectDate\,MmsiNumber &#124;

when invoking the following example is being converted to a String and causing a an error inside the method

!&#124; Generic Fixture &#124; foodb= &#124;
&#124; delete ship &#124; ship= &#124;

Is this the expected behavior?

Thanks a lot for your help,
Sérgio</description>
		<content:encoded><![CDATA[<p>Hi Anubhava,<br />
With your fix we&#8217;ve managed to solve the previous error, however a new one as come up.</p>
<p>The getParameters method in the DSL Adapter class has a return type of List.<br />
This disallows the use of non String objects in the DSL such as the example I&#8217;ve mentioned in a previous reply.</p>
<p>What happens now is that the ship object that is returned from:</p>
<p>| create ship with imoNumber | % | and name | % | setUp | shipFieldSetMapper , array:{1}\,{2}\,”\,” , array:ImoNumber\,Name\,NameEffectDate\,MmsiNumber |</p>
<p>when invoking the following example is being converted to a String and causing a an error inside the method</p>
<p>!| Generic Fixture | foodb= |<br />
| delete ship | ship= |</p>
<p>Is this the expected behavior?</p>
<p>Thanks a lot for your help,<br />
Sérgio</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anubhava</title>
		<link>http://anubhava.wordpress.com/2008/04/11/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-94</link>
		<dc:creator>anubhava</dc:creator>
		<pubDate>Fri, 04 Sep 2009 19:12:06 +0000</pubDate>
		<guid isPermaLink="false">http://anubhava.wordpress.com/2008/01/28/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-94</guid>
		<description>Hi Sérgio,

I found the issue and fixed it. Thanks a lot for bringing it up. New genericfixture.jar has been uploaded to the sourceforge repository. Please download the latest jar file for your test. It should fix the problem for you because I was able to reproduce the problem and then test it again after the fix.

Let me know how it goes.

Cheers,
Anubhava</description>
		<content:encoded><![CDATA[<p>Hi Sérgio,</p>
<p>I found the issue and fixed it. Thanks a lot for bringing it up. New genericfixture.jar has been uploaded to the sourceforge repository. Please download the latest jar file for your test. It should fix the problem for you because I was able to reproduce the problem and then test it again after the fix.</p>
<p>Let me know how it goes.</p>
<p>Cheers,<br />
Anubhava</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sérgio Correia</title>
		<link>http://anubhava.wordpress.com/2008/04/11/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-93</link>
		<dc:creator>Sérgio Correia</dc:creator>
		<pubDate>Fri, 04 Sep 2009 14:28:17 +0000</pubDate>
		<guid isPermaLink="false">http://anubhava.wordpress.com/2008/01/28/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-93</guid>
		<description>Hi Anubhava,
I&#039;ve tried the debug trick you&#039;ve mentioned as the variables do have the correct type.

After taking a look at your code I&#039;ve noticed that the error was in following lines:

              Object v = GenericFixture.fetchVariable( str );
              if ( v != null &amp;&amp; !v.getClass().isArray() )
                str = (String) v;

Hence my question regarding the expected types for the variables.

Are we doing something wrong?

Thanks in advance,
Sérgio</description>
		<content:encoded><![CDATA[<p>Hi Anubhava,<br />
I&#8217;ve tried the debug trick you&#8217;ve mentioned as the variables do have the correct type.</p>
<p>After taking a look at your code I&#8217;ve noticed that the error was in following lines:</p>
<p>              Object v = GenericFixture.fetchVariable( str );<br />
              if ( v != null &amp;&amp; !v.getClass().isArray() )<br />
                str = (String) v;</p>
<p>Hence my question regarding the expected types for the variables.</p>
<p>Are we doing something wrong?</p>
<p>Thanks in advance,<br />
Sérgio</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anubhava</title>
		<link>http://anubhava.wordpress.com/2008/04/11/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-92</link>
		<dc:creator>anubhava</dc:creator>
		<pubDate>Thu, 03 Sep 2009 19:26:12 +0000</pubDate>
		<guid isPermaLink="false">http://anubhava.wordpress.com/2008/01/28/use-of-variables-arrays-and-complex-types-in-generic-fixture/#comment-92</guid>
		<description>Dear Sérgio,

I&#039;m glad that you were able to resolve the previous issue.

No DSLAdapter doesn&#039;t assume a variable to be String or Array or of any other type. Your script is like this:

!&#124; Generic Fixture &#124; foodb= &#124;
&#124; delete ship &#124; ship= &#124;

Which is basically calling a method defined by DSL &quot;delete ship&quot; on the object stored by a variable foodb= and you are supplying a variable ship= to your DSL. 

Are your variables foodb= and ship= storing the values of the correct type? 

To debug further can you check it by creating a variable foodClass= by calling getClass() and then getCanonicalName() method on it. something like this:

!&#124; Generic Fixture &#124; foodb= &#124;
&#124; foodClass=getClass &#124;
&#124; foodClass=.getCanonicalName &#124; &#124;
&#124; shipClass=ship=.getClass &#124;
&#124; shipClass=.getCanonicalName &#124; &#124;
&#124; delete ship &#124; ship= &#124;

Make sure above script prints correct object types in both calls of getCanonicalName methods.

Let me know how it goes.

Cheers,
Anubhava</description>
		<content:encoded><![CDATA[<p>Dear Sérgio,</p>
<p>I&#8217;m glad that you were able to resolve the previous issue.</p>
<p>No DSLAdapter doesn&#8217;t assume a variable to be String or Array or of any other type. Your script is like this:</p>
<p>!| Generic Fixture | foodb= |<br />
| delete ship | ship= |</p>
<p>Which is basically calling a method defined by DSL &#8220;delete ship&#8221; on the object stored by a variable foodb= and you are supplying a variable ship= to your DSL. </p>
<p>Are your variables foodb= and ship= storing the values of the correct type? </p>
<p>To debug further can you check it by creating a variable foodClass= by calling getClass() and then getCanonicalName() method on it. something like this:</p>
<p>!| Generic Fixture | foodb= |<br />
| foodClass=getClass |<br />
| foodClass=.getCanonicalName | |<br />
| shipClass=ship=.getClass |<br />
| shipClass=.getCanonicalName | |<br />
| delete ship | ship= |</p>
<p>Make sure above script prints correct object types in both calls of getCanonicalName methods.</p>
<p>Let me know how it goes.</p>
<p>Cheers,<br />
Anubhava</p>
]]></content:encoded>
	</item>
</channel>
</rss>
