我正在使用Jmeter和Selenium Webdriver采样器和JAVA . 我有一个包含用户名和密码的CSV文件 . 我的测试有CSV数据集配置来读取文件和Webdriver采样器 . 我在java中编写selenium代码 . 我想从CSV文件中读取用户名和密码,并在我的selenium脚本中使用它 . 这是我的代码:
import openqa.selenium.OutputType.*;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.*;
WDS.sampleResult.sampleStart();
var ctx = org.apache.jmeter.threads.JMeterContextService.getContext();
var vars = ctx.getVariables();
String userName = WDS.args[0]; -- the result of this line is "loginName" instead of actual log in name. same for 2nd line.
//String userName = vars.get('loginName');
我的问题是它不是从CSV中挑选 . 以上两行产生结果“loginName”,而不是从文件中选择实际的登录名 . 我用过单引号,双引号等,但没有运气 . 使用$ 会出错 . 任何想法有什么问题以及如何解决它?
1 回答
java
作为语言,它们将导致语法错误groovy
. 当您选择java
时,它不是"real" java,而是Beanshell解释器,因此如果您想使用普通的Java语法 - 请选择Groovy . 此外since JMeter 3.1 it is recommended to use Groovy for all forms of scripting . 这是因为Groovy has much better performance than other scripting options .Groovy脚本工作的证据: