|
| 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 re |
| 16 | + |
| 17 | +import pytest |
| 18 | + |
| 19 | +from playwright import Error |
| 20 | +from playwright.async_api import Browser |
| 21 | + |
| 22 | + |
| 23 | +async def test_should_create_new_page(browser): |
| 24 | + page1 = await browser.newPage() |
| 25 | + assert len(browser.contexts) == 1 |
| 26 | + |
| 27 | + page2 = await browser.newPage() |
| 28 | + assert len(browser.contexts) == 2 |
| 29 | + |
| 30 | + await page1.close() |
| 31 | + assert len(browser.contexts) == 1 |
| 32 | + |
| 33 | + await page2.close() |
| 34 | + assert len(browser.contexts) == 0 |
| 35 | + |
| 36 | + |
| 37 | +async def test_should_throw_upon_second_create_new_page(browser): |
| 38 | + page = await browser.newPage() |
| 39 | + with pytest.raises(Error) as exc: |
| 40 | + await page.context.newPage() |
| 41 | + await page.close() |
| 42 | + assert "Please use browser.newContext()" in exc.value.message |
| 43 | + |
| 44 | + |
| 45 | +async def test_version_should_work(browser: Browser, is_chromium): |
| 46 | + version = browser.version |
| 47 | + if is_chromium: |
| 48 | + assert re.match(r"^\d+\.\d+\.\d+\.\d+$", version) |
| 49 | + else: |
| 50 | + assert re.match(r"^\d+\.\d+$", version) |
0 commit comments