jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: Setting user defined variable in beanshell not working
Date Fri, 04 Sep 2015 12:28:32 GMT
On 4 September 2015 at 12:37, Peter Moser <irki21@gmail.com> wrote:
> Hi,
>
> thanks for your answer.
> The variables in the Testplan are static.

Not really, they can be set from properties and some functions.

> So I have no opportunity at
> runtime to load JDBC Configurations from a config file?

That's not the case, you just have to make sure the variable is
defined early enough.

> Best regards
>
> 2015-09-04 13:25 GMT+02:00 sebb <sebbaz@gmail.com>:
>
>> That's because the JDBC Config element processes variables at
>> configuration time, which occurs before the samplers are run.
>>
>> Try defining the variable on the Test Plan and you should see the
>> difference
>>
>> On 4 September 2015 at 11:31, Peter Moser <irki21@gmail.com> wrote:
>> > Hi,
>> >
>> > I want to set user defined variables in a beanshell.
>> > I use this code: vars.put("user", "one"),
>> >
>> > When I later want to use the variable in a sampler with ${user}, it is
>> not
>> > replaced.
>> > With a debug sampler I can see the variable is set.
>> >
>> >
>> > What am I doing wrong? Here is the xml of the project:
>> >
>> > <?xml version="1.0" encoding="UTF-8"?>
>> > <jmeterTestPlan version="1.2" properties="2.8" jmeter="2.13 r1665067">
>> >   <hashTree>
>> >     <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test
>> > Plan" enabled="true">
>> >       <stringProp name="TestPlan.comments"></stringProp>
>> >       <boolProp name="TestPlan.functional_mode">false</boolProp>
>> >       <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
>> >       <elementProp name="TestPlan.user_defined_variables"
>> > elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments"
>> > testname="User Defined Variables" enabled="true">
>> >         <collectionProp name="Arguments.arguments"/>
>> >       </elementProp>
>> >       <stringProp name="TestPlan.user_define_classpath"></stringProp>
>> >     </TestPlan>
>> >     <hashTree>
>> >       <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup"
>> > testname="Thread Group" enabled="true">
>> >         <stringProp
>> name="ThreadGroup.on_sample_error">continue</stringProp>
>> >         <elementProp name="ThreadGroup.main_controller"
>> > elementType="LoopController" guiclass="LoopControlPanel"
>> > testclass="LoopController" testname="Loop Controller" enabled="true">
>> >           <boolProp
>> name="LoopController.continue_forever">false</boolProp>
>> >           <stringProp name="LoopController.loops">1</stringProp>
>> >         </elementProp>
>> >         <stringProp name="ThreadGroup.num_threads">1</stringProp>
>> >         <stringProp name="ThreadGroup.ramp_time">1</stringProp>
>> >         <longProp name="ThreadGroup.start_time">1441359197000</longProp>
>> >         <longProp name="ThreadGroup.end_time">1441359197000</longProp>
>> >         <boolProp name="ThreadGroup.scheduler">false</boolProp>
>> >         <stringProp name="ThreadGroup.duration"></stringProp>
>> >         <stringProp name="ThreadGroup.delay"></stringProp>
>> >       </ThreadGroup>
>> >       <hashTree>
>> >         <BeanShellSampler guiclass="BeanShellSamplerGui"
>> > testclass="BeanShellSampler" testname="BeanShell Sampler" enabled="true">
>> >           <stringProp
>> > name="BeanShellSampler.query">vars.put(&quot;user&quot;,
>> &quot;one&quot;);
>> > vars.put(&quot;host&quot;, &quot;localhost&quot;);</stringProp>
>> >           <stringProp name="BeanShellSampler.filename"></stringProp>
>> >           <stringProp name="BeanShellSampler.parameters"></stringProp>
>> >           <boolProp
>> > name="BeanShellSampler.resetInterpreter">false</boolProp>
>> >         </BeanShellSampler>
>> >         <hashTree/>
>> >         <JDBCDataSource guiclass="TestBeanGUI" testclass="JDBCDataSource"
>> > testname="JDBC Connection Configuration" enabled="true">
>> >           <stringProp name="dataSource">dbcon</stringProp>
>> >           <stringProp name="poolMax">10</stringProp>
>> >           <stringProp name="timeout">10000</stringProp>
>> >           <stringProp name="trimInterval">60000</stringProp>
>> >           <boolProp name="autocommit">true</boolProp>
>> >           <stringProp name="transactionIsolation">DEFAULT</stringProp>
>> >           <boolProp name="keepAlive">true</boolProp>
>> >           <stringProp name="connectionAge">5000</stringProp>
>> >           <stringProp name="checkQuery">Select 1</stringProp>
>> >           <stringProp
>> > name="dbUrl">jdbc:postgresql://localhost:5432/box</stringProp>
>> >           <stringProp name="driver">org.postgresql.Driver</stringProp>
>> >           <stringProp name="username">${user}</stringProp>
>> >           <stringProp name="password">pwd</stringProp>
>> >         </JDBCDataSource>
>> >         <hashTree/>
>> >         <JDBCSampler guiclass="TestBeanGUI" testclass="JDBCSampler"
>> > testname="JDBC Request" enabled="true">
>> >           <stringProp name="dataSource">dbcon</stringProp>
>> >           <stringProp name="queryType">Select Statement</stringProp>
>> >           <stringProp name="query">SELECT 1</stringProp>
>> >           <stringProp name="queryArguments"></stringProp>
>> >           <stringProp name="queryArgumentsTypes"></stringProp>
>> >           <stringProp name="variableNames"></stringProp>
>> >           <stringProp name="resultVariable"></stringProp>
>> >           <stringProp name="queryTimeout"></stringProp>
>> >           <stringProp name="resultSetHandler">Store as
>> String</stringProp>
>> >         </JDBCSampler>
>> >         <hashTree/>
>> >         <ResultCollector guiclass="ViewResultsFullVisualizer"
>> > testclass="ResultCollector" testname="View Results Tree" enabled="true">
>> >           <boolProp name="ResultCollector.error_logging">false</boolProp>
>> >           <objProp>
>> >             <name>saveConfig</name>
>> >             <value class="SampleSaveConfiguration">
>> >               <time>true</time>
>> >               <latency>true</latency>
>> >               <timestamp>true</timestamp>
>> >               <success>true</success>
>> >               <label>true</label>
>> >               <code>true</code>
>> >               <message>true</message>
>> >               <threadName>true</threadName>
>> >               <dataType>true</dataType>
>> >               <encoding>false</encoding>
>> >               <assertions>true</assertions>
>> >               <subresults>true</subresults>
>> >               <responseData>false</responseData>
>> >               <samplerData>false</samplerData>
>> >               <xml>false</xml>
>> >               <fieldNames>false</fieldNames>
>> >               <responseHeaders>false</responseHeaders>
>> >               <requestHeaders>false</requestHeaders>
>> >               <responseDataOnError>false</responseDataOnError>
>> >
>> >
>> <saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
>> >               <assertionsResultsToSave>0</assertionsResultsToSave>
>> >               <bytes>true</bytes>
>> >               <threadCounts>true</threadCounts>
>> >             </value>
>> >           </objProp>
>> >           <stringProp name="filename"></stringProp>
>> >         </ResultCollector>
>> >         <hashTree/>
>> >       </hashTree>
>> >     </hashTree>
>> >   </hashTree>
>> > </jmeterTestPlan>
>> >
>> >
>> > Error that I got:
>> > FATAL: role "${user}" does not exist
>> >
>> > Best regards, Peter
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
>> For additional commands, e-mail: user-help@jmeter.apache.org
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Mime
View raw message