Skip to content

Commit d280b93

Browse files
authored
chore: run the installation tests only with the actual tested browser (#1341)
1 parent 7db9d6b commit d280b93

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

tests/assets/client.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import sys
1516
from pathlib import Path
1617

1718
from playwright.sync_api import Playwright, sync_playwright
1819

1920

20-
def main(playwright: Playwright) -> None:
21-
for browser_type in [playwright.chromium, playwright.firefox, playwright.webkit]:
22-
browser = browser_type.launch()
23-
page = browser.new_page()
24-
page.goto("data:text/html,Foobar")
25-
here = Path(__file__).parent.resolve()
26-
page.screenshot(path=here / f"{browser_type.name}.png")
27-
page.close()
28-
browser.close()
21+
def main(playwright: Playwright, browser_name: str) -> None:
22+
browser = playwright[browser_name].launch()
23+
page = browser.new_page()
24+
page.goto("data:text/html,Foobar")
25+
here = Path(__file__).parent.resolve()
26+
page.screenshot(path=here / f"{browser_name}.png")
27+
page.close()
28+
browser.close()
2929

3030

3131
if __name__ == "__main__":
32+
browser_name = sys.argv[1]
3233
with sync_playwright() as p:
33-
main(p)
34+
main(p, browser_name)

tests/test_installation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from venv import EnvBuilder
2121

2222

23-
def test_install(tmp_path: Path) -> None:
23+
def test_install(tmp_path: Path, browser_name: str) -> None:
2424
env = EnvBuilder(with_pip=True)
2525
env.create(env_dir=tmp_path)
2626
context = env.ensure_directories(tmp_path)
@@ -43,10 +43,10 @@ def test_install(tmp_path: Path) -> None:
4343
environ = os.environ.copy()
4444
environ["PLAYWRIGHT_BROWSERS_PATH"] = str(tmp_path)
4545
subprocess.check_output(
46-
[context.env_exe, "-m", "playwright", "install"], env=environ
46+
[context.env_exe, "-m", "playwright", "install", browser_name], env=environ
4747
)
4848
shutil.copyfile(root / "tests" / "assets" / "client.py", tmp_path / "main.py")
49-
subprocess.check_output([context.env_exe, str(tmp_path / "main.py")], env=environ)
50-
assert (tmp_path / "chromium.png").exists()
51-
assert (tmp_path / "firefox.png").exists()
52-
assert (tmp_path / "webkit.png").exists()
49+
subprocess.check_output(
50+
[context.env_exe, str(tmp_path / "main.py"), browser_name], env=environ
51+
)
52+
assert (tmp_path / f"{browser_name}.png").exists()

0 commit comments

Comments
 (0)