2
votes

I am trying to use the beanshell script posted here to get the path of the jmx that is being run in my jmeter test - Access to JMeter script path

It is working and if I log the output of the path when set by beanshell or view the variables with the debugger I get the path to the script displayed as I expected -

c:\my\path\to\script

but when I then try to pass that variable into sendKeys, the slashes "\" are being removed so -

c:mypathtoscript

And this doesn't work so I am unable to attach/upload my file..

Sure I am missing something stupid

Thanks

2
try escaping the backward slashes.Kevin Kloet
Hi Kevin, How can I do that? the path is being generated by the beanshell script that is posted in the link...Karl
i don't know how you would escape the generated path, but use either double backslash to escape a backslash or a forward slash if you can modify it before it gets passed to your sendKeys variable.Kevin Kloet
please share the BeanShell code and how you are passing the value of JMeter absolute pathNaveen Kumar R B
I have a UDV called "homepath" with a value of "${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}" and I am calling the variable using ${homepath}, debug shows it with single backslash, and these are being removed when webdriver runs..Karl

2 Answers

0
votes

Needed to user vars.put to put the JMeter UDV value into a Javascript variable, then use javascript concatenate to link it all together.

0
votes

There are at least 2 ways to get this done without using Beanshell:

  1. Call FileServer methods from WebDriver Sampler:

    someElement.sendKeys(org.apache.jmeter.services.FileServer.getFileServer().getBaseDir())
    
  2. Get the value from JMeterVariables

    var vars = org.apache.jmeter.threads.JMeterContextService.getContext().getVariables()
    someElement.sendKeys(vars.get('homepath'))
    

Example full code:

WDS.sampleResult.sampleStart()
WDS.browser.get('http://ya.ru')
var searchInput = WDS.browser.findElement(org.openqa.selenium.By.id('text'))

//directly access function from JavaScript
searchInput.sendKeys(org.apache.jmeter.services.FileServer.getFileServer().getBaseDir())

//alternative way - getting the value from JMeter Variables
var vars = org.apache.jmeter.threads.JMeterContextService.getContext().getVariables()
searchInput.sendKeys(vars.get('homepath'))

WDS.sampleResult.sampleEnd()

Comprehensive information on accessing JMeter API classes from WebDriver Sampler and few more tips and tricks: The WebDriver Sampler: Your Top 10 Questions Answered