JMeter做UI自动化

不推荐,好别扭,但可行

插件安装

  • 搜插件selenium,安装

添加config

  • 添加线程组
  • 右键线程组->添加->配置元件->jp@gc - Chrome Driver Config

  • option和proxy不解释了

添加Sampler

  • 右键线程组->添加->取样器->jp@gc - WebDriver Sampler

  • script language 选择:JavaScript(可惜没有python)

  • 界面说明

    • Name - for the test that each Web Driver Sampler will have. This is used by the reports.
    • Parameters - is optional and allows the reader to inject variables used in the script section.
    • Script - allows the scripter to control the Web Driver and capture times and success/failure outcomes

DEMO代码及解释

https://jmeter-plugins.org/wiki/WebDriverSampler/

  • 示例代码
// 相当于python的from  import   java的import
var pkg = JavaImporter(org.openqa.selenium) // Start capturing the sampler timing 开始捕获取样
WDS.sampleResult.sampleStart() // 代码块
WDS.browser.get('http://114.116.2.138:8090/forum.php')
WDS.browser.findElement(pkg.By.id('ls_username')).sendKeys('admin')
// 等价于 WDS.browser.findElement(org.openqa.selenium.By.id('ls_username')).sendKeys('admin')
WDS.browser.findElement(pkg.By.id('ls_password')).sendKeys('123456')
// js语法定义了一个 sleep函数 ,让你从python平滑过渡到 js
var sleep = function(time) {
var timeOut = new Date().getTime() + parseInt(time, 10);
while(new Date().getTime() <= timeOut) {}
} WDS.browser.findElement(pkg.By.cssSelector('.pn.vm')).click()
sleep(3000) // 断言部分
if(WDS.browser.getCurrentUrl() != 'http://114.116.2.138:8090/forum.php') {
WDS.sampleResult.setSuccessful(false)
WDS.sampleResult.setResponseMessage('Expected url to be XXX')
}
else{
WDS.sampleResult.setSuccessful(true)
} // Stop the sampler timing 停止取样
WDS.sampleResult.sampleEnd()
  • WDS就是Web Driver Sampler

  • 麻烦的是你可能并没有自动补齐(好像可以出来,但没研究),这个对象有哪些属性方法

  • 深入的研究要看

    https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/package-summary.html
  • 比如显式等待的一个应用

    var pkg = JavaImporter(org.openqa.selenium, org.openqa.selenium.support.ui)
    var wait = new pkg.WebDriverWait(WDS.browser, 5, 0.5)
    wait.until(pkg.ExpectedConditions.presenceOfElementLocated(pkg.By.cssSelector('ul.suggestions')))

关于WDS的一些属性

  1. WDS.name - is the value provided in the Name field (above).
  2. WDS.vars - JMeterVariables - e.g.

vars.get("VAR1"); vars.put("VAR2","value"); vars.remove("VAR3"); vars.putObject("OBJ1",new Object());

  1. WDS.props - JMeterProperties (class java.util.Properties) - e.g.

props.get("START.HMS"); props.put("PROP1","1234");

  1. WDS.ctx - JMeterContext
  2. WDS.parameters - is the value provided in the Parameters field (above).
  3. WDS.args - is an array of the strings provided in the Parameters field, but split by the space ' ' character. This allows the scripter to provide a number of strings as input and access each one by position.
  4. WDS.log - is a Logger instance to allow the scripter to debug their scripts by writing information to the jmeter log file (JMeter provides a GUI for its log entries)
  5. WDS.browser - is the configured Web Driver browser that the scripter can script and control. There is detailed documentation on this object on the Selenium Javadocs page.
  6. WDS.sampleResult - is used to log when the timing should start and end. Furthermore, the scripter can set success/failure state on this object, and this SampleResult is then used by the JMeter reporting suite. The JMeter javadocs provide more information on the API of this object

最新文章

  1. Solution to “VirtualBox can&#39;t operate in VMX root mode” error in Windows 7
  2. 一群猴子排成一圈,按1,2,...n 编号,数到m只,踢出局,直到剩下最后一个猴子是大王
  3. 编译及load mydqli.so文件
  4. ACCESS TOKEN
  5. net发布mvc项目
  6. python路径函操作
  7. 边坡优化主题5——bzoj 1096 [ZJOI2007]仓库建设 解决问题的方法
  8. Cocos2d-x 2.3.3版本 FlappyBird
  9. Processes and Threads (转)
  10. Unity中的万能对象池
  11. Scrapy爬虫大战京东商城
  12. windows上定时执行php文件
  13. SpringBoot12 QueryDSL01之QueryDSL介绍、springBoot项目中集成QueryDSL
  14. Win10家庭版中的SQL2005无法远程连接
  15. wGenerator代码生成工具
  16. Api管家系列(一):初探
  17. maven 发布快照版本后的引用
  18. 程序配置的原则和实践以及 Spring Boot 支持方式
  19. c#中的多线程异常 (转载)
  20. 手打struts知识点

热门文章

  1. fiddler提示&quot;The system proxy was changed,click to reenable fiddler capture&quot;的解决方法
  2. Java内存马的学习总结
  3. 【Java SE进阶】Day09 字节流、字符流、I/O操作、属性集
  4. 【Shell脚本案例】案例1:服务器系统配置初始化
  5. 网络基础与osi七层与TCP/IP协议
  6. hashlib加密模块 subprocess模块 logging日志模块
  7. python注释、变量、数据类型详细
  8. 在Windows服务器安装禅道
  9. NeurIPS 2022:基于语义聚合的对比式自监督学习方法
  10. vue下载与安装