如何在WebDriver Sampler中设置JMeter变量? [英] How to set JMeter Vars from within WebDriver Sampler?

查看:240
本文介绍了如何在WebDriver Sampler中设置JMeter变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// 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());

上面的最后一行不起作用。

The last line above doesn't work.

我可以成功使用CSS / JQuery Extractor为JMeter vars添加值...

I can successfully use CSS/JQuery Extractor to add values to JMeter vars...

但怎么能我是从WebDriver Sampler中做同样的事情吗?

But how can I do the same from within WebDriver Sampler?

推荐答案

您可以从WebDriver Sampler中访问JMeter API类,它实现为< a href =https://jcp.org/en/jsr/detail?id=223 =nofollow> JSR 223标准,例如你可以参考JMeter变量(又名 vars 如下所示)

You can access JMeter API classes from within the WebDriver Sampler, it's implemented as JSR 223 standard for instance you can refer JMeter Variables (aka vars as follows)

在WebDriver采样器中:

In the WebDriver Sampler:

var ctx = org.apache.jmeter.threads.JMeterContextService.getContext()
var vars = ctx.getVariables();

vars.put('foo','bar')

现在你有 $ {foo} 变量,其值为 bar

Now you have ${foo} variable with the value of bar

请参阅 WebDriver采样器:您回答的十大问题更多WDS采样器提示和技巧指南。

See The WebDriver Sampler: Your Top 10 Questions Answered guide for more WDS sampler tips and tricks.

这篇关于如何在WebDriver Sampler中设置JMeter变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆