0

I have created a script in JMeter using Selenium jar and I have written script in WebDriver sample using Java script language .

Script is working fine

//var pkg2 = JavaImporter(net.lightbody.bmp.BrowserMobProxy);

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

WDS.sampleResult.sampleStart(); //captures sampler's start time
WDS.sampleResult.getLatency();
WDS.log.info("Sample started");

WDS.browser.get('http://newtours.demoaut.com/mercuryreservation.php'); //opens website specified in 'http://duckduckgo.com'
WDS.log.info("Sample ended - navigated to flight reservation.com");


var btnView = WDS.browser.findElement(pkg.By.xpath("//div[contains(text(),'Mercury')]"))
WDS.browser.executeScript("arguments[0].click();", btnView)

WDS.log.info(btnView.parameters);
WDS.log.info(btnView.size);
var username=WDS.browser.findElement(pkg.By.xpath("//input[@name='userName']"));

username.sendKeys([WDS.parameters]);

var password=WDS.browser.findElement(pkg.By.xpath("//input[@name='password']"));
password.sendKeys(['mypassword']);


var login=WDS.browser.findElement(pkg.By.xpath("//input[@value='Login']"));
login.click();
WDS.sampleResult.sampleEnd();

Now I Would like to generate HAR file(HTTP Water fall) in JMeter.

Can anyone help me on this ?

  • Please tell why the Jmeter is only generating 1KB file after execution. and when we open the same on LoadRunner, no call are recorded. Regards Gaurav – Gaurav Verma Dec 17 '18 at 6:01
1
  1. Add JSR223 PreProcessor as a child of your WebDriver Sampler
  2. Put the following code into "Script" area

    def proxy = new net.lightbody.bmp.BrowserMobProxyServer()
    proxy.setHarCaptureTypes(net.lightbody.bmp.proxy.CaptureType.getAllContentCaptureTypes())
    proxy.enableHarCaptureTypes(net.lightbody.bmp.proxy.CaptureType.REQUEST_CONTENT, net.lightbody.bmp.proxy.CaptureType.RESPONSE_CONTENT)
    proxy.newHar()
    proxy.start(8888)
    vars.putObject('proxy',proxy)
    
  3. Configure your browser to use the BrowserMobProxy for all traffic

    Selenium BrowserMob JMeter

  4. Add JSR223 PostProcessor as a child of the WebDriver Sampler and out the following code into "Script" area:

    def proxy = vars.getObject('proxy')
    
    proxy.getHar().writeTo(new File("/path/to/your/file.har"))
    proxy.stop()
    

You can learn more about Groovy scripting in JMeter via Apache Groovy - Why and How You Should Use It article.

  • Thanks Dmitri.. This code works but Har file is not generated in proper manner. It always shown 1 KB file after TR executing. – avanish sisodia Feb 5 '18 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.