Skip to content

chore: run the installation tests only with the actual tested browser #1341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
21 changes: 11 additions & 10 deletions tests/assets/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
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("data:text/html,Foobar")
here = Path(__file__).parent.resolve()
page.screenshot(path=here / f"{browser_type.name}.png")
page.close()
browser.close()
def main(playwright: Playwright, browser_name: str) -> None:
browser = playwright[browser_name].launch()
page = browser.new_page()
page.goto("data:text/html,Foobar")
here = Path(__file__).parent.resolve()
page.screenshot(path=here / f"{browser_name}.png")
page.close()
browser.close()


if __name__ == "__main__":
browser_name = sys.argv[1]
with sync_playwright() as p:
main(p)
main(p, browser_name)
12 changes: 6 additions & 6 deletions tests/test_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from venv import EnvBuilder


def test_install(tmp_path: Path) -> None:
def test_install(tmp_path: Path, browser_name: str) -> None:
env = EnvBuilder(with_pip=True)
env.create(env_dir=tmp_path)
context = env.ensure_directories(tmp_path)
Expand All @@ -43,10 +43,10 @@ def test_install(tmp_path: Path) -> None:
environ = os.environ.copy()
environ["PLAYWRIGHT_BROWSERS_PATH"] = str(tmp_path)
subprocess.check_output(
[context.env_exe, "-m", "playwright", "install"], env=environ
[context.env_exe, "-m", "playwright", "install", browser_name], 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()
subprocess.check_output(
[context.env_exe, str(tmp_path / "main.py"), browser_name], env=environ
)
assert (tmp_path / f"{browser_name}.png").exists()