pytest-vtestify


Namepytest-vtestify JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/idejongkok/pytest-vtestify
SummaryA pytest plugin for visual assertion using SSIM and image comparison.
upload_time2024-10-10 08:40:07
maintainerNone
docs_urlNone
authorAria Uno Suseno
requires_python>=3.10
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![pytest-vtestify](https://github.com/user-attachments/assets/a4d71178-342b-47f6-8cc6-f7a8ce2a9938)

# pytest-vtestify

`pytest-vtestify` is a pytest plugin designed for visual assertion and image comparison, utilizing Structural Similarity Index (SSIM). This package is perfect for validating UI changes or detecting regressions in web and software interfaces.

## Features

- Compare two images using SSIM.
- Visualize the differences between images.
- Automatically generate and save the diff image with bounding boxes.
- Integrate seamlessly into pytest framework for automated testing workflows.

## Installation

To install the package, simply run:

```bash
pip install pytest-vtestify
```

##  Usage

### Basic Usage

You can integrate pytest-vtestify into your test suite by using the visual_assertion fixture. Below is an example of how to compare two images and generate a diff image.

```python
def test_visual_comparison(visual_assertion):
    image1 = "path/to/expected_image.png"
    image2 = "path/to/actual_image.png"
    visual_assertion(image1, image2, threshold=0.95)
```

### Web Automation Testing with Selenium
`pytest-vtestify` can also be used to perform visual regression testing in web automation projects, especially when working with dynamic web content. Here's an example using Selenium:

1. Capture screenshots of the expected and actual web pages.
2. Use visual_assertion to compare them.

#### Example using Selenium:

```python
from selenium import webdriver

def test_webpage_visual_comparison(visual_assertion):
    driver = webdriver.Chrome()
    
    # Navigate to the webpage and capture a screenshot
    driver.get('https://example.com')
    driver.save_screenshot('actual_page.png')
    
    # Assume 'expected_page.png' is the expected screenshot
    expected_image = 'path/to/expected_page.png'
    actual_image = 'actual_page.png'
    
    # Compare screenshots
    visual_assertion(expected_image, actual_image, threshold=0.98)
    
    driver.quit()
```
In this example:

Selenium's `webdriver.Chrome()` is used to open a web page.
The actual web page screenshot is compared to an expected screenshot using `pytest-vtestify`.
The `threshold` value specifies how similar the images should be to pass the test.

### Diff Image Output
When the comparison fails, a diff image will be automatically generated and saved in `report/images/diff.png`. This diff image contains:

- The expected image.
- The actual image.
- The diff image with bounding boxes highlighting the differences.

### Folder Structure
If the `report/images` folder doesn't exist, the plugin will create it during the test execution and place the diff image inside it.

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

### **Instructions for Using pytest-vtestify with Selenium**

In the example provided for web automation testing with Selenium:
- Selenium takes a screenshot of a web page during a test.
- You compare the screenshot to an "expected" image using the `visual_assertion` fixture from `pytest-vtestify`.
- The `threshold` parameter determines how closely the two images should match.

This approach is commonly used in visual regression testing for web automation, helping to catch unintended UI changes or regressions.

more question find me on:
- Instagram: [https://instagram.com/idejongkok](https://www.instagram.com/idejongkok/)
- YouTube: [https://youtube.com/idejongkok](https://youtube.com/idejongkok)
- Website: https://idejongkok.com

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/idejongkok/pytest-vtestify",
    "name": "pytest-vtestify",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "Aria Uno Suseno",
    "author_email": "idejongkok@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/7b/53/7b085d230cba2a76e17faa89e2acf0c3a9bbc9cae980afef43979deec8d0/pytest_vtestify-0.1.4.tar.gz",
    "platform": null,
    "description": "![pytest-vtestify](https://github.com/user-attachments/assets/a4d71178-342b-47f6-8cc6-f7a8ce2a9938)\r\n\r\n# pytest-vtestify\r\n\r\n`pytest-vtestify` is a pytest plugin designed for visual assertion and image comparison, utilizing Structural Similarity Index (SSIM). This package is perfect for validating UI changes or detecting regressions in web and software interfaces.\r\n\r\n## Features\r\n\r\n- Compare two images using SSIM.\r\n- Visualize the differences between images.\r\n- Automatically generate and save the diff image with bounding boxes.\r\n- Integrate seamlessly into pytest framework for automated testing workflows.\r\n\r\n## Installation\r\n\r\nTo install the package, simply run:\r\n\r\n```bash\r\npip install pytest-vtestify\r\n```\r\n\r\n##  Usage\r\n\r\n### Basic Usage\r\n\r\nYou can integrate pytest-vtestify into your test suite by using the visual_assertion fixture. Below is an example of how to compare two images and generate a diff image.\r\n\r\n```python\r\ndef test_visual_comparison(visual_assertion):\r\n    image1 = \"path/to/expected_image.png\"\r\n    image2 = \"path/to/actual_image.png\"\r\n    visual_assertion(image1, image2, threshold=0.95)\r\n```\r\n\r\n### Web Automation Testing with Selenium\r\n`pytest-vtestify` can also be used to perform visual regression testing in web automation projects, especially when working with dynamic web content. Here's an example using Selenium:\r\n\r\n1. Capture screenshots of the expected and actual web pages.\r\n2. Use visual_assertion to compare them.\r\n\r\n#### Example using Selenium:\r\n\r\n```python\r\nfrom selenium import webdriver\r\n\r\ndef test_webpage_visual_comparison(visual_assertion):\r\n    driver = webdriver.Chrome()\r\n    \r\n    # Navigate to the webpage and capture a screenshot\r\n    driver.get('https://example.com')\r\n    driver.save_screenshot('actual_page.png')\r\n    \r\n    # Assume 'expected_page.png' is the expected screenshot\r\n    expected_image = 'path/to/expected_page.png'\r\n    actual_image = 'actual_page.png'\r\n    \r\n    # Compare screenshots\r\n    visual_assertion(expected_image, actual_image, threshold=0.98)\r\n    \r\n    driver.quit()\r\n```\r\nIn this example:\r\n\r\nSelenium's `webdriver.Chrome()` is used to open a web page.\r\nThe actual web page screenshot is compared to an expected screenshot using `pytest-vtestify`.\r\nThe `threshold` value specifies how similar the images should be to pass the test.\r\n\r\n### Diff Image Output\r\nWhen the comparison fails, a diff image will be automatically generated and saved in `report/images/diff.png`. This diff image contains:\r\n\r\n- The expected image.\r\n- The actual image.\r\n- The diff image with bounding boxes highlighting the differences.\r\n\r\n### Folder Structure\r\nIf the `report/images` folder doesn't exist, the plugin will create it during the test execution and place the diff image inside it.\r\n\r\n### License\r\nThis project is licensed under the MIT License - see the LICENSE file for details.\r\n\r\n### **Instructions for Using pytest-vtestify with Selenium**\r\n\r\nIn the example provided for web automation testing with Selenium:\r\n- Selenium takes a screenshot of a web page during a test.\r\n- You compare the screenshot to an \"expected\" image using the `visual_assertion` fixture from `pytest-vtestify`.\r\n- The `threshold` parameter determines how closely the two images should match.\r\n\r\nThis approach is commonly used in visual regression testing for web automation, helping to catch unintended UI changes or regressions.\r\n\r\nmore question find me on:\r\n- Instagram: [https://instagram.com/idejongkok](https://www.instagram.com/idejongkok/)\r\n- YouTube: [https://youtube.com/idejongkok](https://youtube.com/idejongkok)\r\n- Website: https://idejongkok.com\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A pytest plugin for visual assertion using SSIM and image comparison.",
    "version": "0.1.4",
    "project_urls": {
        "Documentation": "https://github.com/idejongkok/pytest-vtestify/wiki",
        "Homepage": "https://github.com/idejongkok/pytest-vtestify",
        "Source": "https://github.com/idejongkok/pytest-vtestify"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7f765958783b15b4c72707f0360fb3f0905c1198659b22a72bba7f581d50854c",
                "md5": "1dea279e2f05a4849efa0d10011413a8",
                "sha256": "63fbeacc699051e9fa7442651f73ab493e1e95f33ce6ed897766bd6c434235c0"
            },
            "downloads": -1,
            "filename": "pytest_vtestify-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1dea279e2f05a4849efa0d10011413a8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 4932,
            "upload_time": "2024-10-10T08:40:06",
            "upload_time_iso_8601": "2024-10-10T08:40:06.129646Z",
            "url": "https://files.pythonhosted.org/packages/7f/76/5958783b15b4c72707f0360fb3f0905c1198659b22a72bba7f581d50854c/pytest_vtestify-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7b537b085d230cba2a76e17faa89e2acf0c3a9bbc9cae980afef43979deec8d0",
                "md5": "242cd1cf3fdbcadfe662843486fb2c6c",
                "sha256": "5f22684d90d3b3c01067ac2f61933c0b2757f8b2992fbf4d9e32de8c9bad4e2f"
            },
            "downloads": -1,
            "filename": "pytest_vtestify-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "242cd1cf3fdbcadfe662843486fb2c6c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 4462,
            "upload_time": "2024-10-10T08:40:07",
            "upload_time_iso_8601": "2024-10-10T08:40:07.171883Z",
            "url": "https://files.pythonhosted.org/packages/7b/53/7b085d230cba2a76e17faa89e2acf0c3a9bbc9cae980afef43979deec8d0/pytest_vtestify-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-10 08:40:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "idejongkok",
    "github_project": "pytest-vtestify",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pytest-vtestify"
}
        
Elapsed time: 0.73039s