Skip to content

Commit f7c2dc1

Browse files
authored
chore(tests): restructured into sync / async directories (#123)
1 parent 06a0369 commit f7c2dc1

31 files changed

+169
-152
lines changed

tests/async/__init__.py

Whitespace-only changes.

tests/async/conftest.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright (c) Microsoft Corporation.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License")
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import pytest
16+
17+
from playwright import async_playwright
18+
19+
20+
@pytest.fixture(scope="session")
21+
async def playwright():
22+
async with async_playwright() as playwright_object:
23+
yield playwright_object
24+
25+
26+
@pytest.fixture(scope="session")
27+
def browser_type(playwright, browser_name: str):
28+
if browser_name == "chromium":
29+
return playwright.chromium
30+
if browser_name == "firefox":
31+
return playwright.firefox
32+
if browser_name == "webkit":
33+
return playwright.webkit
34+
35+
36+
@pytest.fixture(scope="session")
37+
async def browser_factory(launch_arguments, browser_type):
38+
async def launch(**kwargs):
39+
return await browser_type.launch(**launch_arguments, **kwargs)
40+
41+
return launch
42+
43+
44+
@pytest.fixture(scope="session")
45+
async def browser(browser_factory):
46+
browser = await browser_factory()
47+
yield browser
48+
await browser.close()
49+
50+
51+
@pytest.fixture
52+
async def context(browser):
53+
context = await browser.newContext()
54+
yield context
55+
await context.close()
56+
57+
58+
@pytest.fixture
59+
async def page(context):
60+
page = await context.newPage()
61+
yield page
62+
await page.close()
63+
64+
65+
@pytest.fixture(scope="session")
66+
def selectors(playwright):
67+
return playwright.selectors
File renamed without changes.

tests/test_add_init_script.py renamed to tests/async/test_add_init_script.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
# limitations under the License.
1414

1515
from playwright import Error
16-
from playwright.path_utils import get_file_dirname
17-
18-
_dirname = get_file_dirname()
1916

2017

2118
async def test_add_init_script_evaluate_before_anything_else_on_the_page(page):
@@ -24,8 +21,8 @@ async def test_add_init_script_evaluate_before_anything_else_on_the_page(page):
2421
assert await page.evaluate("window.result") == 123
2522

2623

27-
async def test_add_init_script_work_with_a_path(page):
28-
await page.addInitScript(path=_dirname / "assets/injectedfile.js")
24+
async def test_add_init_script_work_with_a_path(page, assetdir):
25+
await page.addInitScript(path=assetdir / "injectedfile.js")
2926
await page.goto("data:text/html,<script>window.result = window.injected</script>")
3027
assert await page.evaluate("window.result") == 123
3128

@@ -54,9 +51,9 @@ async def test_add_init_script_work_with_browser_context_scripts(page, context):
5451

5552

5653
async def test_add_init_script_work_with_browser_context_scripts_with_a_path(
57-
page, context
54+
page, context, assetdir
5855
):
59-
await context.addInitScript(path=_dirname / "assets/injectedfile.js")
56+
await context.addInitScript(path=assetdir / "injectedfile.js")
6057
page = await context.newPage()
6158
await page.goto("data:text/html,<script>window.result = window.injected</script>")
6259
assert await page.evaluate("window.result") == 123
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)