Metadata-Version: 2.4
Name: pytest-playwright-softassert
Version: 1.0.0
Summary: Complete soft-assertion layer over Playwright's native expect() API
Author-email: Gopinath M <Gopinath.matheswaran1995@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/gopinathsasi/PlaywrightSoftAssertion
Project-URL: Repository, https://github.com/gopinathsasi/PlaywrightSoftAssertion
Project-URL: Issues, https://github.com/gopinathsasi/PlaywrightSoftAssertion/issues
Project-URL: Changelog, https://github.com/gopinathsasi/PlaywrightSoftAssertion/blob/main/CHANGELOG.md
Keywords: playwright,pytest,soft-assert,testing,automation
Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: playwright>=1.40
Requires-Dist: pytest>=7.0
Provides-Extra: dev
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

# pytest-playwright-softassert

A complete soft-assertion layer over Playwright's native `expect()` API.

## Design

`soft_expect(target, message)` is a direct, thin wrapper around Playwright's
own `expect.soft(target, message)`.  It returns Playwright's native
`LocatorAssertions`, `PageAssertions`, or `APIResponseAssertions` object
**unchanged**, so:

- Every current Playwright assertion method is available automatically.
- Every future Playwright assertion method will be available automatically.
- All assertion options (`timeout`, `ignore_case`, `use_inner_text`, regex,
  lists, …) pass through to Playwright without modification.
- Playwright's auto-retry, error messages, and call logs are fully preserved.
- No Playwright assertion logic is reimplemented.

Failure collection and per-test reporting are handled by Playwright's own
`_soft_scope()` mechanism, activated by the `pytest_runtest_call` hook
registered by this package.

## Installation

```bash
pip install pytest-playwright-softassert
```

## Usage

### Sync

```python
from pytest_playwright_softassert import soft_expect

def test_example(page):
    soft_expect(page.get_by_role("button", name="Save")).to_be_visible()
    soft_expect(page.get_by_text("Success")).to_have_text("Success")
    soft_expect(page).to_have_url("/dashboard")
    soft_expect(response).to_be_ok()
```

### With custom message

```python
soft_expect(
    page.get_by_role("heading"),
    "Dashboard heading must be visible"
).to_be_visible()
```

### With assertion options

```python
import re

soft_expect(locator).to_have_text("Hello", timeout=10_000, ignore_case=True)
soft_expect(locator).to_have_text(re.compile(r"Order\s+\d+"))
soft_expect(locator).to_have_text(["Item 1", "Item 2", "Item 3"])
```

### Negative assertions

```python
soft_expect(locator).not_to_be_visible()
soft_expect(locator).not_to_have_text("Error")
soft_expect(page).not_to_have_url(re.compile(r"/error"))
```

### Async

```python
from pytest_playwright_softassert import async_soft_expect

async def test_example(page):
    await async_soft_expect(locator).to_be_visible()
    await async_soft_expect(page).to_have_url("/dashboard")
```

## Behaviour

| Scenario | Behaviour |
|---|---|
| Soft assertion passes | Test continues normally |
| Soft assertion fails | Failure collected; test continues |
| All soft assertions pass | Test passes |
| One or more soft assertions fail | Test marked **FAILED** at the end |
| Hard `expect()` fails | Test fails immediately (unchanged) |

## Running the compatibility tests

```bash
pytest tests/test_compatibility.py -v
```

These tests verify that `soft_expect` exposes the same assertion method
surface as Playwright's native `expect()` for `LocatorAssertions`,
`PageAssertions`, and `APIResponseAssertions`.  They run without a browser
and should be included in CI.

## Running the integration tests

```bash
playwright install chromium
pytest tests/test_integration.py --browser chromium -v
```
