Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Build Status Codacy Badge

Transformer

A tool to transform/convert web browser sessions (HAR files) into Locust load testing scenarios (locustfile).

This tool can be used when you have HAR files (containing recordings of interactions with your website) that you then want to replay in load tests using Locust.

Installation

Install from PyPI with pip:

pip install har-transformer

Usage

Import in your code and use it:

from transformer import transform

with open("locustfile.py", "w") as locust_file:
  locust_file.write(transform.main("scenarios_directory/"))

Example HAR files are included in the examples directory for you to try out.

How-to

Create a HAR file

Using Chrome Developer Tools

Record

  1. Prepare your scenario by thinking through the steps you want to execute
  2. Open Chrome in either Guest or Incognito mode (it's important to have no cookies prior to starting)
  3. Open the Developer Tools
  4. Open the Network panel
  5. Select Disable cache and Preserve log
  6. Clear the existing log by clicking the Clear :no_entry_sign: button
  7. Ensure recording is enabled, the Record button should be red :red_circle: (click to toggle)
  8. Navigate to your target site by entering the URL in the address bar e.g. https://www.zalando.de, https://www.zalando.de/damen-home/, etc.
  9. Perform your scenario by clicking through the pages, filling in forms, clicking buttons etc.

N.B. It's recommend that after each click/action, and before the next one, you wait until the network panel stops showing activity. This is to ensure that all requests are properly recorded.

Save

Once you have finished performing your scenario:

  1. End recording by clicking the Record :red_circle: button
  2. Right-click on any of the file names listed in the bottom pane of the Network panel
  3. Select Save as HAR with content
  4. Save the file on your machine

ℹ️ You can view the details of the recorded HAR by simply drag-and-dropping it into the Chrome Developer Tools Network panel.

Scenario weights

By default, all scenarios have the same weight 1, which means they should all be executed as often as the others.

You can specify a different weight for each HAR file by creating an associated weight file. Weights must be positive, non-null integers due to how Locust works. Consider the following scenario group:

$ ls
scenario1.har
scenario2.har
scenario2.weight

$ cat scenario2.weight
3

Here are the weights Transformer will specify in the corresponding locustfile:

Scenario Weight
scenario1.har 1
scenario2.har 3

This means that Locust will run scenario2.har 3 times as much as scenario1.har.

Hierarchical scenarios

It may be the case that all your scenarios cannot be treated the same:

  • some only apply to a part of your load test target,
  • some should run more often than others.

For instance, the Zalando website works differently depending on its top-level domain: zalando.fr has an additional step before payment compared to zalando.de. This requires using different scenarios (i.e. different HAR files) depending on the tested domain. Moreover, to execute a realistic load test, we need to produce much more traffic targeting certain countries (i.e. groups of scenarios) than others.

To accommodate this way of working, our HAR files are organized in TLD-specific directories, each of which is potentially associated to a specific "weight" according to the relative amount of traffic expected:

scenarios/
├── Germany/
│   ├── scenario_1.har
│   ├── scenario_2.har
│   └── scenario_2.weight
├── Germany.weight
├── Switzerland/
│   └── scenario_1.har
└── Switzerland.weight

The "weight file" of directories (Germany.weight, Switzerland.weight) are similar to scenario weight files but apply to the whole directory (relatively to other directories of the same level). Thus, in the previous example, if Germany.weight is 6 and Switzerland.weight is 2, then Germany scenarios will be executed (in total) 3 times more (6 / 2) than Switzerland scenarios. A directory without a weight file has a weight of 1.

Scenarios can be arbitrarily nested, allowing you to organize and weight them as you want:

scenarios/
├── Germany/
│   ├── beauty/
│   │   └── checkout.har
│   ├── kids/
│   │   └── frontpage.har
│   ├── kids.weight
│   └── scenario_1.har
├── Germany.weight
├── Switzerland/
│   └── scenario_1.har
└── Switzerland.weight

To represent this, Transformer will produce nested Locust TaskSets in the resulting locustfile.

Blacklist specific URLs

By default, Transformer converts all requests found in input HAR files. You can blacklist, i.e. ignore, certain URLs by creating a .urlignore file in the directory in which Transformer is called.

Example

A .urlignore containing:

google
www.facebook.com
https://mosaic

... would ignore requests with URLs such as https://www.google.com, https://www.facebook.com/, and https://mosaic01-abc.js (amongst others).

An example blacklist file called .urlignore_example exists that you can use as a base.

Use plugins

In case you need some customization of the Locustfile generated by Transformer, you can use its plugin mechanisms to achieve it. Please see plugins documentation for more details.

Contributing

Please read CONTRIBUTING.md for details on our process for submitting pull requests to us, and please ensure you follow the CODE_OF_CONDUCT.md.

The only required dependency for local development is Poetry.

With Poetry, our Makefile installs all necessary dependencies and run all tests and linters:

make

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Release files for har-transformer 1.0.2.dev20190213164549

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for har-transformer 1.0.2.dev20190213164549
File Size Uploaded
har-transformer-1.0.2.dev20190213164549.tar.gz 47.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for har-transformer 1.0.2.dev20190213164549
File Interpreter ABI Platform
har_transformer-1.0.2.dev20190213164549-py3-none-any.whl Python 3 none any Details

Total release size: 216.7 kB

Release files / har-transformer-1.0.2.dev20190213164549.tar.gz

Download URL har-transformer-1.0.2.dev20190213164549.tar.gz
Size 47.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9f5415453bc035f50e08a6baeb609e5bd53629882f21a89f8a8d853eb5521e2c
BLAKE2b-256 checksum
How to use checksums
cf773a96bba12088b0afe2f5829d1bfdb2b5cf736ae806d1ff31fce7ee03e710
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.11 CPython/3.7.1 Linux/4.15.0-1026-gcp

Release files / har_transformer-1.0.2.dev20190213164549-py3-none-any.whl

Download URL har_transformer-1.0.2.dev20190213164549-py3-none-any.whl
Size 169.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
278a41e3184430caa766710ff4039d8ef28370890154562a3059fb556739ca22
BLAKE2b-256 checksum
How to use checksums
7f4b51e00492c09034fcef31dc24419358fb5b6ca31e95bc521c8dd48205b8ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.11 CPython/3.7.1 Linux/4.15.0-1026-gcp

Release history Release notifications | RSS feed

2.0.0

2 release files

1.3.0

2 release files

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

This release

1.0.1

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page