selenium - 如何获得多页 JMeter Webdriver 计时

标签 selenium jmeter

我使用 JMeter 已经有一段时间了,但是 webdriver 对我来说是新的。
我正在尝试为多页场景做一些计时并有一个问题。
我正在使用 JMeter webdriver 采样器和 HTMLunit:

这是场景
1.进入网页http://162.243.100.2342.在搜索框中输入单词hello
3.点击提交

我想得到的是:
1.加载第一页需要多长时间
2. 从点击提交到结果页面加载需要多长时间

我有以下代码,它只给我一个示例时间。
我要怎么改才能有两个?

var pkg = JavaImporter(org.openqa.selenium)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
var wait = new support_ui.WebDriverWait(WDS.browser, 5000)

WDS.sampleResult.sampleStart()
WDS.browser.get('http://162.243.100.234/')

var searchField = WDS.browser.findElement(pkg.By.id('s'))
searchField.click()
searchField.sendKeys(['hello'])

var button = WDS.browser.findElement(pkg.By.id('searchsubmit'))
button.click()
WDS.sampleResult.sampleEnd()

我尝试添加另一个 sampleStart 和 sampleEnd 但得到了错误。
我需要以某种方式使用两个采样器吗?

最佳答案

是的,您需要将代码分成两部分:

第一采样器:

WDS.sampleResult.sampleStart()
WDS.browser.get('http://162.243.100.234')
WDS.sampleResult.sampleEnd()

第二个采样器:
var pkg = JavaImporter(org.openqa.selenium)
WDS.sampleResult.sampleStart()
var searchField = WDS.browser.findElement(pkg.By.id('s'))
searchField.click()
searchField.sendKeys(['hello'])
var button = WDS.browser.findElement(pkg.By.id('searchsubmit'))
button.click()
WDS.sampleResult.sampleEnd()

提及 WDS.sampleResult.sampleStart()WDS.sampleResult.sampleEnd()方法调用

根据将 Selenium 与 JMeter's WebDriver Sampler 一起使用指导

WDS.sampleResult.sampleStart() and WDS.sampleResult.sampleEnd() captures sampler’s time and will track it. You can remove them, the script will still work but you can’t get load time



希望这可以帮助

关于selenium - 如何获得多页 JMeter Webdriver 计时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21444441/

相关文章:

java - 我们可以将 List<WebElement> 的对象作为参数传递给函数吗?

java.lang.NoClassDefFoundError : gherkin/IGherkinDialectProvider while running Selenium-Cucumber test 错误

java - 如何在 xpath 中选择多个标签

python - 为什么 split is_text_present() 会导致 Firefox 间歇性出现 StaleElementReferenceException(但 Chrome 或 phantomjs 不会)?

JMeter HTTP请求: Always Sending GET Method

jmeter - 将变量从响应传递到 JMETER 中的请求

JMeter:检索所有嵌入资源并不检索所有资源

javascript - Selenium JavaScript 在异常后继续循环

http - jmeter 在多个服务器上运行相同的 HTTP 请求

java - Perfmon 指标收集器错误