Maintaining the variable state in repeat loop

Manish Ranade <[email protected]>
Newsgroups gmane.comp.web.canoo.webtest
Message-ID <CAHm3MGNgPvgVjJ9EG6nJVvfH4eygYAHS_4UrT+c-sONOjm7_9g@mail.gmail.com>
Hi,

I have a test that tests all the links on a given page by clicking on
them. I use clickLink to click. There is one more piece of logic where
I am checking for a link url pattern and if it matches a given pattern
then I dont want to click on that link more than three times. Reason
for doing this is I have more than 500 links that have the same url
except for some different url params, so I dont want to test them all.
Below is my code and the problem I am facing.


==========================================================

<repeat xpath="//a" counterName="link" description="Click on each link
on the HomePage" >
	
	<storeXPath description="Link Url" xpath="$link/@href" property="linkUrl" />
	
	<scriptStep language="groovy">
		def articlePageUrlPattern = /.*ArticlePage\?id=[1-9]+.*/;
		
		try {
			articlePageCount;
		} catch(e) {
			articlePageCount = 0;
		}
		
		if( !("#{linkUrl}" ==~ articlePageUrlPattern) ) {
			step.setWebtestProperty('clickLink', 'true');
		} else {
			step.setWebtestProperty('clickLink', 'false');
			
			articlePageCount++;
			
			if(articlePageCount > 3) {
				step.setWebtestProperty('clickLink', 'false');
			} else {
				step.setWebtestProperty('clickLink', 'true');
			}
		}
			
	</scriptStep>

	<ifStep test="#{clickLink}">
		<clickLink xpath="$link[@href]" description="#{linkUrl}"/>
		&testForErrorPage;
	</ifStep>
	
	
</repeat>

==========================================================

The problem I am facing:

It always goes in a catch block and sets articlePageCount to zero and
then test ends up testing all the links with that pattern. How do I
solve this problem? It seems link in every iteration of <repeat>,
Groovy code block behaves like it doesnt know what happened in the
previous iternation. I have also tried setting articlePageCount
outside of <repeat> inside of a separate <ScriptStep> Groovy block.
That doesnt work.

Any thoughts? Something I am doing wrong?


-- 
Regards,
Manish Ranade
Phone: 408-596-6546
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.