Page tree
Skip to end of metadata
Go to start of metadata

Important: This feature is available only for limited release, to add support for the feature contact support.

 

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:

  1. How long it takes to fetch DNS information.
  2. How long each object takes to be requested.
  3. How long it takes to connect to the server.
  4. 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 of the different elements displayed and the interactions of each UI element.

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:

  1. Select the device to install the mitm certificate on.
    The certificate must be installed on the device used later for the HAR file generation.
  2. Running a short Perfecto Automation script (see below).
    The script browses to the certificate installation wizard.
  3. Suspending the Automation script,
  4. Use Interactive mode to follow the certificate installation wizard.
  5. Complete the Automation script.

Perfecto Automation Script

Network virtualization start(generateHarFile: true)
Wait(Wait duration: 2)
Browser go to(URL: http://mitm.it)
Wait(Wait duration:180)
<< during this three minute suspension follow the Wizard instructions, see below >>
Network virtualization stop

Selenium Automation Script

{...
	Map<String, Object> params = new HashMap<>
    params.put("generateHarFile", "true");
    // Start the network virtualization
    driver.executeScript("mobile:vnetwork:start", params);
    // browse to the mitm site
    driver.get("http://mitm.it");

	Thread.sleep(18000);  //three minute suspension, perform Wizard installation in manual mode, see below

	//End the network virtualization
	params.clear();
	driver.executeScript("mobile:vnetwork:stop", params);
...
}

Wizard Installation

During the Wait period, after the device browser navigates to the mitm.it site, perform the following steps in Interactive mode:

  1. 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.
  2. The wizard displays information on the proxy trust status - Click Install (upper right)
  3. Wizard displays a warning message regarding the Trust status of the installation, Click Install
  4. When installation completes, the Wizard displays the updated Certificate status of the proxy, Click Done
  5. 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.

  1. After installing the Proxy with the Wizard (as detailed above), Open the Settings application.
  2. Click on General > About
  3. Click Certificate Trust Settings

  4. Set the trust setting for mitmproxy to True (selected). The system displays a warning message:
  5. Click Continue, Proxy is now trusted.

Android Certificate Manual Install

To install the certificate on an Android device - perform the Automation script, and navigate to the mitm.it site and select Android.:

  1. 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)
  2. The installation will prompt for a Certificate Name - supply any name (for example "mitm") and click OK.
  3. 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
  4. Click OK on the message and the system will present different options for the unlock credentials

    Note: If the device you are working with supports fingerprint identification, the system will present options that include use of Android Imprint. Select the option to not use Imprint.


  5. Select PIN option, and the system prompts to enter a new four-digit PIN code. Click CONTINUE.
  6. Confirm the PIN on the next screen, Click OK.
  7. The certificate is automatically installed.
Recommendation: When you are finished recording the HAR file disable the Screen Unlock PIN code - use Settings→Security→Screen Lock, and select None

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.

    	Map<String, Object> params = new HashMap<>
    	params.put("generateHarFile", "true");
    	// Start the network virtualization
    	driver.executeScript("mobile:vnetwork:start", params);
    
    	// Add your script code here
    
    	//End the network virutalization
    	params.clear();
    	driver.executeScript("mobile:vnetwork:stop", params);


  • 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.

Known Limitations

  •  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.