delta-qa-vision 0.0.1b2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ src/delta_qa_vision/delta-qa-capture.js
2
+ .venv/
3
+ __pycache__/
4
+ .pytest_cache/
5
+ dist/
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,4 @@
1
+ Delta-QA Vision SDK
2
+ Copyright 2026 LAYA CONSEIL
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
@@ -0,0 +1,199 @@
1
+ Metadata-Version: 2.4
2
+ Name: delta-qa-vision
3
+ Version: 0.0.1b2
4
+ Summary: Delta-QA Vision SDK: a Selenium or Playwright test sends its pages to Delta-QA and reads the verdict
5
+ Project-URL: Homepage, https://delta-qa.com
6
+ Project-URL: Repository, https://github.com/delta-qa-com/delta-qa-vision
7
+ Author-email: Delta-QA <support@delta-qa.com>
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ License-File: NOTICE
11
+ Requires-Python: >=3.10
12
+ Provides-Extra: playwright
13
+ Requires-Dist: playwright>=1.40; extra == 'playwright'
14
+ Provides-Extra: selenium
15
+ Requires-Dist: selenium>=4.10; extra == 'selenium'
16
+ Description-Content-Type: text/markdown
17
+
18
+ # Delta-QA Vision for Python
19
+
20
+ Delta-QA's visual regression SDK for Selenium and Playwright. A test sends its pages to Delta-QA, which compares each of them with the reference of the test in the same environment. Delta-QA is artificial sight: it compares the way a human eye would. A pixel-by-pixel comparison flags differences no one can see — false positives — and misses changes a person notices — false negatives. Delta-QA reports only the differences a person can see, and decides the result.
21
+
22
+ ## Requirements
23
+
24
+ - Python 3.10 or later
25
+ - Selenium 4.10 or later: the SDK uses the Selenium of your test. pytest, unittest and Robot Framework (SeleniumLibrary) run on it.
26
+ - Or Playwright for Python 1.40 or later, its sync API: the SDK uses the Playwright of your test.
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install delta-qa-vision # with your own Selenium
32
+ pip install "delta-qa-vision[selenium]" # with Selenium
33
+ pip install "delta-qa-vision[playwright]" # with Playwright
34
+ ```
35
+
36
+ ## Environment variables
37
+
38
+ | Variable | Purpose |
39
+ |---|---|
40
+ | `DELTAQA_API_KEY` | An API key of your workspace (`dqa_…`) whose role can edit, to send pages. An administrator creates it in *Settings → Workspace → API keys*; it is shown once. The workspace is the key's: there is no workspace setting |
41
+ | `DELTAQA_SERVER_URL` | The root of your Delta-QA server, e.g. `http://localhost:9327`; the SaaS, `https://api.delta-qa.com`, when not set |
42
+
43
+ Without a key, opening a test fails and names the variable to set. The key is sent in the `Authorization` header only: it never appears in an error message, a log or a link of the SDK.
44
+
45
+ ## The Vision API
46
+
47
+ ```python
48
+ import os
49
+ import delta_qa_vision
50
+ from delta_qa_vision import CheckSettings, Size, VisionSettings
51
+ from selenium.webdriver.common.by import By
52
+
53
+ settings = VisionSettings(
54
+ id="checkout",
55
+ name="Checkout",
56
+ commit=os.environ["GITHUB_SHA"],
57
+ branch=os.environ.get("GITHUB_HEAD_REF") or None,
58
+ base_branch=os.environ.get("GITHUB_BASE_REF") or None,
59
+ )
60
+ with delta_qa_vision.open(driver, settings) as vision:
61
+ driver.get("https://shop.example/cart")
62
+ vision.check("Cart")
63
+ driver.find_element(By.ID, "pay").click()
64
+ vision.check("Payment", CheckSettings(ignore=["#now", (By.ID, "advert")]))
65
+ # closed: raises VisionTestFailedError when Delta-QA decides UNRESOLVED, REJECTED or FAILED
66
+ ```
67
+
68
+ The `with` block closes the test only when its body succeeds: a test that already failed keeps its own error, and its launches are closed by Delta-QA after a delay. Without `with`, call `vision.close()`, which returns the `VisionResults` (each launch, its result, the link of its comparison and of the commit).
69
+
70
+ ## Playwright
71
+
72
+ The same API takes the page of a Playwright test: give `delta_qa_vision.open` a `playwright.sync_api.Page`. The SDK picks its adapter by the type of what it is given.
73
+
74
+ ```bash
75
+ pip install "delta-qa-vision[playwright]" pytest-playwright
76
+ ```
77
+
78
+ ```python
79
+ import os
80
+ import delta_qa_vision
81
+ from delta_qa_vision import CheckSettings, VisionSettings
82
+
83
+
84
+ def test_cart(page): # the page fixture of pytest-playwright
85
+ settings = VisionSettings(id="cart", name="Cart", commit=os.environ["GITHUB_SHA"])
86
+ with delta_qa_vision.open(page, settings) as vision:
87
+ page.goto("https://shop.example/cart")
88
+ vision.check("Cart", CheckSettings(ignore=["#now", page.get_by_test_id("advert")]))
89
+ ```
90
+
91
+ Run it in Chrome, Chromium or Edge: `pytest --browser chromium`, or `--browser-channel chrome` for Google Chrome. Under Firefox or WebKit, opening the test fails with an unsupported-browser error.
92
+
93
+ Under Playwright, a zone is a selector (a `str`, in Playwright's selector syntax), a `Locator` or an `ElementHandle` of the page of the test. A locator or a handle of another page is refused. The SDK takes the page's frames itself: there is nothing to switch.
94
+
95
+ Only the sync API is supported: a page of `playwright.async_api` is refused when the test opens.
96
+
97
+ ## Settings
98
+
99
+ `VisionSettings` takes these settings; `sizes` is a list of `Size(width, height)`:
100
+
101
+ | Setting | Meaning |
102
+ |---|---|
103
+ | `id` | What recognises the test, with `app`: keep it when the name changes; a new id is a new test |
104
+ | `name` | The name Delta-QA shows the test under |
105
+ | `commit` | **Required**: the git commit tested, its hash as the CI gives it |
106
+ | `tag` | The git tag of the commit, shown beside it; `None` when the commit has none — the common case |
107
+ | `branch` | The branch of the launch; `None` when the run is on no branch (the build of a tag, a detached commit) |
108
+ | `base_branch` | The branch whose reference is used while the branch has none — the target of a pull or merge request; `None` without one. Equal to the branch, it is not sent |
109
+ | `app` | The application of the test, a label; optional |
110
+ | `sizes` | The sizes the page is taken at: one launch per size, the page resized in the test's browser at each check and given back its size, its resources sent once; without it, the page's own size |
111
+ | `save_new_tests` | Whether the pages of a new test become its reference (result `NEW`); true when absent, false to judge them first (`UNRESOLVED`) |
112
+
113
+ A setting given as an empty text is refused when the test opens, and nothing is sent.
114
+
115
+ ## Demo
116
+
117
+ The [GoodDeal practice tests](https://github.com/delta-qa-com/gooddeal-practice-tests/tree/main) hold ready-to-run tests against [GoodDeal](https://delta-qa.com/playground/), a free demo store: four journeys (an order, a declined card, the contact form, the sign-in), each with a Vision check at every step. The Vision tests run when `DELTAQA_API_KEY` is set.
118
+
119
+ | Framework | Demo |
120
+ |---|---|
121
+ | Selenium | [`python/selenium`](https://github.com/delta-qa-com/gooddeal-practice-tests/tree/main/python/selenium) |
122
+ | Playwright | [`python/playwright`](https://github.com/delta-qa-com/gooddeal-practice-tests/tree/main/python/playwright) |
123
+
124
+ ## The commit, the tag and the branches
125
+
126
+ The SDK reads neither git nor your CI: give it the values of the run, read in the variables of your CI. `commit` is required; the others are absent (``None``) when they do not exist.
127
+
128
+ | CI | commit | tag | branch | base branch |
129
+ |---|---|---|---|---|
130
+ | GitHub Actions | `GITHUB_SHA` | `GITHUB_REF_NAME` when `GITHUB_REF_TYPE` is `tag` | `GITHUB_HEAD_REF`, else `GITHUB_REF_NAME` when `GITHUB_REF_TYPE` is `branch` | `GITHUB_BASE_REF` |
131
+ | GitLab CI | `CI_COMMIT_SHA` | `CI_COMMIT_TAG` | `CI_MERGE_REQUEST_SOURCE_BRANCH_NAME`, else `CI_COMMIT_BRANCH` | `CI_MERGE_REQUEST_TARGET_BRANCH_NAME` |
132
+ | Bitbucket Pipelines | `BITBUCKET_COMMIT` | `BITBUCKET_TAG` | `BITBUCKET_BRANCH` | `BITBUCKET_PR_DESTINATION_BRANCH` |
133
+ | Azure Pipelines | `BUILD_SOURCEVERSION` | `BUILD_SOURCEBRANCH` of the form `refs/tags/…` | `SYSTEM_PULLREQUEST_SOURCEBRANCH`, without its `refs/heads/`, else `BUILD_SOURCEBRANCH` of the form `refs/heads/…` | `SYSTEM_PULLREQUEST_TARGETBRANCH`, without its `refs/heads/` |
134
+
135
+ Machines that run the same suite in parallel share one commit by giving the same text.
136
+
137
+ ## Browsers
138
+
139
+ The page is taken in **Chrome, Chromium or Edge**, through the browser's DevTools protocol, at a device pixel ratio of 1. Under another browser (Firefox, Safari), opening a test fails with an unsupported-browser error, and nothing is sent.
140
+
141
+ Under Selenium, a check is taken from the top document of the page: switch back out of any frame before checking.
142
+
143
+ ## Checks and zones
144
+
145
+ `check(name)` sends the page as the test sees it now — the live DOM, the state of its fields, its web components and its frames, and the files it uses. Every check of a test has its own name: a name already taken is refused, and nothing is sent.
146
+
147
+ A check can leave **zones** out of the comparison (`ignore`: a clock, an advert) or compare **one zone alone** (`region`). Under Selenium, a zone is a CSS selector (a `str`), a locator tuple such as `(By.ID, "advert")` or a `WebElement`; under Playwright, see [Playwright](#playwright). Every element a zone designates is one zone; a zone that designates none fails the check, and nothing is sent.
148
+
149
+ ```python
150
+ vision.check("Cart", CheckSettings(ignore=["#now"], region="main"))
151
+ ```
152
+
153
+ ## The verdict
154
+
155
+ `close()` closes every launch of the test and waits for Delta-QA's result (at most 15 minutes):
156
+
157
+ | Result | The test |
158
+ |---|---|
159
+ | `NEW` | Passes: the pages became the reference of a new test |
160
+ | `PASSED` | Passes: the same pages as the reference |
161
+ | `UNRESOLVED` | Fails: a difference waits for a person's judgment — the message gives the link of the commit in Delta-QA |
162
+ | `REJECTED` | Fails: a difference was judged a bug |
163
+ | `FAILED` | Fails: Delta-QA could not compare the pages |
164
+
165
+ A second call to `close()` gives the same results, or the same failure, without asking Delta-QA again.
166
+
167
+ ## Errors
168
+
169
+ | Error | When |
170
+ |---|---|
171
+ | `DeltaQaConfigurationError` | A variable is missing or wrong; the error names it |
172
+ | `DeltaQaApiError` | Delta-QA refused a request: its code names the cause (e.g. `API_KEY_INVALID`, `INSUFFICIENT_ROLE`, `LAUNCH_CLOSED`), its ticket names the occurrence — quote it to the support |
173
+ | `DeltaQaUnreachableError` | No answer came from the server; the cause says what the network said |
174
+ | `UnsupportedBrowserError` | The browser is not Chrome, Chromium or Edge; nothing is opened |
175
+ | `UnsupportedDensityError` | The page is shown at a device pixel ratio other than 1 |
176
+ | `DuplicateCheckNameError` | `check` was given a name already taken in the test; nothing is sent |
177
+ | `ZoneNotFoundError` | A zone of `check` matches no element of the page; the error names it, and nothing is sent |
178
+ | `ResourceUnreadableError` | A file the page cites could not be read, or did not come whole within 30 seconds; the error names its address |
179
+ | `ResourceTooLargeError` | A file the page cites is larger than Delta-QA admits; the check is not sent |
180
+ | `LaunchResultTimeoutError` | The wait for a result ran out; the launch keeps running on Delta-QA, and the message gives the address of its comparison |
181
+ | `VisionTestFailedError` | Delta-QA decided a launch `UNRESOLVED`, `REJECTED` or `FAILED`: the results give each launch, its comparison, and the link of the commit |
182
+
183
+ Every error is importable from `delta_qa_vision`.
184
+
185
+ ## Your data
186
+
187
+ What the SDK sends — the pages your tests check and the files they use — serves only to compare them. Testing on production personal data is your responsibility: run your suites on test data.
188
+
189
+ To read a file the page cites and the browser cannot hand over, the SDK asks for it itself, as the browser would: with the browser's cookies for that address, its user agent and its `Referer`. Only `http` and `https` addresses are read.
190
+
191
+ ## Versions
192
+
193
+ The SDK is released with Delta-QA: its version is the Delta-QA release that published it. Its compatibility is carried by the API it calls — the Vision API **v1**, `/api/vision/v1`, a frozen contract that only grows. A breaking change of the API is a v2, deployed beside v1, and v1 keeps answering until its announced end.
194
+
195
+ ## Licence
196
+
197
+ Apache License 2.0 — see [LICENSE](LICENSE) and [NOTICE](NOTICE). Calling Delta-QA requires a Delta-QA API key.
198
+
199
+ Support: support@delta-qa.com · <https://delta-qa.com>
@@ -0,0 +1,182 @@
1
+ # Delta-QA Vision for Python
2
+
3
+ Delta-QA's visual regression SDK for Selenium and Playwright. A test sends its pages to Delta-QA, which compares each of them with the reference of the test in the same environment. Delta-QA is artificial sight: it compares the way a human eye would. A pixel-by-pixel comparison flags differences no one can see — false positives — and misses changes a person notices — false negatives. Delta-QA reports only the differences a person can see, and decides the result.
4
+
5
+ ## Requirements
6
+
7
+ - Python 3.10 or later
8
+ - Selenium 4.10 or later: the SDK uses the Selenium of your test. pytest, unittest and Robot Framework (SeleniumLibrary) run on it.
9
+ - Or Playwright for Python 1.40 or later, its sync API: the SDK uses the Playwright of your test.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pip install delta-qa-vision # with your own Selenium
15
+ pip install "delta-qa-vision[selenium]" # with Selenium
16
+ pip install "delta-qa-vision[playwright]" # with Playwright
17
+ ```
18
+
19
+ ## Environment variables
20
+
21
+ | Variable | Purpose |
22
+ |---|---|
23
+ | `DELTAQA_API_KEY` | An API key of your workspace (`dqa_…`) whose role can edit, to send pages. An administrator creates it in *Settings → Workspace → API keys*; it is shown once. The workspace is the key's: there is no workspace setting |
24
+ | `DELTAQA_SERVER_URL` | The root of your Delta-QA server, e.g. `http://localhost:9327`; the SaaS, `https://api.delta-qa.com`, when not set |
25
+
26
+ Without a key, opening a test fails and names the variable to set. The key is sent in the `Authorization` header only: it never appears in an error message, a log or a link of the SDK.
27
+
28
+ ## The Vision API
29
+
30
+ ```python
31
+ import os
32
+ import delta_qa_vision
33
+ from delta_qa_vision import CheckSettings, Size, VisionSettings
34
+ from selenium.webdriver.common.by import By
35
+
36
+ settings = VisionSettings(
37
+ id="checkout",
38
+ name="Checkout",
39
+ commit=os.environ["GITHUB_SHA"],
40
+ branch=os.environ.get("GITHUB_HEAD_REF") or None,
41
+ base_branch=os.environ.get("GITHUB_BASE_REF") or None,
42
+ )
43
+ with delta_qa_vision.open(driver, settings) as vision:
44
+ driver.get("https://shop.example/cart")
45
+ vision.check("Cart")
46
+ driver.find_element(By.ID, "pay").click()
47
+ vision.check("Payment", CheckSettings(ignore=["#now", (By.ID, "advert")]))
48
+ # closed: raises VisionTestFailedError when Delta-QA decides UNRESOLVED, REJECTED or FAILED
49
+ ```
50
+
51
+ The `with` block closes the test only when its body succeeds: a test that already failed keeps its own error, and its launches are closed by Delta-QA after a delay. Without `with`, call `vision.close()`, which returns the `VisionResults` (each launch, its result, the link of its comparison and of the commit).
52
+
53
+ ## Playwright
54
+
55
+ The same API takes the page of a Playwright test: give `delta_qa_vision.open` a `playwright.sync_api.Page`. The SDK picks its adapter by the type of what it is given.
56
+
57
+ ```bash
58
+ pip install "delta-qa-vision[playwright]" pytest-playwright
59
+ ```
60
+
61
+ ```python
62
+ import os
63
+ import delta_qa_vision
64
+ from delta_qa_vision import CheckSettings, VisionSettings
65
+
66
+
67
+ def test_cart(page): # the page fixture of pytest-playwright
68
+ settings = VisionSettings(id="cart", name="Cart", commit=os.environ["GITHUB_SHA"])
69
+ with delta_qa_vision.open(page, settings) as vision:
70
+ page.goto("https://shop.example/cart")
71
+ vision.check("Cart", CheckSettings(ignore=["#now", page.get_by_test_id("advert")]))
72
+ ```
73
+
74
+ Run it in Chrome, Chromium or Edge: `pytest --browser chromium`, or `--browser-channel chrome` for Google Chrome. Under Firefox or WebKit, opening the test fails with an unsupported-browser error.
75
+
76
+ Under Playwright, a zone is a selector (a `str`, in Playwright's selector syntax), a `Locator` or an `ElementHandle` of the page of the test. A locator or a handle of another page is refused. The SDK takes the page's frames itself: there is nothing to switch.
77
+
78
+ Only the sync API is supported: a page of `playwright.async_api` is refused when the test opens.
79
+
80
+ ## Settings
81
+
82
+ `VisionSettings` takes these settings; `sizes` is a list of `Size(width, height)`:
83
+
84
+ | Setting | Meaning |
85
+ |---|---|
86
+ | `id` | What recognises the test, with `app`: keep it when the name changes; a new id is a new test |
87
+ | `name` | The name Delta-QA shows the test under |
88
+ | `commit` | **Required**: the git commit tested, its hash as the CI gives it |
89
+ | `tag` | The git tag of the commit, shown beside it; `None` when the commit has none — the common case |
90
+ | `branch` | The branch of the launch; `None` when the run is on no branch (the build of a tag, a detached commit) |
91
+ | `base_branch` | The branch whose reference is used while the branch has none — the target of a pull or merge request; `None` without one. Equal to the branch, it is not sent |
92
+ | `app` | The application of the test, a label; optional |
93
+ | `sizes` | The sizes the page is taken at: one launch per size, the page resized in the test's browser at each check and given back its size, its resources sent once; without it, the page's own size |
94
+ | `save_new_tests` | Whether the pages of a new test become its reference (result `NEW`); true when absent, false to judge them first (`UNRESOLVED`) |
95
+
96
+ A setting given as an empty text is refused when the test opens, and nothing is sent.
97
+
98
+ ## Demo
99
+
100
+ The [GoodDeal practice tests](https://github.com/delta-qa-com/gooddeal-practice-tests/tree/main) hold ready-to-run tests against [GoodDeal](https://delta-qa.com/playground/), a free demo store: four journeys (an order, a declined card, the contact form, the sign-in), each with a Vision check at every step. The Vision tests run when `DELTAQA_API_KEY` is set.
101
+
102
+ | Framework | Demo |
103
+ |---|---|
104
+ | Selenium | [`python/selenium`](https://github.com/delta-qa-com/gooddeal-practice-tests/tree/main/python/selenium) |
105
+ | Playwright | [`python/playwright`](https://github.com/delta-qa-com/gooddeal-practice-tests/tree/main/python/playwright) |
106
+
107
+ ## The commit, the tag and the branches
108
+
109
+ The SDK reads neither git nor your CI: give it the values of the run, read in the variables of your CI. `commit` is required; the others are absent (``None``) when they do not exist.
110
+
111
+ | CI | commit | tag | branch | base branch |
112
+ |---|---|---|---|---|
113
+ | GitHub Actions | `GITHUB_SHA` | `GITHUB_REF_NAME` when `GITHUB_REF_TYPE` is `tag` | `GITHUB_HEAD_REF`, else `GITHUB_REF_NAME` when `GITHUB_REF_TYPE` is `branch` | `GITHUB_BASE_REF` |
114
+ | GitLab CI | `CI_COMMIT_SHA` | `CI_COMMIT_TAG` | `CI_MERGE_REQUEST_SOURCE_BRANCH_NAME`, else `CI_COMMIT_BRANCH` | `CI_MERGE_REQUEST_TARGET_BRANCH_NAME` |
115
+ | Bitbucket Pipelines | `BITBUCKET_COMMIT` | `BITBUCKET_TAG` | `BITBUCKET_BRANCH` | `BITBUCKET_PR_DESTINATION_BRANCH` |
116
+ | Azure Pipelines | `BUILD_SOURCEVERSION` | `BUILD_SOURCEBRANCH` of the form `refs/tags/…` | `SYSTEM_PULLREQUEST_SOURCEBRANCH`, without its `refs/heads/`, else `BUILD_SOURCEBRANCH` of the form `refs/heads/…` | `SYSTEM_PULLREQUEST_TARGETBRANCH`, without its `refs/heads/` |
117
+
118
+ Machines that run the same suite in parallel share one commit by giving the same text.
119
+
120
+ ## Browsers
121
+
122
+ The page is taken in **Chrome, Chromium or Edge**, through the browser's DevTools protocol, at a device pixel ratio of 1. Under another browser (Firefox, Safari), opening a test fails with an unsupported-browser error, and nothing is sent.
123
+
124
+ Under Selenium, a check is taken from the top document of the page: switch back out of any frame before checking.
125
+
126
+ ## Checks and zones
127
+
128
+ `check(name)` sends the page as the test sees it now — the live DOM, the state of its fields, its web components and its frames, and the files it uses. Every check of a test has its own name: a name already taken is refused, and nothing is sent.
129
+
130
+ A check can leave **zones** out of the comparison (`ignore`: a clock, an advert) or compare **one zone alone** (`region`). Under Selenium, a zone is a CSS selector (a `str`), a locator tuple such as `(By.ID, "advert")` or a `WebElement`; under Playwright, see [Playwright](#playwright). Every element a zone designates is one zone; a zone that designates none fails the check, and nothing is sent.
131
+
132
+ ```python
133
+ vision.check("Cart", CheckSettings(ignore=["#now"], region="main"))
134
+ ```
135
+
136
+ ## The verdict
137
+
138
+ `close()` closes every launch of the test and waits for Delta-QA's result (at most 15 minutes):
139
+
140
+ | Result | The test |
141
+ |---|---|
142
+ | `NEW` | Passes: the pages became the reference of a new test |
143
+ | `PASSED` | Passes: the same pages as the reference |
144
+ | `UNRESOLVED` | Fails: a difference waits for a person's judgment — the message gives the link of the commit in Delta-QA |
145
+ | `REJECTED` | Fails: a difference was judged a bug |
146
+ | `FAILED` | Fails: Delta-QA could not compare the pages |
147
+
148
+ A second call to `close()` gives the same results, or the same failure, without asking Delta-QA again.
149
+
150
+ ## Errors
151
+
152
+ | Error | When |
153
+ |---|---|
154
+ | `DeltaQaConfigurationError` | A variable is missing or wrong; the error names it |
155
+ | `DeltaQaApiError` | Delta-QA refused a request: its code names the cause (e.g. `API_KEY_INVALID`, `INSUFFICIENT_ROLE`, `LAUNCH_CLOSED`), its ticket names the occurrence — quote it to the support |
156
+ | `DeltaQaUnreachableError` | No answer came from the server; the cause says what the network said |
157
+ | `UnsupportedBrowserError` | The browser is not Chrome, Chromium or Edge; nothing is opened |
158
+ | `UnsupportedDensityError` | The page is shown at a device pixel ratio other than 1 |
159
+ | `DuplicateCheckNameError` | `check` was given a name already taken in the test; nothing is sent |
160
+ | `ZoneNotFoundError` | A zone of `check` matches no element of the page; the error names it, and nothing is sent |
161
+ | `ResourceUnreadableError` | A file the page cites could not be read, or did not come whole within 30 seconds; the error names its address |
162
+ | `ResourceTooLargeError` | A file the page cites is larger than Delta-QA admits; the check is not sent |
163
+ | `LaunchResultTimeoutError` | The wait for a result ran out; the launch keeps running on Delta-QA, and the message gives the address of its comparison |
164
+ | `VisionTestFailedError` | Delta-QA decided a launch `UNRESOLVED`, `REJECTED` or `FAILED`: the results give each launch, its comparison, and the link of the commit |
165
+
166
+ Every error is importable from `delta_qa_vision`.
167
+
168
+ ## Your data
169
+
170
+ What the SDK sends — the pages your tests check and the files they use — serves only to compare them. Testing on production personal data is your responsibility: run your suites on test data.
171
+
172
+ To read a file the page cites and the browser cannot hand over, the SDK asks for it itself, as the browser would: with the browser's cookies for that address, its user agent and its `Referer`. Only `http` and `https` addresses are read.
173
+
174
+ ## Versions
175
+
176
+ The SDK is released with Delta-QA: its version is the Delta-QA release that published it. Its compatibility is carried by the API it calls — the Vision API **v1**, `/api/vision/v1`, a frozen contract that only grows. A breaking change of the API is a v2, deployed beside v1, and v1 keeps answering until its announced end.
177
+
178
+ ## Licence
179
+
180
+ Apache License 2.0 — see [LICENSE](LICENSE) and [NOTICE](NOTICE). Calling Delta-QA requires a Delta-QA API key.
181
+
182
+ Support: support@delta-qa.com · <https://delta-qa.com>
@@ -0,0 +1,41 @@
1
+ [build-system]
2
+ requires = ["hatchling==1.27.0"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "delta-qa-vision"
7
+ version = "0.0.1-beta2"
8
+ description = "Delta-QA Vision SDK: a Selenium or Playwright test sends its pages to Delta-QA and reads the verdict"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ license-files = ["LICENSE", "NOTICE"]
12
+ authors = [{ name = "Delta-QA", email = "support@delta-qa.com" }]
13
+ requires-python = ">=3.10"
14
+ dependencies = []
15
+
16
+ [project.urls]
17
+ Homepage = "https://delta-qa.com"
18
+ # The public repository of the SDKs: the one address that names it in this package.
19
+ Repository = "https://github.com/delta-qa-com/delta-qa-vision"
20
+
21
+ [project.optional-dependencies]
22
+ # Selenium is the test's own: the version of the client decides.
23
+ selenium = ["selenium>=4.10"]
24
+ # Playwright is the test's own too: its sync API.
25
+ playwright = ["playwright>=1.40"]
26
+
27
+ [dependency-groups]
28
+ test = ["selenium==4.39.0", "playwright==1.65.2", "pytest==8.4.2", "pyyaml==6.0.3"]
29
+
30
+ [tool.hatch.build.targets.wheel]
31
+ packages = ["src/delta_qa_vision"]
32
+ # The capture script, copied by scripts/copy_capture.py, travels in the wheel.
33
+ artifacts = ["src/delta_qa_vision/delta-qa-capture.js"]
34
+
35
+ # The script is ignored by git: the sdist names it too, or the wheel built from it would lack it.
36
+ [tool.hatch.build.targets.sdist]
37
+ artifacts = ["src/delta_qa_vision/delta-qa-capture.js"]
38
+
39
+ [tool.pytest.ini_options]
40
+ testpaths = ["tests"]
41
+ pythonpath = ["src"]
@@ -0,0 +1,18 @@
1
+ """Copies the capture script of the repository (../capture/) into the package.
2
+
3
+ The one script every Vision SDK carries: the Python SDK has no page rule of its own. The copy is never
4
+ edited nor committed (.gitignore); tests/test_contracts.py refuses one that is missing or behind.
5
+ """
6
+ import pathlib
7
+ import sys
8
+
9
+ ROOT = pathlib.Path(__file__).resolve().parent.parent
10
+ SOURCE = ROOT.parent / "capture" / "delta-qa-capture.js"
11
+ TARGET = ROOT / "src" / "delta_qa_vision" / "delta-qa-capture.js"
12
+
13
+ if not SOURCE.exists():
14
+ sys.exit(f"{SOURCE} is missing: the capture script lives in capture/ of this repository")
15
+ script = SOURCE.read_text(encoding="utf-8")
16
+ if "DeltaQaCapture" not in script:
17
+ sys.exit(f"{SOURCE} is not the capture script: it declares no DeltaQaCapture")
18
+ TARGET.write_text(script, encoding="utf-8")