How to use test_browser_type_executable_path_should_work method in Playwright Python

Best Python code snippet using playwright-python

Run Playwright Python automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

test_launcher.py

Source: test_launcher.py Github

copy
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
15import asyncio
16import os
17
18import pytest
19
20from playwright.async_api import BrowserType, Error
21
22
23async def test_browser_type_launch_should_reject_all_promises_when_browser_is_closed(
24    browser_type: BrowserType, launch_arguments
25):
26    browser = await browser_type.launch(**launch_arguments)
27    page = await (await browser.new_context()).new_page()
28    never_resolves = asyncio.create_task(page.evaluate("() => new Promise(r => {})"))
29    await page.close()
30    with pytest.raises(Error) as exc:
31        await never_resolves
32    assert "Protocol error" in exc.value.message
33
34
35@pytest.mark.skip_browser("firefox")
36async def test_browser_type_launch_should_throw_if_page_argument_is_passed(
37    browser_type, launch_arguments
38):
39    with pytest.raises(Error) as exc:
40        await browser_type.launch(**launch_arguments, args=["http://example.com"])
41    assert "can not specify page" in exc.value.message
42
43
44@pytest.mark.skip("currently disabled on upstream")
45async def test_browser_type_launch_should_reject_if_launched_browser_fails_immediately(
46    browser_type, launch_arguments, assetdir
47):
48    with pytest.raises(Error):
49        await browser_type.launch(
50            **launch_arguments,
51            executable_path=assetdir / "dummy_bad_browser_executable.js"
52        )
53
54
55@pytest.mark.skip(
56    "does not return the expected error"
57)  # TODO: hangs currently on the bots
58async def test_browser_type_launch_should_reject_if_executable_path_is_invalid(
59    browser_type, launch_arguments
60):
61    with pytest.raises(Error) as exc:
62        await browser_type.launch(
63            **launch_arguments, executable_path="random-invalid-path"
64        )
65    assert "Failed to launch" in exc.value.message
66
67
68@pytest.mark.skip()
69async def test_browser_type_launch_server_should_return_child_process_instance(
70    browser_type, launch_arguments
71):
72    browser_server = await browser_type.launchServer(**launch_arguments)
73    assert browser_server.pid > 0
74    await browser_server.close()
75
76
77@pytest.mark.skip()
78async def test_browser_type_launch_server_should_fire_close_event(
79    browser_type, launch_arguments
80):
81    browser_server = await browser_type.launchServer(**launch_arguments)
82    close_event = asyncio.Future()
83    browser_server.on("close", lambda: close_event.set_result(None))
84    await asyncio.gather(close_event, browser_server.close())
85
86
87async def test_browser_type_executable_path_should_work(browser_type):
88    executable_path = browser_type.executable_path
89    assert os.path.exists(executable_path)
90    assert os.path.realpath(executable_path) == os.path.realpath(executable_path)
91
92
93async def test_browser_type_name_should_work(
94    browser_type, is_webkit, is_firefox, is_chromium
95):
96    if is_webkit:
97        assert browser_type.name == "webkit"
98    elif is_firefox:
99        assert browser_type.name == "firefox"
100    elif is_chromium:
101        assert browser_type.name == "chromium"
102    else:
103        raise ValueError("Unknown browser")
104
105
106async def test_browser_close_should_fire_close_event_for_all_contexts(
107    browser_type, launch_arguments
108):
109    browser = await browser_type.launch(**launch_arguments)
110    context = await browser.new_context()
111    closed = []
112    context.on("close", lambda: closed.append(True))
113    await browser.close()
114    assert closed == [True]
115
116
117async def test_browser_close_should_be_callable_twice(browser_type, launch_arguments):
118    browser = await browser_type.launch(**launch_arguments)
119    await asyncio.gather(
120        browser.close(),
121        browser.close(),
122    )
123    await browser.close()
124
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run Python Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Python on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)