Hi,
Look at the documentation, chapter "Parameters and args"
http://jmeter-plugins.org/wiki/WebDriverSampler/Extract from my contribution for the thread discussion forum "Contributing a Web Driver (Browser) based Sampler"
=================================================================================================================
Hi
I found a way to pass parameters containing spaces as a single parameter in Webdrivers Sampler or Javascript Sampler generally.
My parameter called P_TITLE have the value "Welcome page" (with space character)
I replace all space characters with another character, i choose the # character.
So, in the Webdriver Sampler, i want to pass the modified P_TITLE like this
Parameters = ${__javaScript("${P_TITLE}".split(' ').join('#'))}
And in the script
var TITLE_WITH_SHARP = WDS.args[0];
WDS.log.info("TITLE_WITH_SHARP = " + TITLE_WITH_SHARP); ==> Welcome#page
// replace # by space
var TITLE = TITLE_WITH_SHARP.split('#').join(' ');
WDS.log.info("TITLE = " + TITLE) ==> Welcome page
Regards
Vincent D.
=================================================================================================================
Hi,
I find a solution to return information or data from a webdriver sampler outside this current webdriver sampler.
This solution uses a sub sample result to store information and this new sub sample result is add to the current sampler.
Example, who transmits the title of the current page and get the title with Regular Expression Extractor :
== 1 =======================================================================
// 1a. Start capturing the sampler timing
WDS.sampleResult.sampleStart()
// 2. Perform the Sampler task
WDS.browser.get('
http://host:8080/gestdocqualif/')
// 1b. Stop the sampler timing
WDS.sampleResult.sampleEnd()
// 3. Verify the results
var stringToFind = "Page d'accueil application";
if(!WDS.browser.getTitle().match(stringToFind)) {
WDS.sampleResult.setSuccessful(false)
WDS.sampleResult.setResponseMessage("Expected title to be <" + stringToFind + ">")
}
else {
WDS.log.info("In the expected page");
// create a subSampleResult to transmit information from WebDriver easily retrievable
var sampleResultSub = new org.apache.jmeter.samplers.SampleResult();
// value to transmit, here is the title read by driver.getTitle()
var sResultToTransmit = WDS.browser.getTitle();
sampleResultSub.setResponseData(sResultToTransmit);
sampleResultSub.setSampleLabel("SubResultToTransmitInfo");
sampleResultSub.setSuccessful(true);
sampleResultSub.setContentType("text/plain");
// sampleResultSub.setDataEncoding("ISO-8895-1");
WDS.sampleResult.addSubResult(sampleResultSub)
}
=== 2 =============================================================================
Add a child Regular Expression Extractor to the webdriver sampler like this (look at the screenshot)
Name : regEx Read Value from the SubSampleResult
Apply to : check Sub-samples only
Response field to check : Body
Reference name : P_TITLE
Regular expression : (.*)
Template : $1$
Matches no : 1
Default value : P_TITLE_NOT_FOUND
==========================================
The variable called P_TITLE contents the title of the page. The title is get by a webdriver function WDS.browser.getTitle()
But i have now a little issue to passe the title to another webdriver sampler because the title contents space chars.
In a second Webdriver sampler > Parameters : ${P_TITLE}
In the script :
WDS.log.info("Nb args = " + WDS.args.length); => 5 args !
Regards
Vincent D.