[Http-webtest-general] Re: Passing optional parameters
Brought to you by:
m_ilya,
richardanderson
From: Ilya M. <il...@ma...> - 2003-09-10 08:51:02
|
>>>>> On Tue, 9 Sep 2003 14:59:46 -0400, William McKee <wi...@kn...> said: WM> Hi list, WM> I have been using the following code to set my URL in each of my WM> wtscript files: WM> on_start { WM> URL = http://www.yahoo.com ^^^^^^ Typo? It should $URL. WM> } WM> In each of my tests I use this value as follows: WM> url = "$URL/purchase.cgi" WM> When using more than 2 wtscripts, it would be far easier to set this WM> value just once (following the first virtue of good programming). I WM> looked into the API documentation and found that I can pass in optional WM> parameters when calling the run_wtscript function. Thus I rewrote my WM> master script that calls each of my wtscripts as follows: WM> $webtest->run_wtscript($file,{'URL' => $URL}); WM> Unfortunately when I run my tests, the $URL parameter is not available WM> and I get 500 errors because WebTest cannot find the empty domain name. WM> Is this a bug or user error? User error :) Test parameters are not visible as perl variables in a test. They are different things. But you can do something like $MY::URL = 'http://www.yahoo.com'; $webtest->run_wtscript($file); and in your tests use url = "$MY::URL/purchase.cgi" Note that I have to use fully qualified names as Perl code in wtscript files is run from different scope and package then caller code. You can replace package name MY with any other but it must be a fully qualified name. I'll consider adding a feature which would make passing Perl variables to tests easier. Something like $webtest->run_wtscript($file, { perl_vars =< {URL => $URL}}); -- Ilya Martynov, il...@ip... CTO IPonWEB (UK) Ltd Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net Personal website - http://martynov.org |