{"id":4675,"date":"2018-03-09T09:57:02","date_gmt":"2018-03-09T14:57:02","guid":{"rendered":"https:\/\/www.redline13.com\/blog\/?p=4675"},"modified":"2018-03-09T09:57:02","modified_gmt":"2018-03-09T14:57:02","slug":"capturing-api-performance-data-firefox-chrome-webdriver-test","status":"publish","type":"post","link":"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/","title":{"rendered":"Capturing API Performance Data from Firefox or Chrome during Webdriver Test"},"content":{"rendered":"<div>In support of <a href=\"https:\/\/www.redline13.com\/blog\/2017\/02\/using-selenium-webdriver-run-scalable-load-tests\/\">running selenium webdriver tests<\/a> at scale, we built a simple wrapper for webdriver.<\/div>\n<div>\n<div>The wrapper is\u00a0<a href=\"https:\/\/github.com\/redline13\/webdriverjs\">open source<\/a> and easy to run on a single machine, while RedLine13 can run it on 1,000 machines.<\/div>\n<\/div>\n<div><\/div>\n<p>Initial support for performance metrics:<\/p>\n<h3>Collecting real-time metrics by running via PhantomJS.<\/h3>\n<div style=\"padding-left: 30px;\">We injected javascript into PhantomJS to listen to <a href=\"http:\/\/phantomjs.org\/api\/webpage\/handler\/on-resource-requested.html\">onResourceRequested<\/a> and <a href=\"http:\/\/phantomjs.org\/api\/webpage\/handler\/on-resource-received.html\">onResourceReceived<\/a>.\u00a0 We could also track errors and timeouts.\u00a0 You can see <a href=\"https:\/\/github.com\/redline13\/webdriverjs\/blob\/master\/lib\/phantomjs.js\">here<\/a> how we tracked and summarized this data.\u00a0 As well as emitting performance data to report back or write to\u00a0Apache JMeter JTL Performance file.<\/div>\n<div><\/div>\n<h3>Collecting metrics after test completed in Chrome<\/h3>\n<div style=\"padding-left: 30px;\">Chrome&#8217;s performance logs will give fine grain details of all events, however, accessing the log was easier when the test completed.\u00a0 This gave us full access to the log details.\u00a0 Enabling performance logs via webdriver is simple, just set the capabilities.<code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">builder.getCapabilities().setLoggingPrefs({'performance': 'ALL'});<\/code>\u00a0 \u00a0Read details of enabling Performance Log <a href=\"https:\/\/sites.google.com\/a\/chromium.org\/chromedriver\/logging\/performance-log\">here<\/a>.\u00a0 \u00a0 Our code processes the log to summarize the API performance and convert to Apache JMeter JTL format.<\/div>\n<div><\/div>\n<h3>Firefox to run tests but no metrics support<\/h3>\n<div style=\"padding-left: 30px;\">Firefox does not have a built in\u00a0mechanism to collect performance metrics.\u00a0 You would need to write a plugin which monitored the streams.\u00a0 \u00a0We have a plugin to do that\u00a0https:\/\/github.com\/redline13\/selenium-jmeter but it was written to be a recorder that worked with Selenium IDE plugin.<\/div>\n<div><\/div>\n<h3>Adding support via Browser Performance APIs<\/h3>\n<div>However, we had not looked at how to use\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Performance\">Browser Performance APIs<\/a>\u00a0to collect metrics during a test.\u00a0 We realize that by executing a script in the browser at any given point we can return back all the performance data and process for reporting in real-time or writing to Apache JMeter JTL.<\/div>\n<div>Here is how we did it (source <a href=\"https:\/\/github.com\/redline13\/webdriverjs\/blob\/master\/index.js#L92\">here<\/a>)<\/div>\n<div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">RedLineWebDriver.driver.executeScript(`\n  \/\/ PhantomJS does not support so don't execute if not available.\n  if ( ! window.performance || !window.performance.timeOrigin )\n    return null;\n\n  var data = {\n    \/\/ We need origin for timestamps\n    start : Math.round(window.performance.timeOrigin),\n    \/\/ The page we are on\n    navigation: window.performance.getEntriesByType('navigation'),\n    \/\/ All metrics available\n    resources: window.performance.getEntriesByType('resource')\n  };\n  \/\/ Clear so next time we get new data\n  window.performance.clearResourceTimings();\n  return data;\n`).then( function(metrics){ ... do things ... } );<\/pre>\n<p>We have further simplified this in our module<\/p>\n<h3>To record metrics at any time in Chrome or Chrome-Headless<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\/\/ include redline\nvar redline = require( 'redline13-webdriver' );\n\n\/\/ load your driver via redline13\n\/\/ redline13 library uses standard mechanism but presets some capabilities\n\/\/ browsers available - chrome, chrome-headless, firefox, firefox-headless, phantomjs\nvar browser = redline.loadBrowser('chrome');\n\n\/\/ You can require webdriver yourself or use redline13.webdriver\nvar By = redline.webdriver.By;\nvar until = redline.webdriver.until;\n\n\/\/ Start your script\nbrowser.get( \"http:\/\/example.com\" );\n\/\/ Do your normal operations\n\n\/\/ Record what is currently available\nbrowser.recordrecordMetrics( \"example\" );<\/pre>\n<h3>Firefox and Firefox headless support<\/h3>\n<p>Since firefox had no metrics support we manipulate webdriver .get to automatically\u00a0collect performance data.\u00a0 The call to browser.recordMetrics can still be used to collect metrics at other points of your script.\u00a0 See how we override the function at the source of <a href=\"https:\/\/github.com\/redline13\/webdriverjs\/blob\/master\/lib\/firefox-headless.js#L24\">firefox-headless.js<\/a>.<\/p>\n<\/div>\n<h3>Limitations<\/h3>\n<div>There are limitations to using this approach<\/div>\n<ul>\n<li>Failed requests are not logged<\/li>\n<li>Status codes of the request not provided<\/li>\n<\/ul>\n<div>These limitations prohibit collecting a full picture into missing or cached data.\u00a0 However, we can get accurate performance data for the API calls being made without having to build more tests.\u00a0 Huge win!\u00a0 We do recommend still using PhantomJS or Chrome Headless for a\u00a0complete performance analysis.<\/div>\n<div><\/div>\n<div>You can run this locally or add into all of your Selenium tests to capture API performance metrics.<\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In support of running selenium webdriver tests at scale, we built a simple wrapper for webdriver. The wrapper is\u00a0open source and easy to run on a single machine, while RedLine13 can run it on 1,000 machines. Initial support for performance metrics: Collecting real-time metrics by running via PhantomJS. We injected javascript into PhantomJS to listen to onResourceRequested and onResourceReceived.\u00a0 We could also track errors and timeouts.\u00a0 You can see here how we tracked and summarized this<a class=\"more-link\" href=\"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/\">Read More &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,52],"tags":[],"class_list":{"0":"entry","1":"post","2":"publish","3":"author-user","4":"post-4675","6":"format-standard","7":"category-blog","8":"category-webdriver"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.12 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Capturing API Performance Data from Firefox or Chrome during Webdriver Test - RedLine13<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Capturing API Performance Data from Firefox or Chrome during Webdriver Test - RedLine13\" \/>\n<meta property=\"og:description\" content=\"In support of running selenium webdriver tests at scale, we built a simple wrapper for webdriver. The wrapper is\u00a0open source and easy to run on a single machine, while RedLine13 can run it on 1,000 machines. Initial support for performance metrics: Collecting real-time metrics by running via PhantomJS. We injected javascript into PhantomJS to listen to onResourceRequested and onResourceReceived.\u00a0 We could also track errors and timeouts.\u00a0 You can see here how we tracked and summarized thisRead More &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/\" \/>\n<meta property=\"og:site_name\" content=\"RedLine13\" \/>\n<meta property=\"article:published_time\" content=\"2018-03-09T14:57:02+00:00\" \/>\n<meta name=\"author\" content=\"RedLine13\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"RedLine13\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/\"},\"author\":{\"name\":\"RedLine13\",\"@id\":\"https:\/\/www.redline13.com\/blog\/#\/schema\/person\/4acbcdcb8a9c72ec5a274e69c0ebea28\"},\"headline\":\"Capturing API Performance Data from Firefox or Chrome during Webdriver Test\",\"datePublished\":\"2018-03-09T14:57:02+00:00\",\"dateModified\":\"2018-03-09T14:57:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/\"},\"wordCount\":453,\"publisher\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/#organization\"},\"articleSection\":[\"Blog\",\"webdriver\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/\",\"url\":\"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/\",\"name\":\"Capturing API Performance Data from Firefox or Chrome during Webdriver Test - RedLine13\",\"isPartOf\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/#website\"},\"datePublished\":\"2018-03-09T14:57:02+00:00\",\"dateModified\":\"2018-03-09T14:57:02+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.redline13.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Capturing API Performance Data from Firefox or Chrome during Webdriver Test\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.redline13.com\/blog\/#website\",\"url\":\"https:\/\/www.redline13.com\/blog\/\",\"name\":\"RedLine13\",\"description\":\"(Almost) Free Load Testing in the Cloud\",\"publisher\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.redline13.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.redline13.com\/blog\/#organization\",\"name\":\"RedLine13\",\"url\":\"https:\/\/www.redline13.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.redline13.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/06\/cropped-rl13-header-logo.jpg\",\"contentUrl\":\"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/06\/cropped-rl13-header-logo.jpg\",\"width\":300,\"height\":68,\"caption\":\"RedLine13\"},\"image\":{\"@id\":\"https:\/\/www.redline13.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.redline13.com\/blog\/#\/schema\/person\/4acbcdcb8a9c72ec5a274e69c0ebea28\",\"name\":\"RedLine13\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.redline13.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514?s=96&d=mm&r=g\",\"caption\":\"RedLine13\"},\"sameAs\":[\"http:\/\/127.0.0.1\"],\"url\":\"https:\/\/www.redline13.com\/blog\/author\/user\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Capturing API Performance Data from Firefox or Chrome during Webdriver Test - RedLine13","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/","og_locale":"en_US","og_type":"article","og_title":"Capturing API Performance Data from Firefox or Chrome during Webdriver Test - RedLine13","og_description":"In support of running selenium webdriver tests at scale, we built a simple wrapper for webdriver. The wrapper is\u00a0open source and easy to run on a single machine, while RedLine13 can run it on 1,000 machines. Initial support for performance metrics: Collecting real-time metrics by running via PhantomJS. We injected javascript into PhantomJS to listen to onResourceRequested and onResourceReceived.\u00a0 We could also track errors and timeouts.\u00a0 You can see here how we tracked and summarized thisRead More &rarr;","og_url":"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/","og_site_name":"RedLine13","article_published_time":"2018-03-09T14:57:02+00:00","author":"RedLine13","twitter_card":"summary_large_image","twitter_misc":{"Written by":"RedLine13","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/#article","isPartOf":{"@id":"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/"},"author":{"name":"RedLine13","@id":"https:\/\/www.redline13.com\/blog\/#\/schema\/person\/4acbcdcb8a9c72ec5a274e69c0ebea28"},"headline":"Capturing API Performance Data from Firefox or Chrome during Webdriver Test","datePublished":"2018-03-09T14:57:02+00:00","dateModified":"2018-03-09T14:57:02+00:00","mainEntityOfPage":{"@id":"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/"},"wordCount":453,"publisher":{"@id":"https:\/\/www.redline13.com\/blog\/#organization"},"articleSection":["Blog","webdriver"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/","url":"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/","name":"Capturing API Performance Data from Firefox or Chrome during Webdriver Test - RedLine13","isPartOf":{"@id":"https:\/\/www.redline13.com\/blog\/#website"},"datePublished":"2018-03-09T14:57:02+00:00","dateModified":"2018-03-09T14:57:02+00:00","breadcrumb":{"@id":"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.redline13.com\/blog\/2018\/03\/capturing-api-performance-data-firefox-chrome-webdriver-test\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.redline13.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Capturing API Performance Data from Firefox or Chrome during Webdriver Test"}]},{"@type":"WebSite","@id":"https:\/\/www.redline13.com\/blog\/#website","url":"https:\/\/www.redline13.com\/blog\/","name":"RedLine13","description":"(Almost) Free Load Testing in the Cloud","publisher":{"@id":"https:\/\/www.redline13.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.redline13.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.redline13.com\/blog\/#organization","name":"RedLine13","url":"https:\/\/www.redline13.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.redline13.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/06\/cropped-rl13-header-logo.jpg","contentUrl":"https:\/\/www.redline13.com\/blog\/wp-content\/uploads\/2013\/06\/cropped-rl13-header-logo.jpg","width":300,"height":68,"caption":"RedLine13"},"image":{"@id":"https:\/\/www.redline13.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.redline13.com\/blog\/#\/schema\/person\/4acbcdcb8a9c72ec5a274e69c0ebea28","name":"RedLine13","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.redline13.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514?s=96&d=mm&r=g","caption":"RedLine13"},"sameAs":["http:\/\/127.0.0.1"],"url":"https:\/\/www.redline13.com\/blog\/author\/user\/"}]}},"_links":{"self":[{"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/posts\/4675","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/comments?post=4675"}],"version-history":[{"count":0,"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/posts\/4675\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/media?parent=4675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/categories?post=4675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.redline13.com\/blog\/wp-json\/wp\/v2\/tags?post=4675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}