【问题标题】:JMETER Beanshell ( java.lang.String ) not found in class在类中找不到 JMETER Beanshell ( java.lang.String )
【发布时间】:2017-04-03 12:28:44
【问题描述】:

我正在开发一个 Jmeter beanshell 脚本来使用 Selenium。我决定使用 beanshell 采样器,这样我就可以使用在 WDS 界面中无法访问的 java 和 selenium 命令。

我的代码工作正常,除了一些字符串输入。这是一个示例(分解为准系统):

import org.openqa.selenium.chrome.ChromeOptions;

ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");

我得到了这个错误

2017/03/31 13:43:21 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``import org.openqa.selenium.chrome.ChromeOptions; debug();  ChromeOptions options . . . '' : Error in method invocation: Method addArguments( java.lang.String ) not found in class'org.openqa.selenium.chrome.ChromeOptions'  2017/03/31 13:43:21 WARN  - jmeter.protocol.java.sampler.BeanShellSampler: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.openqa.selenium.chrome.ChromeOptions; debug();  ChromeOptions options . . . '' : Error in method invocation: Method addArguments( java.lang.String ) not found in class'org.openqa.selenium.chrome.ChromeOptions'  201

我在 sendkeys 等其他一些命令中看到了类似的情况。

为什么这个命令不接受我的字符串?我可以运行完整的脚本并且浏览器打开文件,所以我知道 selenium 是用 jmeter 设置的。只是某些使用字符串的命令执行此操作。

谢谢 J

【问题讨论】:

  • 您是如何将 Selenium 类添加到 JMeter 类路径的?
  • 它不起作用,除非您正确映射硒罐。我建议您使用网络驱动程序采样器。 Beanshell 并不容易获得更好的性能。

标签: java selenium jmeter beanshell


【解决方案1】:

根据您的 Selenium 客户端库版本,您可能没有此方法将单个字符串作为参数。使用以下行创建一个新的Beanshell Sampler

log.info(javap(org.openqa.selenium.chrome.ChromeOptions));

查看 JMeter 控制台:您将看到 javap command 打印出 ChromeOptions 类的所有可用方法,例如对于我的安装(我有 WebDriver Sampler 插件),它会输出以下内容:

类 org.openqa.selenium.chrome.ChromeOptions 扩展类 java.lang.Object

公共布尔 org.openqa.selenium.chrome.ChromeOptions.equals(java.lang.Object)

public int org.openqa.selenium.chrome.ChromeOptions.hashCode()

public void org.openqa.selenium.chrome.ChromeOptions.addArguments(java.lang.String[])

public void org.openqa.selenium.chrome.ChromeOptions.addArguments(java.util.List)

如果您使用与我相同的 Selenium 库版本 (2.52.0),您应该更改此行:

options.addArguments("start-maximized");

到这个:

options.addArguments(new String[] {"start-maximized"});

您的脚本应该会按预期开始工作。

有关 JMeter 测试中的 Beanshell 脚本的更多信息,请参阅 How to Use BeanShell: JMeter's Favorite Built-in Component 文章。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-15
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多