Last updated: Jul 02, 2019 12:02
What is a HAR file
HTTP Archive (HAR) file is a JSON-formatted archive file format for logging an application’s (either browser or a native/hybrid app) interaction with HTTP servers. The HAR file format is an evolving standard and the information contained within it is both flexible and extensible. You can expect a HAR file to include a breakdown of timings including:
- How long it takes to fetch DNS information.
- How long each object takes to be requested.
- How long it takes to connect to the server.
- How long it takes to transfer assets from the server to the browser of each object.
In addition to the timing information, the HAR file may include details regarding any HTTP events generated during the script execution.
Perfecto provides support to generate a HAR file from an automation-script run, by activating the Network Virtualization functionality of the Perfecto CQ Lab. The HAR file will be included in the Reporting artifacts for the automation report.
Installing the Certificate
When generating the HAR file, Perfecto uses a proxy to capture the information and generate the HAR entries. Use of the proxy requires that a mitm certificate is installed on the Perfecto Lab device.
Installing the certificate involves:
- Select the device to install the mitm certificate on.
The certificate must be installed on the device used later for the HAR file generation.
- Running a short Perfecto Automation script (see below).
The script browses to the certificate installation wizard.
- Suspending the Automation script,
- Use Interactive mode to follow the certificate installation wizard.
- Complete the Automation script.
Perfecto Automation Script
Selenium Automation Script
During the Wait period, after the device browser navigates to the mitm.it site, perform the following steps in Interactive mode:
- Select the OS of the device as the proxy version to install:
For Android devices continue with Android installation.
For iOS devices continue with the following steps.
- The wizard displays information on the proxy trust status - Click Install (upper right)
- Wizard displays a warning message regarding the Trust status of the installation, Click Install
- When installation completes, the Wizard displays the updated Certificate status of the proxy, Click Done
- For Apple devices running iOS 10.3 or later continue with the Trust Proxy procedure. Other devices are ready to run.
Trusting the MITM Proxy
On iOS devices, you may need to verify that the system Trusts the installed proxy.
- After installing the Proxy with the Wizard (as detailed above), Open the Settings application.
- Click on General > About
- Click Certificate Trust Settings
- Set the trust setting for mitmproxy to True (selected). The system displays a warning message:
- Click Continue, Proxy is now trusted.
Android Certificate Manual Install
- Open the downloaded file, by either clicking on the Open when filename is displayed at the bottom of the browser, or by opening the Downloads window of the browser (from the browser options menu)
- The installation will prompt for a Certificate Name - supply any name (for example "mitm") and click OK.
- Android may require that you setup an unlock credential PIN for the device -
if you receive the following message continue to the next step.
If you do not continue to Step #9
Click OK on the message and the system will present different options for the unlock credentials
- Select PIN option, and the system prompts to enter a new four-digit PIN code. Click CONTINUE.
- Confirm the PIN on the next screen, Click OK.
- The certificate is automatically installed.
Activating the Network Virtualization
- Use the Network virtualization start command in your automation script, setting the generateHarFile parameter to True.
In Native Automation use the command from the Services/Network Virtualization folder in the Functions tab.
For Selenium/Appium scripts use the mobile:vnetwork:start command in the driver.executeScript() method.
- Include whatever network navigation steps needed in your automation script.
- Add the Network virtualization stop command at the end of your script.
- Run the script.
Retrieving the HAR file
After completing the automation script, open the Single Test Report for the execution. In the upper right corner of the STR View, open the Retrieve artifacts menu and select the Download network files option.
Save the files to a known location and view the .har file with an appropriate viewer, either a browser developer tool (Chrome, Firefox tools) or an external tool like Charles (used in the example below). Import the har file and examine the timing information, request/response content, etc.
- When using this feature together with Network Virtualization Profiles - the HAR file will not reflect the traffic on the virtual network, only the traffic to the actual Internet is included in the HAR file.