简体   繁体   English

如何在JMeter中运行groovy / geb测试?

[英]How to run groovy/geb tests in JMeter?

How would I go about running geb tests in JMeter? 我如何在JMeter中运行geb测试?

I have compiled a jar of my test and have created a BSF sampler in JMeter. 我编译了一个测试罐,并在JMeter中创建了一个BSF采样器。 I have installed the groovy plugin for Jmeter. 我已经为Jmeter安装了groovy插件。

My test class looks something like this: 我的测试类看起来像这样:

class LoginLogoutTest extends GebSpec {
  def "Login Logout"() {
    given: "Go to the Login Page"
    LoginPage loginPage = to LoginPage

    when:
    loginPage.login("admin", "password")
    then:
    DashboardPage dashboardPage = at DashboardPage

    when:
    dashboardPage.logout()
    then:
    waitFor {at LoginPage}
  }
}

I've used Gradle to build the jar with all the required dependencies for this test class. 我已经使用Gradle来构建具有此测试类所需的所有依赖项的jar。

Then in my JMeter BSF sampler I have set the language to groovy and written the following script. 然后在我的JMeter BSF采样器中,我将语言设置为groovy并编写以下脚本。 My web-test.jar is in JMeters \\lib directory as some tutorials have shown. 我的web-test.jar位于JMeters \\ lib目录中,正如一些教程所示。

import com.geb.tests.LoginLogoutTest;

LoginLogoutTest myTest = new LoginLogoutTest();

myTest."Login Logout"(); //if commented out i get no errors

When I try to call the "Login Logout"() function JMeter throws the follolwing exception: 当我尝试调用"Login Logout"()函数时,JMeter会抛出以下异常:

WARN  - jmeter.protocol.java.sampler.BSFSampler: BSF error org.apache.bsf.BSFException: exception from Groovy: groovy.lang.MissingFieldException: No such field: $spock_sharedField__browser for class: org.codehaus.groovy.runtime.NullObject

If I don't call the method Jmeter does not throw any errors so I'm assuming I am initializing the class from my jar correctly in my JMeter script. 如果我不调用该方法,Jmeter不会抛出任何错误,所以我假设我在我的JMeter脚本中正确地从我的jar初始化类。

The reason for doing this is so we can perform load testing by running multiple threads of this test using PhantomJs. 这样做的原因是我们可以通过使用PhantomJs运行此测试的多个线程来执行负载测试。

You can use Groovy Out of the box in JMeter through JSR223 Samplers: 您可以通过JSR223采样器在JMeter中使用Groovy开箱即用:

  • Before JMeter 3.0 , download Groovy, copy embeddable/groovy-all.jar to jmeter/lib and restart JMeter 在JMeter 3.0之前,下载Groovy,将embeddable / groovy-all.jar复制到jmeter / lib并重启JMeter

  • Starting from JMeter 3.0, Groovy is embedded 从JMeter 3.0开始,嵌入了Groovy

I was able to find a Spock sampler for JMeter that works. 我找到了适用于JMeter的Spock采样器。 I'm able to run my tests. 我能够运行我的测试。 Here's the link if anyone else is interested. 如果其他人有兴趣,这是链接。 JMeter Spock Sampler However, when running single threaded tests, just to see that the sampler works, the chrome browser stays open. JMeter Spock Sampler然而,当运行单线程测试时,只是为了看到采样器工作,Chrome浏览器保持打开状态。 Not quite sure why. 不太清楚为什么。 This would be an issue when running multiple thread because there would be many browsers left open. 这在运行多个线程时会出现问题,因为会有许多浏览器保持打开状态。 The goal is to use a headless browser, phantomjs, which I've also gotten to work. 我的目标是使用无头浏览器phantomjs,我也开始使用它。 But if I run multiple threads with the headless browser there are multiple instances left behind and visible in the windows task manage process list lol. 但是,如果我使用无头浏览器运行多个线程,则会在Windows任务管理进程列表中显示多个实例并且可见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM