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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ jobs:
run: python setup.py bdist_wheel
- name: Install browsers
run: python -m playwright install
- name: Common Tests
run: pytest -vv tests/common --browser=${{ matrix.browser }} --timeout 90
- name: Test Sync API
if: matrix.os != 'ubuntu-latest'
run: pytest -vv tests/sync --browser=${{ matrix.browser }} --timeout 90
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ jobs:
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" pip install -r local-requirements.txt
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" pip install -e .
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" python setup.py bdist_wheel
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" xvfb-run pytest -vv tests/common/
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" xvfb-run pytest -vv tests/sync/
docker exec --workdir /root/playwright/ "${CONTAINER_ID}" xvfb-run pytest -vv tests/async/
12 changes: 9 additions & 3 deletions playwright/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,15 @@ async def __aexit__(self, *args: Any) -> None:
self._connection.stop_async()


if sys.platform == "win32":
# Use ProactorEventLoop in 3.7, which is default in 3.8
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
if sys.version_info.major == 3 and sys.version_info.minor == 7:
if sys.platform == "win32":
# Use ProactorEventLoop in 3.7, which is default in 3.8
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
else:
# Prevent Python 3.7 from throwing on Linux:
# RuntimeError: Cannot add child handler, the child watcher does not have a loop attached
asyncio.get_event_loop()
asyncio.get_child_watcher()


def main() -> None:
Expand Down
11 changes: 1 addition & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@ markers =
only_platform
junit_family=xunit2
[mypy]
ignore_missing_imports = True
python_version = 3.7
warn_unused_ignores = False
warn_redundant_casts = True
warn_unused_configs = True
check_untyped_defs = True
disallow_untyped_defs = True
[mypy-tests.*]
check_untyped_defs = False
disallow_untyped_defs = False
ignore_errors = True
[flake8]
ignore =
E501
Expand Down
35 changes: 35 additions & 0 deletions tests/common/test_threads.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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 threading

from playwright import sync_playwright


def test_running_in_thread(browser_name):
result = []

class TestThread(threading.Thread):
def run(self):
with sync_playwright() as playwright:
browser = getattr(playwright, browser_name).launch()
# This should not throw ^^.
browser.newPage()
browser.close()
result.append("Success")

test_thread = TestThread()
test_thread.start()
test_thread.join()
assert "Success" in result