Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 11 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ jobs:
git diff
exit 1
fi
- name: Run reference checks
run: bash buildbots/test-reference-count.sh
build:
name: Build
timeout-minutes: 30
Expand Down Expand Up @@ -87,19 +85,25 @@ jobs:
- name: Install browsers
run: python -m playwright install
- name: Common Tests
run: pytest -vv tests/common --browser=${{ matrix.browser }} --timeout 90
run: pytest tests/common --browser=${{ matrix.browser }} --timeout 90
- name: Test Reference count
run: pytest tests/test_reference_count_async.py --browser=${{ matrix.browser }}
- name: Test Wheel Installation
run: pytest tests/test_installation.py --browser=${{ matrix.browser }}
- name: Test Generation Scripts
run: pytest tests/test_generation_scripts.py --browser=${{ matrix.browser }}
- name: Test Sync API
if: matrix.os != 'ubuntu-latest'
run: pytest -vv tests/sync --browser=${{ matrix.browser }} --timeout 90
run: pytest tests/sync --browser=${{ matrix.browser }} --timeout 90
- name: Test Sync API
if: matrix.os == 'ubuntu-latest'
run: xvfb-run pytest -vv tests/sync --browser=${{ matrix.browser }} --timeout 90
run: xvfb-run pytest tests/sync --browser=${{ matrix.browser }} --timeout 90
- name: Test Async API
if: matrix.os != 'ubuntu-latest'
run: pytest -vv tests/async --browser=${{ matrix.browser }} --timeout 90
run: pytest tests/async --browser=${{ matrix.browser }} --timeout 90
- name: Test Async API
if: matrix.os == 'ubuntu-latest'
run: xvfb-run pytest -vv tests/async --browser=${{ matrix.browser }} --timeout 90
run: xvfb-run pytest tests/async --browser=${{ matrix.browser }} --timeout 90

stable:
name: Stable
Expand Down Expand Up @@ -148,23 +152,3 @@ jobs:
- name: Test Async API
if: matrix.os == 'ubuntu-latest'
run: xvfb-run pytest -vv tests/async --browser=chromium --browser-channel=${{ matrix.browser-channel }} --timeout 90

test-package-installations:
name: Test package installations
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r local-requirements.txt
pip install -e .
python setup.py bdist_wheel
python -m playwright install-deps
- name: Test package installation
run: bash buildbots/test-package-installations.sh
9 changes: 0 additions & 9 deletions buildbots/assets/stub.py

This file was deleted.

45 changes: 0 additions & 45 deletions buildbots/assets/test-reference-count-async.py

This file was deleted.

30 changes: 0 additions & 30 deletions buildbots/test-package-installations.sh

This file was deleted.

25 changes: 0 additions & 25 deletions buildbots/test-reference-count.sh

This file was deleted.

1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[tool:pytest]
addopts = -rsx -vv
markers =
skip_browser
only_browser
Expand Down
33 changes: 33 additions & 0 deletions tests/assets/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) Microsoft Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from pathlib import Path

from playwright.sync_api import Playwright, sync_playwright


def main(playwright: Playwright) -> None:
for browser_type in [playwright.chromium, playwright.firefox, playwright.webkit]:
browser = browser_type.launch()
page = browser.new_page()
page.goto("https://example.com")
here = Path(__file__).parent.resolve()
page.screenshot(path=here / f"{browser_type.name}.png")
page.close()
browser.close()


if __name__ == "__main__":
with sync_playwright() as p:
main(p)
32 changes: 21 additions & 11 deletions tests/test_generation_scripts.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
# Copyright (c) Microsoft Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
from io import StringIO
from unittest.mock import patch

import pytest

CAN_RUN_GENERATION_SCRIPT = sys.version_info >= (3, 8)

if CAN_RUN_GENERATION_SCRIPT:
from scripts.generate_async_api import main as generate_async_api
from scripts.generate_sync_api import main as generate_sync_api
pytestmark = pytest.mark.skipif(
sys.version_info < (3, 9), reason="requires python3.9 or higher"
)


@pytest.mark.skipif(
not CAN_RUN_GENERATION_SCRIPT, reason="requires python3.8 or higher"
)
@patch("sys.stderr", new_callable=StringIO)
@patch("sys.stdout", new_callable=StringIO)
def test_generate_sync_api(stdout, stderr):
from scripts.generate_sync_api import main as generate_sync_api

generate_sync_api()


@pytest.mark.skipif(
not CAN_RUN_GENERATION_SCRIPT, reason="requires python3.8 or higher"
)
@patch("sys.stderr", new_callable=StringIO)
@patch("sys.stdout", new_callable=StringIO)
def test_generate_async_api(stdout, stderr):
from scripts.generate_async_api import main as generate_async_api

generate_async_api()
52 changes: 52 additions & 0 deletions tests/test_installation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright (c) Microsoft Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import shutil
import subprocess
import sys
from pathlib import Path
from venv import EnvBuilder


def test_install(tmp_path: Path):
env = EnvBuilder(with_pip=True)
env.create(env_dir=tmp_path)
context = env.ensure_directories(tmp_path)
root = Path(__file__).parent.parent.resolve()
if sys.platform == "win32":
wheelpath = list((root / "dist").glob("playwright*win_amd64*.whl"))[0]
elif sys.platform == "linux":
wheelpath = list((root / "dist").glob("playwright*manylinux1*.whl"))[0]
elif sys.platform == "darwin":
wheelpath = list((root / "dist").glob("playwright*macosx_10_*.whl"))[0]
subprocess.check_output(
[
context.env_exe,
"-m",
"pip",
"install",
str(wheelpath),
]
)
environ = os.environ.copy()
environ["PLAYWRIGHT_BROWSERS_PATH"] = str(tmp_path)
subprocess.check_output(
[context.env_exe, "-m", "playwright", "install"], env=environ
)
shutil.copyfile(root / "tests" / "assets" / "client.py", tmp_path / "main.py")
subprocess.check_output([context.env_exe, str(tmp_path / "main.py")], env=environ)
assert (tmp_path / "chromium.png").exists()
assert (tmp_path / "firefox.png").exists()
assert (tmp_path / "webkit.png").exists()
52 changes: 52 additions & 0 deletions tests/test_reference_count_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright (c) Microsoft Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import gc

import objgraph
import pandas as pd
import pytest

from playwright.async_api import async_playwright


@pytest.mark.asyncio
async def test_memory_objects() -> None:
async with async_playwright() as p:
browser = await p.chromium.launch()
page = await browser.new_page()
await page.goto("https://example.com")

page.on("dialog", lambda dialog: dialog.dismiss())
for _ in range(100):
await page.evaluate("""async () => alert()""")

await page.route("**/", lambda route, _: route.fulfill(body="OK"))

for _ in range(100):
response = await page.evaluate("""async () => (await fetch("/")).text()""")
assert response == "OK"

await browser.close()

gc.collect()

df_dicts = pd.DataFrame()
df_dicts["dicts"] = objgraph.by_type("dict")
df_dicts["pw_types"] = df_dicts["dicts"].apply(lambda x: x.get("_type"))

head = df_dicts["pw_types"].value_counts().head(20)
assert "Dialog" not in head.items()
assert "Request" not in head.items()
assert "Route" not in head.items()