SlideShare a Scribd company logo
Performance Metrics In A DayShane HenderMark Watson
AgendaGoal is to show how you can enhance your automation tests to gather performance metricsKeep the short presentation as practical as possible with enough code snippets to give you a starting point
One more thing…HTTP Archive (HAR)What?UTF8 Text based JSON encoding to represent performance dataWhy?Many libraries to convert from JSON to objectsMore tools allowing import/export/view HARBecoming the standard format
Snippet of HAR format{"log": {"version": "1.1",     "creator": {       "name": "Firebug",       "version": "1.7.0"     },     "browser": {       "name": "Firefox",       "version": "4.0"     },     "pages": [       {         "startedDateTime": "2011-03-31T16:56:50.455-07:00",         "id": "page_62901",         "title": "Google",         "pageTimings": {           "onContentLoad": 431,           "onLoad": 3148         }       }     ],"entries": [       {         "pageref": "page_62901",         "startedDateTime": "2011-03-31T16:56:50.455-07:00",         "time": 250,         "request": {           "method": "GET",           "url": "http://www.google.com/",           "httpVersion": "HTTP/1.1",           "cookies": [             {               "name": "PREF",               "value": "ID"             },
HAR Viewershttp://www.softwareishard.com/har/viewer/Fiddler UI can import HAR filesShowSlowwebapp can be used to archive and view HAR files
Which Metrics?Overall page load timeDOM loading/interactive/complete, browser 1st render, …Per-item timingsDNS, SSL connect, time to first byte, total time to download bytes, …Headers, status codes, and contentFor a more detailed picture of the reasons for the page performanceCan help with debugging performance, e.g. were items compressed, or not being loaded dynamically, or certain items not being prioritized for above-the-fold rendering
Methods for gathering metricsSetting your own timings in test codeUsing the new ‘Navigation.Timings’ or Web Timings standard built into browsers Using browser plugins that report back the timings to you, e.g. WebPageTestPer HTTP request logs via Selenium’s built-in proxy Routing the browser traffic through a local proxy and gathering the statistics from there.Network traffic capture
Method 1: Own TimingsWebDriver driver = newChromeDriver();Date start = new Date();driver.get("http://www.webmetrics.com");Date end = new Date();
Method 2: Web TimingsCurrently Chrome and IE9 supported, coming soon for Firefoxhttp://w3c-test.org/webperf/specs/NavigationTiming/WebDriver driver = newChromeDriver();// A "base url", used by selenium to resolve relative URLs StringbaseUrl = "http://www.webmetrics.com"; driver.get(baseUrl); JavascriptExecutorjs = (JavascriptExecutor)driver; LongloadEventEnd= (Long) js.executeScript("returnwindow.performance.timing.loadEventEnd");LongnavigationStart= (Long) js.executeScript("returnwindow.performance.timing.navigationStart");Long answerToAllProblems =loadEventEnd - navigationStart;
Method 2: Web TimingsCould also modify this by using your own JavaScript loaded into the page to set timingsAlso would work in combination with the already set Web TimingsE.g. Set a Date().getTime() variable when some dynamically loaded content is loaded into the DOMLongperceivedLoadTime = (Long) js.executeScript("returnelementInsertTime – window.performance.timing.navigationStart");
Unfortunately it doesn't give timings per item downloaded, e.g. images, css, js, ....
Method 3: Browser PluginsTypically can give compute time metricsJavascript execution timeCPU usageRender timesIE8 - WebPageTestCPU usageVideo captureFirefox - Firebug Net Panel + NetExporthttps://github.com/lightbody/browsermob-page-perfhttps://github.com/AutomatedTester/AutomatedTester.PagePerf.gitDynaTrace browser plugin (FireFox/IE on Windows)Good breakdown of stats (Javascript execution times, CSS times, render, 'first impression' time).http://ajax.dynatrace.com/ajax/en/Chrome – some export from the Developer Tools Network Panel?
FirefoxProfilep=newFirefoxProfile();try{p.addExtension(newFile("c:/firebug-1.6.0.xpi"));p.addExtension(newFile("c:/netExport-0.8b9.xpi"));p.addExtension(newFile("c:/firestarter-0.1.a5.xpi"));}catch(IOExceptione){thrownewRuntimeException(“Failed to load extensions:",e);}p.setPreference("extensions.firebug.netexport.autoExportActive",true);//p.setPreference("extensions.firebug.netexport.defaultLogDir", "c:/");p.setPreference("extensions.firebug.onByDefault",true);p.setPreference("extensions.firebug.defaultPanelName","net");p.setPreference("extensions.firebug.net.enableSites",true);p.setPreference("extensions.firebug.previousPlacement",1);driver=newFirefoxDriver(p);Method 3: Example - Firebug + NetExport
Method 4: Example - Firebug + NetExport
Method 4: Use a ProxyUse built in Selenium 1 proxyUse a 3rd party proxy library Many available, few capture metrics in a convenient wayTwo good ones:BrowserMob ProxyFiddler
Method 4: Selenium built-in ProxyUse API Selenium.captureNetworkTraffic()Selenium selenium = newDefaultSelenium("localhost", 4444,"*firefox", "http://www.webmetrics.com"); selenium.start("captureNetworkTraffic=true");selenium.open("http://www.webmetrics.com"); Stringjson = selenium.captureNetworkTraffic("json"); selenium.stop();
Method 4: Selenium built-in ProxyNot in HTTP Archive (HAR) format, but does report:HTTP status code, URL and HTTP methodRequest & response headersOverall request->response timingBytes downloadedWorks with Chrome and FirefoxDoesn’t work for WebDriver tests.Still work with Selenium 2 RC, but only if send jobs via Selenese API.Not much control over the proxy
Method 4: Advantages of using a ProxyTesting benefits beyond performance monitoringBlacklisting/whitelisting URLsComparing page load times of site with/without external contentNot hitting analytics/advertising contentSimulating external content being offlineURL rewritesRedirect production URLs back to staging/test environmentPretend to be production as far as the browser is concerned (e.g. for cookies)Make sure ad/metrics requests are being made
Method 4: Advantages of using a ProxyHeader changesSet the user agent manually to test different browser behaviorAuto authenticationWait until all content is downloadedHTTP idle for X secondsLimit bandwidth
Method 4: BrowserMob ProxyOpen source cross platform proxy written in Java.HTTP Archive supportFriendly APISource code available:https://github.com/lightbody/browsermob-proxy
Method 4: BrowserMob ProxyExport HAR Sampleimport org.browsermob.proxy.ProxyServer;ProxyServer proxy = new ProxyServer(9090);proxy.start();Proxy mobProxy = new Proxy().setHttpProxy("localhost:9090");DesiredCapabilities caps = new DesiredCapabilities();caps.setCapability("proxy", mobProxy);FirefoxDriver driver = new FirefoxDriver(caps);
Method 4: BrowserMob ProxyRun test, denoting pages in HARproxy.newHar("Yahoo");driver.get("http://yahoo.com");proxy.endPage();proxy.newPage("CNN");driver.get("http://cnn.com");proxy.endPage();
Method 4: BrowserMob ProxyWrite out HTTP Archive fileproxy.getHar().writeTo(newFile("test.har"));
Method 4: BrowserMob ProxyBlacklist/Whitelist URLsproxy.blacklistRequests(regex, responseCode)proxy.whitelistRequests(regex, responseCode)Redirecting URLsproxy.rewriteUrl(regex, replace)Limit Bandwidthproxy.setDownstreamKbps(kbps)proxy.setUpstreamKbps(kbps)
Method 4: BrowserMob ProxyWhen to useCross platformJavaCan set the browser proxy
Method 4: Proxy - FiddlerCoreFiddler is an application for viewing HTTP traffic on Windows.Works with Chrome, FireFox, Internet Explorer.Fiddler Application is built on FiddlerCore.NET libraryAllows extensive programmatic control over the proxyCaptures HTTP timingsAllows request/responses to be intercepted and modifiedConfigures itself as default Windows proxy (supports proxy chaining)Can decrypt SSL traffic
To start the proxy and register it as the default system wide proxy.Each HTTP transaction can then be recorded as follows:Method 4: Proxy - FiddlerCore// Initialize the proxyFiddler.FiddlerApplication.Startup(	8877, FiddlerCoreStartupFlags.Default);var items = new List<Fiddler.Session>(); Fiddler.FiddlerApplication.AfterSessionComplete +=     	delegate(Fiddler.SessionoS){items.Add(oS);};
Method 4: Proxy - FiddlerCoreRun Selenium test as normalAs each item is downloaded it will be added to the ’items’ var in previous slide.string baseUrl = "http://www.webmetrics.com";varwebDriver =newOpenQA.Selenium.Firefox.FirefoxDriver();var selenium = newSelenium.WebDriverBackedSelenium		(webDriver, baseUrl);selenium.Start();selenium.Open(baseUrl);selenium.WaitForPageToLoad("30000");selenium.Stop();
Method 4: Proxy (Fiddler -> HAR)Using the HAR Exporter to convert the sessions to HARAdd FiddlerCore-BasicFormats.dll to the project references and load the assembly:https://www.fiddler2.com/dl/FiddlerCore-BasicFormats.zipString exePath = Assembly.GetExecutingAssembly().Location;String path = Path.Combine(Path.GetDirectoryName(exePath),   @"FiddlerCore-BasicFormats.dll");FiddlerApplication.oTranscoders.ImportTranscoders(path);
Method 4: Proxy (Fiddler -> HAR)Finally, export the HAR to a file:varoExportOptions = new Dictionary<string, object>();string filename = @"output.har”;oExportOptions.Add("Filename", filename);Fiddler.FiddlerApplication.DoExport("HTTPArchive v1.2", sessions, oExportOptions, null);
Method 4: Proxy Bonus FeaturesModifying HTTP requestsFiddler.FiddlerApplication.BeforeRequest +=delegate(Fiddler.SessionoS){// Ignore requests made to the main site.RegexmatchUrl = newRegex("webmetrics\\.com”);if (matchUrl.IsMatch(oS.fullUrl))	{oS.utilCreateResponseAndBypassServer();oS.responseCode = 200;	}};In the same way responses from the server can be modifiedFiddler.FiddlerApplication.BeforeResponse
Method 4: Proxy – FiddlerCoreWhen to useWindows OnlyCross browser.NET
Method 5: Wire HTTP captureCaptured network traffic can be converted to HAROn Unix/OSX use tcpdumptcpdump -i en0 -n -s 0 -wtraffic.pcapOn Windows use WinPCapwinpcap -i 0 -n -s 0 -wtraffic.pcapThen use pcap2har to do the conversion:main.pytraffic.pcap http-requests.harPcap2harhttps://github.com/andrewf/pcap2har
Method 5: Wire HTTP captureCaptures allHTTP trafficTimings based on actual network trafficNo interference from proxyNo extra network delays/context switches talking to the proxyBrowsers sometimes behave differently when talking to a proxy
SummaryDiscussed 5 methods for recording performance metricsUse timers around selenium commandsUse WebTimings JavaScript APIFirebug & NetExportProxyUse the built-in Selenium proxyUse a 3rd party proxySniff network traffic
LinksBrowserMob proxyhttps://github.com/lightbody/browsermob-proxyFiddler Cookbookhttp://www.fiddler2.com/fiddler/dev/ScriptSamples.aspExamples from this talkhttps://github.com/watsonmw/selenium-pageloadmetrics

More Related Content

PPTX
Your hash is.
abend_cve_9999_0001
 
PDF
Network Interception - Write Swift codes to inspect network requests (even wi...
Kenneth Poon
 
PPTX
The Travelling Pentester: Diaries of the Shortest Path to Compromise
Will Schroeder
 
PDF
Hunting Lateral Movement in Windows Infrastructure
Sergey Soldatov
 
PDF
Database Firewall with Snort
Narudom Roongsiriwong, CISSP
 
PDF
[表示が崩れる場合ダウンロードしてご覧ください] 2018年のDocker・Moby
Akihiro Suda
 
PDF
DevOps - CI/CD 알아보기
SeungYong Baek
 
PPTX
Kheirkhabarov24052017_phdays7
Teymur Kheirkhabarov
 
Your hash is.
abend_cve_9999_0001
 
Network Interception - Write Swift codes to inspect network requests (even wi...
Kenneth Poon
 
The Travelling Pentester: Diaries of the Shortest Path to Compromise
Will Schroeder
 
Hunting Lateral Movement in Windows Infrastructure
Sergey Soldatov
 
Database Firewall with Snort
Narudom Roongsiriwong, CISSP
 
[表示が崩れる場合ダウンロードしてご覧ください] 2018年のDocker・Moby
Akihiro Suda
 
DevOps - CI/CD 알아보기
SeungYong Baek
 
Kheirkhabarov24052017_phdays7
Teymur Kheirkhabarov
 

What's hot (20)

PPTX
Damn Vulnerable Chemical Process
Positive Hack Days
 
PDF
What are latest new features that DPDK brings into 2018?
Michelle Holley
 
PDF
ClickHouse Mark Cache, by Mik Kocikowski, Cloudflare
Altinity Ltd
 
PDF
Nutanix Acropolis File Services ( AFS ) を「一足先に」試してみる
milk hanakara
 
PPTX
Dataplane programming with eBPF: architecture and tools
Stefano Salsano
 
PDF
Ansible
DaeMyung Kang
 
POTX
Performance Tuning EC2 Instances
Brendan Gregg
 
PDF
Docker 기반 개발환경 구축 - XE Open seminar #2
XpressEngine
 
PDF
GPU Virtualization in SUSE
Liang Yan
 
PDF
Webinar - A Developer's Quick Start Guide to Open Source Process Automation U...
camunda services GmbH
 
PPT
Hacking tutorial
MSA Technosoft
 
PPTX
Abusing Microsoft Kerberos - Sorry you guys don't get it
Benjamin Delpy
 
PPTX
2014 OpenStack Summit - Neutron OVS to LinuxBridge Migration
James Denton
 
PDF
A Threat Hunter Himself
Teymur Kheirkhabarov
 
PPT
Top 10 Web Security Vulnerabilities (OWASP Top 10)
Brian Huff
 
PDF
PHDays 2018 Threat Hunting Hands-On Lab
Teymur Kheirkhabarov
 
PDF
Nightmare with ceph : Recovery from ceph cluster total failure
Andrew Yongjoon Kong
 
PDF
Temel Kavramlar, DoS/DDoS Saldırıları ve Çeşitleri
BGA Cyber Security
 
PDF
10 Adımda Sızma Testleri
BGA Cyber Security
 
Damn Vulnerable Chemical Process
Positive Hack Days
 
What are latest new features that DPDK brings into 2018?
Michelle Holley
 
ClickHouse Mark Cache, by Mik Kocikowski, Cloudflare
Altinity Ltd
 
Nutanix Acropolis File Services ( AFS ) を「一足先に」試してみる
milk hanakara
 
Dataplane programming with eBPF: architecture and tools
Stefano Salsano
 
Ansible
DaeMyung Kang
 
Performance Tuning EC2 Instances
Brendan Gregg
 
Docker 기반 개발환경 구축 - XE Open seminar #2
XpressEngine
 
GPU Virtualization in SUSE
Liang Yan
 
Webinar - A Developer's Quick Start Guide to Open Source Process Automation U...
camunda services GmbH
 
Hacking tutorial
MSA Technosoft
 
Abusing Microsoft Kerberos - Sorry you guys don't get it
Benjamin Delpy
 
2014 OpenStack Summit - Neutron OVS to LinuxBridge Migration
James Denton
 
A Threat Hunter Himself
Teymur Kheirkhabarov
 
Top 10 Web Security Vulnerabilities (OWASP Top 10)
Brian Huff
 
PHDays 2018 Threat Hunting Hands-On Lab
Teymur Kheirkhabarov
 
Nightmare with ceph : Recovery from ceph cluster total failure
Andrew Yongjoon Kong
 
Temel Kavramlar, DoS/DDoS Saldırıları ve Çeşitleri
BGA Cyber Security
 
10 Adımda Sızma Testleri
BGA Cyber Security
 
Ad

Similar to Performance Metrics in a Day with Selenium (20)

PDF
Web Standards Support in WebKit
Joone Hur
 
PPTX
Compatibility Detector Tool of Chrome extensions
Kai Cui
 
PDF
Using HttpWatch Plug-in with Selenium Automation in Java
Sandeep Tol
 
PPT
Internet Explorer 8 for Developers by Christian Thilmany
Christian Thilmany
 
PPTX
High-Speed HTML5
Peter Lubbers
 
ODP
Implementing Comet using PHP
King Foo
 
PPTX
Selenium Automation in Java Using HttpWatch Plug-in
Sandeep Tol
 
PPT
Even Faster Web Sites at jQuery Conference '09
Steve Souders
 
PPTX
hacking with node.JS
Harsha Vashisht
 
PPT
Sanjeev ghai 12
Praveen kumar
 
PPTX
03 integrate webapisignalr
Erhwen Kuo
 
PPTX
Spicy javascript: Create your first Chrome extension for web analytics QA
Alban Gérôme
 
PPTX
Accelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
Todd Anglin
 
PPTX
Chanhao Jiang And David Wei Presentation Quickling Pagecache
Ajax Experience 2009
 
PPT
Ajax to the Moon
davejohnson
 
PPTX
Google I/O 2012 - Protecting your user experience while integrating 3rd party...
Patrick Meenan
 
PPT
Html5 drupal7 with mandakini kumari(1)
Mandakini Kumari
 
PDF
5.node js
Geunhyung Kim
 
ODP
Basic testing with selenium
Søren Lund
 
PPT
Google Gears
silenceIT Inc.
 
Web Standards Support in WebKit
Joone Hur
 
Compatibility Detector Tool of Chrome extensions
Kai Cui
 
Using HttpWatch Plug-in with Selenium Automation in Java
Sandeep Tol
 
Internet Explorer 8 for Developers by Christian Thilmany
Christian Thilmany
 
High-Speed HTML5
Peter Lubbers
 
Implementing Comet using PHP
King Foo
 
Selenium Automation in Java Using HttpWatch Plug-in
Sandeep Tol
 
Even Faster Web Sites at jQuery Conference '09
Steve Souders
 
hacking with node.JS
Harsha Vashisht
 
Sanjeev ghai 12
Praveen kumar
 
03 integrate webapisignalr
Erhwen Kuo
 
Spicy javascript: Create your first Chrome extension for web analytics QA
Alban Gérôme
 
Accelerated Adoption: HTML5 and CSS3 for ASP.NET Developers
Todd Anglin
 
Chanhao Jiang And David Wei Presentation Quickling Pagecache
Ajax Experience 2009
 
Ajax to the Moon
davejohnson
 
Google I/O 2012 - Protecting your user experience while integrating 3rd party...
Patrick Meenan
 
Html5 drupal7 with mandakini kumari(1)
Mandakini Kumari
 
5.node js
Geunhyung Kim
 
Basic testing with selenium
Søren Lund
 
Google Gears
silenceIT Inc.
 
Ad

Recently uploaded (20)

PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Doc9.....................................
SofiaCollazos
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Software Development Methodologies in 2025
KodekX
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
This slide provides an overview Technology
mineshkharadi333
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Doc9.....................................
SofiaCollazos
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
Coupa-Overview _Assumptions presentation
annapureddyn
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Software Development Methodologies in 2025
KodekX
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 

Performance Metrics in a Day with Selenium

  • 1. Performance Metrics In A DayShane HenderMark Watson
  • 2. AgendaGoal is to show how you can enhance your automation tests to gather performance metricsKeep the short presentation as practical as possible with enough code snippets to give you a starting point
  • 3. One more thing…HTTP Archive (HAR)What?UTF8 Text based JSON encoding to represent performance dataWhy?Many libraries to convert from JSON to objectsMore tools allowing import/export/view HARBecoming the standard format
  • 4. Snippet of HAR format{"log": {"version": "1.1", "creator": { "name": "Firebug", "version": "1.7.0" }, "browser": { "name": "Firefox", "version": "4.0" }, "pages": [ { "startedDateTime": "2011-03-31T16:56:50.455-07:00", "id": "page_62901", "title": "Google", "pageTimings": { "onContentLoad": 431, "onLoad": 3148 } } ],"entries": [ { "pageref": "page_62901", "startedDateTime": "2011-03-31T16:56:50.455-07:00", "time": 250, "request": { "method": "GET", "url": "http://www.google.com/", "httpVersion": "HTTP/1.1", "cookies": [ { "name": "PREF", "value": "ID" },
  • 5. HAR Viewershttp://www.softwareishard.com/har/viewer/Fiddler UI can import HAR filesShowSlowwebapp can be used to archive and view HAR files
  • 6. Which Metrics?Overall page load timeDOM loading/interactive/complete, browser 1st render, …Per-item timingsDNS, SSL connect, time to first byte, total time to download bytes, …Headers, status codes, and contentFor a more detailed picture of the reasons for the page performanceCan help with debugging performance, e.g. were items compressed, or not being loaded dynamically, or certain items not being prioritized for above-the-fold rendering
  • 7. Methods for gathering metricsSetting your own timings in test codeUsing the new ‘Navigation.Timings’ or Web Timings standard built into browsers Using browser plugins that report back the timings to you, e.g. WebPageTestPer HTTP request logs via Selenium’s built-in proxy Routing the browser traffic through a local proxy and gathering the statistics from there.Network traffic capture
  • 8. Method 1: Own TimingsWebDriver driver = newChromeDriver();Date start = new Date();driver.get("http://www.webmetrics.com");Date end = new Date();
  • 9. Method 2: Web TimingsCurrently Chrome and IE9 supported, coming soon for Firefoxhttp://w3c-test.org/webperf/specs/NavigationTiming/WebDriver driver = newChromeDriver();// A "base url", used by selenium to resolve relative URLs StringbaseUrl = "http://www.webmetrics.com"; driver.get(baseUrl); JavascriptExecutorjs = (JavascriptExecutor)driver; LongloadEventEnd= (Long) js.executeScript("returnwindow.performance.timing.loadEventEnd");LongnavigationStart= (Long) js.executeScript("returnwindow.performance.timing.navigationStart");Long answerToAllProblems =loadEventEnd - navigationStart;
  • 10. Method 2: Web TimingsCould also modify this by using your own JavaScript loaded into the page to set timingsAlso would work in combination with the already set Web TimingsE.g. Set a Date().getTime() variable when some dynamically loaded content is loaded into the DOMLongperceivedLoadTime = (Long) js.executeScript("returnelementInsertTime – window.performance.timing.navigationStart");
  • 11. Unfortunately it doesn't give timings per item downloaded, e.g. images, css, js, ....
  • 12. Method 3: Browser PluginsTypically can give compute time metricsJavascript execution timeCPU usageRender timesIE8 - WebPageTestCPU usageVideo captureFirefox - Firebug Net Panel + NetExporthttps://github.com/lightbody/browsermob-page-perfhttps://github.com/AutomatedTester/AutomatedTester.PagePerf.gitDynaTrace browser plugin (FireFox/IE on Windows)Good breakdown of stats (Javascript execution times, CSS times, render, 'first impression' time).http://ajax.dynatrace.com/ajax/en/Chrome – some export from the Developer Tools Network Panel?
  • 13. FirefoxProfilep=newFirefoxProfile();try{p.addExtension(newFile("c:/firebug-1.6.0.xpi"));p.addExtension(newFile("c:/netExport-0.8b9.xpi"));p.addExtension(newFile("c:/firestarter-0.1.a5.xpi"));}catch(IOExceptione){thrownewRuntimeException(“Failed to load extensions:",e);}p.setPreference("extensions.firebug.netexport.autoExportActive",true);//p.setPreference("extensions.firebug.netexport.defaultLogDir", "c:/");p.setPreference("extensions.firebug.onByDefault",true);p.setPreference("extensions.firebug.defaultPanelName","net");p.setPreference("extensions.firebug.net.enableSites",true);p.setPreference("extensions.firebug.previousPlacement",1);driver=newFirefoxDriver(p);Method 3: Example - Firebug + NetExport
  • 14. Method 4: Example - Firebug + NetExport
  • 15. Method 4: Use a ProxyUse built in Selenium 1 proxyUse a 3rd party proxy library Many available, few capture metrics in a convenient wayTwo good ones:BrowserMob ProxyFiddler
  • 16. Method 4: Selenium built-in ProxyUse API Selenium.captureNetworkTraffic()Selenium selenium = newDefaultSelenium("localhost", 4444,"*firefox", "http://www.webmetrics.com"); selenium.start("captureNetworkTraffic=true");selenium.open("http://www.webmetrics.com"); Stringjson = selenium.captureNetworkTraffic("json"); selenium.stop();
  • 17. Method 4: Selenium built-in ProxyNot in HTTP Archive (HAR) format, but does report:HTTP status code, URL and HTTP methodRequest & response headersOverall request->response timingBytes downloadedWorks with Chrome and FirefoxDoesn’t work for WebDriver tests.Still work with Selenium 2 RC, but only if send jobs via Selenese API.Not much control over the proxy
  • 18. Method 4: Advantages of using a ProxyTesting benefits beyond performance monitoringBlacklisting/whitelisting URLsComparing page load times of site with/without external contentNot hitting analytics/advertising contentSimulating external content being offlineURL rewritesRedirect production URLs back to staging/test environmentPretend to be production as far as the browser is concerned (e.g. for cookies)Make sure ad/metrics requests are being made
  • 19. Method 4: Advantages of using a ProxyHeader changesSet the user agent manually to test different browser behaviorAuto authenticationWait until all content is downloadedHTTP idle for X secondsLimit bandwidth
  • 20. Method 4: BrowserMob ProxyOpen source cross platform proxy written in Java.HTTP Archive supportFriendly APISource code available:https://github.com/lightbody/browsermob-proxy
  • 21. Method 4: BrowserMob ProxyExport HAR Sampleimport org.browsermob.proxy.ProxyServer;ProxyServer proxy = new ProxyServer(9090);proxy.start();Proxy mobProxy = new Proxy().setHttpProxy("localhost:9090");DesiredCapabilities caps = new DesiredCapabilities();caps.setCapability("proxy", mobProxy);FirefoxDriver driver = new FirefoxDriver(caps);
  • 22. Method 4: BrowserMob ProxyRun test, denoting pages in HARproxy.newHar("Yahoo");driver.get("http://yahoo.com");proxy.endPage();proxy.newPage("CNN");driver.get("http://cnn.com");proxy.endPage();
  • 23. Method 4: BrowserMob ProxyWrite out HTTP Archive fileproxy.getHar().writeTo(newFile("test.har"));
  • 24. Method 4: BrowserMob ProxyBlacklist/Whitelist URLsproxy.blacklistRequests(regex, responseCode)proxy.whitelistRequests(regex, responseCode)Redirecting URLsproxy.rewriteUrl(regex, replace)Limit Bandwidthproxy.setDownstreamKbps(kbps)proxy.setUpstreamKbps(kbps)
  • 25. Method 4: BrowserMob ProxyWhen to useCross platformJavaCan set the browser proxy
  • 26. Method 4: Proxy - FiddlerCoreFiddler is an application for viewing HTTP traffic on Windows.Works with Chrome, FireFox, Internet Explorer.Fiddler Application is built on FiddlerCore.NET libraryAllows extensive programmatic control over the proxyCaptures HTTP timingsAllows request/responses to be intercepted and modifiedConfigures itself as default Windows proxy (supports proxy chaining)Can decrypt SSL traffic
  • 27. To start the proxy and register it as the default system wide proxy.Each HTTP transaction can then be recorded as follows:Method 4: Proxy - FiddlerCore// Initialize the proxyFiddler.FiddlerApplication.Startup( 8877, FiddlerCoreStartupFlags.Default);var items = new List<Fiddler.Session>(); Fiddler.FiddlerApplication.AfterSessionComplete += delegate(Fiddler.SessionoS){items.Add(oS);};
  • 28. Method 4: Proxy - FiddlerCoreRun Selenium test as normalAs each item is downloaded it will be added to the ’items’ var in previous slide.string baseUrl = "http://www.webmetrics.com";varwebDriver =newOpenQA.Selenium.Firefox.FirefoxDriver();var selenium = newSelenium.WebDriverBackedSelenium (webDriver, baseUrl);selenium.Start();selenium.Open(baseUrl);selenium.WaitForPageToLoad("30000");selenium.Stop();
  • 29. Method 4: Proxy (Fiddler -> HAR)Using the HAR Exporter to convert the sessions to HARAdd FiddlerCore-BasicFormats.dll to the project references and load the assembly:https://www.fiddler2.com/dl/FiddlerCore-BasicFormats.zipString exePath = Assembly.GetExecutingAssembly().Location;String path = Path.Combine(Path.GetDirectoryName(exePath), @"FiddlerCore-BasicFormats.dll");FiddlerApplication.oTranscoders.ImportTranscoders(path);
  • 30. Method 4: Proxy (Fiddler -> HAR)Finally, export the HAR to a file:varoExportOptions = new Dictionary<string, object>();string filename = @"output.har”;oExportOptions.Add("Filename", filename);Fiddler.FiddlerApplication.DoExport("HTTPArchive v1.2", sessions, oExportOptions, null);
  • 31. Method 4: Proxy Bonus FeaturesModifying HTTP requestsFiddler.FiddlerApplication.BeforeRequest +=delegate(Fiddler.SessionoS){// Ignore requests made to the main site.RegexmatchUrl = newRegex("webmetrics\\.com”);if (matchUrl.IsMatch(oS.fullUrl)) {oS.utilCreateResponseAndBypassServer();oS.responseCode = 200; }};In the same way responses from the server can be modifiedFiddler.FiddlerApplication.BeforeResponse
  • 32. Method 4: Proxy – FiddlerCoreWhen to useWindows OnlyCross browser.NET
  • 33. Method 5: Wire HTTP captureCaptured network traffic can be converted to HAROn Unix/OSX use tcpdumptcpdump -i en0 -n -s 0 -wtraffic.pcapOn Windows use WinPCapwinpcap -i 0 -n -s 0 -wtraffic.pcapThen use pcap2har to do the conversion:main.pytraffic.pcap http-requests.harPcap2harhttps://github.com/andrewf/pcap2har
  • 34. Method 5: Wire HTTP captureCaptures allHTTP trafficTimings based on actual network trafficNo interference from proxyNo extra network delays/context switches talking to the proxyBrowsers sometimes behave differently when talking to a proxy
  • 35. SummaryDiscussed 5 methods for recording performance metricsUse timers around selenium commandsUse WebTimings JavaScript APIFirebug & NetExportProxyUse the built-in Selenium proxyUse a 3rd party proxySniff network traffic

Editor's Notes

  • #2: Welcome to our talk about getting performance metrics in a day
  • #3: Outline the talk, what is the takeawayRun your standard unit tests (Junit, minitest, ….) but put in performance testing as well
  • #4: Becoming the standard mechanism to store/dump performance data
  • #7: Lots of text on this slide, we’ll keep it more entetaining laterOverall page load time= The obvious starting point and usually the easiest to acquire
  • #8: Setting your own timings – obvious, but is not always very accurate if you are in a sequence of steps and capture page transitions and other delays Very coarse, incorporates latency/setup/teardown delays in the times reported, e.g. it sometimes takes a second or 2 for an IE window to become responsiveWeb Timings == Very simple at the moment, but gives very accurate overall stats, like initial connection time, DOM ready, and total request-&gt;response times.Browser plugins == Accurate picture of what the browser is doing, but not so straightforward to incorporate into your code.Proxy == Gives you very good timings for http traffic but can’t give you timings like render time or DOM ready events.Network traffic capture tools like WinPCAP, or wireshark
  • #14: Doesn&apos;t seem to work currently in FF4Will have to parse the HAR format if you just want the basic timing out of it
  • #16: Going to go over:- How to grab metrics using a proxy How using a proxy can be beneficial for testing in general
  • #28: (Fiddler refers to thehttp transaction as &apos;sessions&apos;)
  • #33: Documentation spread out over blogs, fiddler google groups, and fiddler extensions pageAPI is little difficult