Best Python code snippet using playwright-python
base.py
Source:base.py
...59class Path(Base):60 def home(self):61 self.page.goto('/', wait_until="networkidle")62 expect(self.page).to_have_title("Home | Colorful")63 expect(self.page).to_have_url("https://www.colorful.app/")64 def showcase(self):65 self.page.goto('/showcases/showcase', wait_until="networkidle")66 expect(self.page).to_have_title("colorful.app")67 expect(self.page).to_have_url("https://www.colorful.app/showcases/showcase")68 def packshot_generator(self):69 self.page.goto('https://packshot.colorful.app/', wait_until="networkidle")70 expect(self.page).to_have_title("Colorful - Create realistic packshots using a 3D model")71 expect(self.page).to_have_url("https://packshot.colorful.app/")72 def careers(self):73 self.page.goto('/careers', wait_until="networkidle")74 expect(self.page).to_have_title("Careers")75 expect(self.page).to_have_url("https://www.colorful.app/careers")76class Background(Base):77 @property78 def colorpicker(self):79 return self.page.locator(".chrome-picker ")80 @property81 def bg_button(self):82 locator = self.page.locator('.w-10') # rework83 return self.get_visible_element(locator)84 def open_colorpicker(self):85 if not self.colorpicker.is_visible():86 self.bg_button.click()87 self.colorpicker.wait_for(state="visible")88 def close_colorpicker(self):89 overlay = self.page.locator('[id="headlessui-portal-root"] >> [role="dialog"]')...
test_assertions.py
Source:test_assertions.py
...38 """39 )40 expect(page).to_have_title("great title")41 expect(page).to_have_title(re.compile("great title"))42def test_assertions_page_to_have_url(page: Page, server: Server) -> None:43 page.goto(server.EMPTY_PAGE)44 expect(page).to_have_url(server.EMPTY_PAGE)45 expect(page).to_have_url(re.compile(r".*/empty\.html"))46 with pytest.raises(AssertionError):47 expect(page).to_have_url("nooooo", timeout=100)48 with pytest.raises(AssertionError):49 expect(page).to_have_url(re.compile("not-the-url"), timeout=100)50 page.evaluate(51 """52 setTimeout(() => {53 window.location = window.location.origin + '/grid.html';54 }, 2000);55 """56 )57 expect(page).to_have_url(server.PREFIX + "/grid.html")58 expect(page).not_to_have_url(server.EMPTY_PAGE, timeout=100)59 with pytest.raises(AssertionError):60 expect(page).not_to_have_url(re.compile(r".*/grid\.html"), timeout=100)61 with pytest.raises(AssertionError):62 expect(page).not_to_have_url(server.PREFIX + "/grid.html", timeout=100)63 expect(page).to_have_url(re.compile(r".*/grid\.html"))64 expect(page).not_to_have_url("**/empty.html", timeout=100)65def test_assertions_page_to_have_url_with_base_url(66 browser: Browser, server: Server67) -> None:68 page = browser.new_page(base_url=server.PREFIX)69 page.goto("/empty.html")70 expect(page).to_have_url("/empty.html")71 expect(page).to_have_url(re.compile(r".*/empty\.html"))72 page.close()73def test_assertions_locator_to_contain_text(page: Page, server: Server) -> None:74 page.goto(server.EMPTY_PAGE)75 page.set_content("<div id=foobar>kek</div>")76 expect(page.locator("div#foobar")).to_contain_text("kek")77 expect(page.locator("div#foobar")).not_to_contain_text("bar", timeout=100)78 with pytest.raises(AssertionError):79 expect(page.locator("div#foobar")).to_contain_text("bar", timeout=100)80 page.set_content("<div>Text \n1</div><div>Text2</div><div>Text3</div>")81 expect(page.locator("div")).to_contain_text(["ext 1", re.compile("ext3")])82def test_assertions_locator_to_have_attribute(page: Page, server: Server) -> None:83 page.goto(server.EMPTY_PAGE)84 page.set_content("<div id=foobar>kek</div>")85 expect(page.locator("div#foobar")).to_have_attribute("id", "foobar")...
out.py
Source:out.py
...7 # Go to https://usegalaxy.eu/8 page.goto("https://usegalaxy.eu/")9 # Click text=Login or Register10 page.locator("text=Login or Register").click()11 # expect(page).to_have_url("https://usegalaxy.eu/login")12 # Click input[name="login"]13 page.locator("input[name=\"login\"]").click()14 # Fill input[name="login"]15 page.locator("input[name=\"login\"]").fill("hxr@informatik.uni-freiburg.de")16 # Click input[name="password"]17 page.locator("input[name=\"password\"]").click()18 # Fill input[name="password"]19 page.locator("input[name=\"password\"]").fill("wswTKY3Rem5knnWTakuNzrBbZ9")20 # Click button:has-text("Login")21 # with page.expect_navigation(url="https://usegalaxy.eu/"):22 with page.expect_navigation():23 page.locator("button:has-text(\"Login\")").click()24 # Click #history-new-button span25 page.locator("#history-new-button span").click()26 # Click [aria-label="Download from URL or upload files from disk"]27 page.locator("[aria-label=\"Download from URL or upload files from disk\"]").click()28 # Fill text=Name Size Type Genome Settings Status Download data from the web by entering URL >> textarea29 page.locator("text=Name Size Type Genome Settings Status Download data from the web by entering URL >> textarea").fill("https://zenodo.org/record/1156405/files/contigs.fasta\n")30 # Press Escape31 page.locator("body:has-text(\"Galaxy Europe Workflow Visualize Shared Data Data Libraries Histories Workflows \")").press("Escape")32 # Click #current-history-panel div:has-text("1 contigs.fasta") >> nth=133 page.locator("#current-history-panel div:has-text(\"1 contigs.fasta\")").nth(1).click()34 # Click [placeholder="search tools"]35 page.locator("[placeholder=\"search tools\"]").click()36 # Fill [placeholder="search tools"]37 page.locator("[placeholder=\"search tools\"]").fill("prokka")38 # Press Enter39 page.locator("[placeholder=\"search tools\"]").press("Enter")40 # Click text=Prokaryotic genome annotation41 page.locator("text=Prokaryotic genome annotation").click()42 # expect(page).to_have_url("https://usegalaxy.eu/")43 # Click span:has-text("1: contigs.fasta")44 page.locator("span:has-text(\"1: contigs.fasta\")").click()45 # Click div[role="option"]:has-text("1: contigs.fasta")46 page.locator("div[role=\"option\"]:has-text(\"1: contigs.fasta\")").click()47 # Click button:has-text("Execute")48 page.locator("button:has-text(\"Execute\")").click()49 # Click text=Unnamed history50 page.locator("text=Unnamed history").click()51 # Fill text=13 shown178.93 KBYou are over your disk quota. Tool execution is on hold until y >> input[type="text"] >> nth=152 page.locator("text=13 shown178.93 KBYou are over your disk quota. Tool execution is on hold until y >> input[type=\"text\"]").nth(1).fill("Playwright Prokka Test")53 # Press Enter54 page.locator("text=13 shown178.93 KBYou are over your disk quota. Tool execution is on hold until y >> input[type=\"text\"]").nth(1).press("Enter")55 # Click #dataset-4838ba20a6d867650bf94871f40d260a .primary-actions .icon-btn.display-btn .fa56 page.locator("#dataset-4838ba20a6d867650bf94871f40d260a .primary-actions .icon-btn.display-btn .fa").click()...
test_password_recovery.py
Source:test_password_recovery.py
...8 with page.expect_navigation():9 page.locator("[data-test=\"button-accept-all-in-general\"]").click()10 # Click [data-test="section-desktopLayout"] [data-test="anchor-login"]11 page.locator("[data-test=\"section-desktopLayout\"] [data-test=\"anchor-login\"]").click()12 # expect(page).to_have_url("https://login.pracuj.pl/")13 # Click text=ZapomniaÅeÅ hasÅa?14 page.locator("text=ZapomniaÅeÅ hasÅa?").click()15 # expect(page).to_have_url("https://login.pracuj.pl/przypomnij-haslo")16 # Click [data-test="button-forgot-password"]17 page.locator("[data-test=\"button-forgot-password\"]").click()18 # Click [data-test="validation-summary-errors"]19 page.locator("[data-test=\"validation-summary-errors\"]").click()20 assert page.inner_text(21 "[data-test=\"validation-summary-errors\"]") == r'WypeÅnij to pole.'22def test_login_correct(page):23 # Go to https://www.pracuj.pl/24 page.goto("/")25 # Click [data-test="button-accept-all-in-general"]26 # with page.expect_navigation(url="https://www.pracuj.pl/"):27 with page.expect_navigation():28 page.locator("[data-test=\"button-accept-all-in-general\"]").click()29 # Click [data-test="section-desktopLayout"] [data-test="anchor-login"]30 page.locator("[data-test=\"section-desktopLayout\"] [data-test=\"anchor-login\"]").click()31 # expect(page).to_have_url("https://login.pracuj.pl/")32 # Click text=ZapomniaÅeÅ hasÅa?33 page.locator("text=ZapomniaÅeÅ hasÅa?").click()34 # expect(page).to_have_url("https://login.pracuj.pl/przypomnij-haslo")35 # Click [data-test="input-forgot-password-email"]36 page.locator("[data-test=\"input-forgot-password-email\"]").click()37 # Fill [data-test="input-forgot-password-email"]38 page.locator("[data-test=\"input-forgot-password-email\"]").fill("bond47647@gmail.com")39 # Click [data-test="button-forgot-password"]40 page.locator("[data-test=\"button-forgot-password\"]").click()41 assert page.inner_text(...
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!