简体   繁体   English

如何在Jmeter中编写Groovy脚本

[英]How to write groovy Script in Jmeter

Hello Stackoverflow Community, 您好Stackoverflow社区,
I am new to Jmeter and Related Stuff. 我是Jmeter和相关人员的新手。
Just Finished with Login Request and Response through Selenium WebDriver Sampler(using Java Script) . 通过Selenium WebDriver Sampler(使用Java脚本)完成登录请求和响应。
Screen shot is also attached with this post. 此帖子也附有屏幕截图。 All working Well. 一切正常。
Now i go through some articles ,they stress on using groovy script(under JSR223 Sampler) but i am not able to figure out how to convert this same Javascript(WDS sampler) in Groovy(JSR223 sampler) runnable Script.I will be very thankful for any Kind of help in this direction. 现在我浏览一些文章,他们重点介绍了使用Groovy脚本(在JSR223 Sampler下),但是我无法弄清楚如何在Groovy(JSR223 sampler)可运行脚本中转换相同的Javascript(WDS sampler)。我将非常感谢在这方面的任何帮助。 Thanks 谢谢

groovy(Groovy 2.4.15/Groovy Scripting Engine 2.0) is already displayed in my JSR223 Sampler [im using apache-jmeter-5.0 ] i run hello world program its working fine..further i have no idea abt how to play with groovy script. groovy(Groovy 2.4.15 / Groovy Scripting Engine 2.0)已经显示在我的JSR223采样器中[使用apache-jmeter-5.0即时显示]我运行了hello world程序,它的工作正常。.我还不知道如何使用groovy脚本。
Below is my code in Javascipt(selenium WDS) 以下是我在Javascipt(Selenium WDS)中的代码

WDS.sampleResult.sampleStart();
WDS.log.info("Maximo Application ---- Sample started");
var pkg = JavaImporter(org.openqa.selenium); //WebDriver classes
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait); 
var wait = new support_ui.WebDriverWait(WDS.browser, 5000);
var conditions=org.openqa.selenium.support.ui.ExpectedConditions;
var selenium_keys=JavaImporter(org.openqa.selenium.Keys);
WDS.sampleResult.getLatency();
//-----------------------------Login in Application---------------------------------------------

WDS.browser.get('http://xxxxxxxxxxxxxxx/maximo/webclient/login/login.jsp'); //opens website  
WDS.log.info("Maximo Application ---- Username and Password dynamicly picked from C:/user.csv ");

//UserName
var userName = WDS.browser.findElement(pkg.By.id('username'));  
WDS.log.info("Maximo Application ---- Username "+'${username}');
userName.click(); 
userName.sendKeys('${username}'); 
//Password
var password=WDS.browser.findElement(pkg.By.id("password"));
password.click();
WDS.log.info("Maximo Application ---- password "+'${password}');
password.clear();
password.sendKeys('${password}');
WDS.browser.findElement(pkg.By.id("loginbutton")).click();
WDS.log.info("Maximo Application ---- Logged by USER Name--- "+ '${username}');
WDS.sampleResult.sampleEnd();

I really Wann to switch on groovy as all coming scenarios are going to be complex 我真的要开始使用Groovy,因为所有即将出现的情况都将变得非常复杂

WDS_javascript WDS_javascript

i could give you the guidance about your code. 我可以为您提供有关您的代码的指导。

in general, even when you are using javascript in jmeter - you are calling java methods. 通常,即使在jmeter中使用javascript时,您也在调用java方法。

groovy will do the same but in syntax it's closer to java. groovy会做同样的事情,但是在语法上更接近java。

so: 所以:

  • declare variables with def instead of var def而不是var声明变量
  • change JavaImporter(XYZ) to import XYZ at the beginning of script JavaImporter(XYZ)更改为在脚本开头import XYZ
  • remove all java imported variables as they not needed. 删除所有不需要的Java导入变量。 such as support_ui support_ui

just an example: 只是一个例子:

import org.openqa.selenium.*; //need .* to import all classes from package
import org.openqa.selenium.support.ui.WebDriverWait; //import exact class

WDS.sampleResult.sampleStart(); //code remains the same
//var pkg = JavaImporter(org.openqa.selenium); //moved to import
//var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait); //moved to import
def wait = new WebDriverWait(WDS.browser, 5000); //removed `support_ui.`

def userName = WDS.browser.findElement(By.id('username')); //removed `pkg.`

and finally just learn java & groovy 最后只是学习Java和groovy

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

相关问题 JMeter Groovy - WebDriver Sampler 脚本失败,响应代码为 500 - JMeter Groovy - WebDriver Sampler script failed with Response Code 500 如何在JMeter脚本中加密数据 - How to Encrypt data in JMeter script 如何在 Jmeter 上使用 Selenium WebDriver 4 和 Groovy 保持浏览器打开? - How to keep browser open with Selenium WebDriver 4 and Groovy on Jmeter? Jmeter Groovy webdriver By.xpath - Jmeter Groovy webdriver By.xpath Jmeter-selenim 驱动程序 javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException:No such property: org for class - Jmeter-selenim driver javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException:No such property: org for class 如何通过 jenkins - jmeter webdriver 脚本管理网络驱动程序? - How to manage web drivers via jenkins - jmeter webdriver script? 如何从 Jenkins Pipeline groovy 脚本更新配置属性文件? - How to update config properties file from a Jenkin Pipeline groovy script? 如何编写自动化脚本以检查UI更改? - How to write Automation script to check the UI changes? 如何在webdriver中为网格复选框编写测试脚本 - How to write test script for grid checkbox in webdriver 如何使用Selenium Web驱动程序和groovy脚本在chrome中运行测试用例? - How to run my test case in chrome using selenium web driver and groovy script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM