What?JMeter做UI自动化!

what,jmeter,ui,自动化 · 浏览次数 : 330

小编点评

**推荐:** JMeter不能使用Selenium插件进行UI自动化。Selenium插件只支持Python脚本。 **其他提示:** 1. 在安装Selenium插件之前,确保已安装了Python环境。 2. 在运行UI自动化脚本时,请确保浏览器已安装并已启动。 3. 确保代码中的变量和配置项正确。

正文

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

与What?JMeter做UI自动化!相似的内容:

What?JMeter做UI自动化!

JMeter做UI自动化 不推荐,好别扭,但可行 插件安装 搜插件selenium,安装 添加config 添加线程组 右键线程组->添加->配置元件->jp@gc - Chrome Driver Config option和proxy不解释了 添加Sampler 右键线程组->添加->取样器->j

[转帖]JMeter InfluxDB v2.0 listener plugin

https://github.com/mderevyankoaqa/jmeter-influxdb2-listener-plugin Support my Ukrainian Family ❤️ Like what you see? 😍 Description The goal of the pr

[转帖]WHAT IS MTR?

https://github.com/traviscross/mtr mtr combines the functionality of the 'traceroute' and 'ping' programs in a single network diagnostic tool. As mtr

【转帖】What are segfault rip/rsp numbers and how to use them

https://stackoverflow.com/questions/1456899/what-are-segfault-rip-rsp-numbers-and-how-to-use-them 11 When my linux application crashes, it produces a

[转帖]What is Pstate

https://www.jianshu.com/p/342480d917e3 When someone refers to a P-state, generally only the frequency is talked about. For example, on my Intel® Core™

生成带重复的笛卡尔乘积过程 Cartesian Product with Repetition

目录What is Cartesian Product with RepetitionCode Demo What is Cartesian Product with Repetition 比如说有两个集合: \(\{1, 2, 3\}\) \(\{A, B, C\}\) 想把他们组合成所有可能组合

[转帖]什么是 istio

https://cizixs.com/2018/08/26/what-is-istio/ 如果你比较关注新兴技术的话,那么很可能在不同的地方听说过 istio,并且知道它和 service mesh 有着牵扯。这篇文章是我之前在公司内部做过的分享,可以作为了解 istio 的入门介绍,了解什么是 i

[转帖]每个程序员都应该了解的内存知识【第一部分】

https://www.oschina.net/translate/what-every-programmer-should-know-about-memory-part1?print [编辑的话: Ulrich Drepper最近问我们,是不是有兴趣发表一篇他写的内存方面的长文。我们不用看太多就已

[转帖]什么是 LLVM?Swift, Rust, Clang 等语言背后的支持

https://www.oschina.net/translate/what-is-llvm-the-power-behind-swift-rust-clang-and-more?print 要了解用于以编程方式生成机器原生代码的编译器框架是如何让新语言的推出以及对现有的语言进行增强比以往更加容易了

基于Java Swing和BouncyCastle的证书生成工具

"Almost no one will remember what he had just not interested." - Nobody “几乎没有人会记得他所丝毫不感兴趣的事情。” —— 佚名 0x00 大纲 目录0x00 大纲0x01 前言0x02 技术选型0x03 需求分析目标用户用户故