How to write a script in Javascript for getting a browser performance data with using jp@gc webdriver plugin

738 views
Skip to first unread message

ino...@gmail.com

unread,
Jul 12, 2017, 7:21:48 PM7/12/17
to jmeter-plugins
Hi, All

I write a script for getting a browser performance data with using jp@gc webdriver plugin/javascript
but some exceptions occur and I couldn't get performance log.

It (performance log) means Chrome developer tools' network tab and timeline tab data.  

In addition, I found out some web page knowledge resource but I couldn't find out javascript sample code.

Anybody help?

My  jp@gc Webdriver Sampler code:================
//import
var pkg = JavaImporter(
    org.openqa.selenium
    ,org.openqa.selenium.support.ui
    ,org.openqa.selenium.remote
    ,java.util.Arrays
    ,java.util.logging
    ,java.util.Map
    ,org.openqa.selenium.chrome
    ,org.openqa.selenium.logging)

var capabilities = pkg.DesiredCapabilities.chrome()
var logPrefs = {'browser':'ALL','driver':'ALL','performance': 'ALL'}
var options = {perfLoggingPrefs:{traceCategories: 'v8,blink.console,disabled-by-default-devtools.timeline'}}

capabilities.setCapability(pkg.CapabilityType.LOGGING_PREFS, logPrefs)
capabilities.setCapability(pkg.ChromeOptions.CAPABILITY, options)

WDS.sampleResult.sampleStart()

WDS.browser.capabilities = capabilities

WDS.browser.get("http://www.sample.com/")

var logEntries = new pkg.LogEntries(WDS.browser.manage().logs().get(pkg.LogType.PERFORMANCE))
logEntries.forEach(
    function(entry){
        WDS.log.info(entry.getTimestamp() + " " + entry.getLevel() + " " + entry.getMessage())
    }
)
WDS.sampleResult.sampleEnd()


My environment:================

OS:windows 7
Java : 8
JMeter ver : 3.2 --<<use>>--> plugin manager--<<use>>-->Selenium/Webdriver support
Borwser : Chrome latest
JMeter setting:
 ThreadGroup 1user 1iteration + jp@gc Chrome Driver (is set chromedriver.exe)

Thanks

ino9dev @ gmail.com

rohitset...@gmail.com

unread,
Feb 1, 2019, 3:36:44 AM2/1/19
to jmeter-plugins
even i am trying to get the same. Do you have any luck?

gli...@gmail.com

unread,
Feb 4, 2019, 9:41:48 AM2/4/19
to jmeter-plugins
DesiredCapabilities are used for browser instance creation and they are immutable (cannot be changed in the runtime). So consider the following alternatives:

  1. Execute JavaScript in order to access window.performance object and query i.e. Performance.timeOrigin / Performance.navigation data
  2. Switch to JSR223 Sampler and Groovy language so you will be able to instantiate your own WebDriver implementation with whatever capabilities you want so you will not have to rely on the defaults hard-coded into the WebDriver Sampler plugin    

Nikita Raikar

unread,
Jun 18, 2024, 2:32:10 PMJun 18
to jmeter-plugins
any luck on this code ? i have a similar requirement in my project . let me know if you have leads with this issue 

Dmitri T

unread,
Jun 19, 2024, 2:22:54 AMJun 19
to jmeter-plugins
If you upgrade your WebDriver Sampler to the latest version using JMeter Plugins Manager you should see Capabilities Management tab, you can set whatever Capabilities you want there

Untitled.jpg
Reply all
Reply to author
Forward
0 new messages