javascript-如何从WebDriver Sampler内设置JMeter Vars?
作者:互联网
// I had previously used a CSS/JQuery extractor to get a URL from a page and add it to JMeter vars - accessing it here
var pageURL = "${valueFromJmeterVars}";
// navigate to that url
WDS.browser.get(pageURL);
// selecting an element
var button = wait.until(pkg.ExpectedConditions.visibilityOfElementLocated(pkg.By.cssSelector(buttonLocator)));
// log desired boolean value to console, so I can confirm is as expected
WDS.log.info('reserveASpotButton:' + reserveASpotButton.isEnabled());
// add my boolean to JMeter vars, so I can access later from beanshell post-processor (where I do my assertions)
vars.put("reserveASpotButtonIsEnabled", reserveASpotButton.isEnabled());
上面的最后一行无效.
我可以成功使用CSS / JQuery Extractor将值添加到JMeter vars …
但是,如何在WebDriver Sampler中执行相同的操作?
解决方法:
您可以从WebDriver Sampler中访问JMeter API类,它实现为JSR 223 standard,例如,您可以引用JMeter变量(也称为var,如下所示)
在WebDriver采样器中:
var ctx = org.apache.jmeter.threads.JMeterContextService.getContext()
var vars = ctx.getVariables();
vars.put('foo','bar')
现在您有了${foo}变量,其值为bar
有关更多WDS采样器的提示和技巧,请参见The WebDriver Sampler: Your Top 10 Questions Answered指南.
标签:jmeter-plugins,javascript,jmeter,automated-tests,webdriver 来源: https://codeday.me/bug/20191011/1890772.html