How to use to_have_url method in Playwright Python

Best Python code snippet using playwright-python

base.py

Source:base.py Github

copy

Full Screen

...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"]')...

Full Screen

Full Screen

test_assertions.py

Source:test_assertions.py Github

copy

Full Screen

...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")...

Full Screen

Full Screen

out.py

Source:out.py Github

copy

Full Screen

...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()...

Full Screen

Full Screen

test_password_recovery.py

Source:test_password_recovery.py Github

copy

Full Screen

...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(...

Full Screen

Full Screen

Playwright tutorial

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.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful