Dom2Fixture is a python module that extracts the important information about a page and outputs it to a fixture file. This allows the user to quickly build page fixtures without having to manually select and copy elements.
At any time, run the following command to get help.
python -m dom2fixture --helpCurrently Dom2Fixture is not installed anywhere by default. To use Dom2Fixture locally, simply ensure that you have a valid virtual environment for Python 3.6 or later, and install the requirements with the following command.
git clone https://github.com/Codebiosys/dom2fixture.git
# Development (allows changes to the python files)
cd dom2fixture && pip install -r requirements.txt && pip install -e .To run the tests, ensure you've installed the dependencies and run:
pytest- In your browser, navigate to the page you want to model, and open the inspector.
- Copy the contents of the DOM to your clipboard.
- (On macOS) run the following command to send the DOM through the converter.
pbpaste | python -m dom2fixture -o <destination>On Linux or Windows, you'll have to save the data to a file and then run it though.
Dom2Fixture easily allows developers to add new extractors to the output.
- Add a new XPath selector to the list of extractors in
extract.py. This will tell the extraction to pull out all of the new elements matching this criteria. Any valid XPath is valid here. The extractors is a Tuple of (XPath, formatter function).
extractors = (
# ...
('//a', formatters.format_link),
# My new extractor goes here
('//directions/to/the/cheeseshop[type="open"], formatters.format_shop),
)- Add a formatter for the new extracted type. In some cases you can use a formatter that already exists. Check in
formattersfor one that might fit your needs. If not, add yours there.
You can easily view the results of the conversion in the terminal by using jq. Using the command from before, with JQ it becomes:
pbpaste | python -m dom2fixture | jqThe results should look something like this:

