Best Python code snippet using playwright-python
_assertions.py
Source: _assertions.py
...56 self._actual_page = page57 @property58 def _not(self) -> "PageAssertions":59 return PageAssertions(self._actual_page, not self._is_not)60 async def to_have_title(61 self, title_or_reg_exp: Union[Pattern, str], timeout: float = None62 ) -> None:63 expected_values = to_expected_text_values(64 [title_or_reg_exp], normalize_white_space=True65 )66 __tracebackhide__ = True67 await self._expect_impl(68 "to.have.title",69 FrameExpectOptions(expectedText=expected_values, timeout=timeout),70 title_or_reg_exp,71 "Page title expected to be",72 )73 async def not_to_have_title(74 self, title_or_reg_exp: Union[Pattern, str], timeout: float = None75 ) -> None:76 __tracebackhide__ = True77 await self._not.to_have_title(title_or_reg_exp, timeout)78 async def to_have_url(79 self, url_or_reg_exp: Union[str, Pattern], timeout: float = None80 ) -> None:81 __tracebackhide__ = True82 base_url = self._actual_page.context._options.get("baseURL")83 if isinstance(url_or_reg_exp, str) and base_url:84 url_or_reg_exp = urljoin(base_url, url_or_reg_exp)85 expected_text = to_expected_text_values([url_or_reg_exp])86 await self._expect_impl(87 "to.have.url",88 FrameExpectOptions(expectedText=expected_text, timeout=timeout),89 url_or_reg_exp,90 "Page URL expected to be",91 )...
base.py
Source: base.py
...58 expect(locator).to_have_attribute("aria-checked", "false")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):...
test_assertions.py
Source: test_assertions.py
...15from datetime import datetime16import pytest17from playwright.sync_api import Browser, Page, expect18from tests.server import Server19def test_assertions_page_to_have_title(page: Page, server: Server) -> None:20 page.goto(server.EMPTY_PAGE)21 page.set_content("<title>new title</title>")22 expect(page).to_have_title("new title")23 expect(page).to_have_title(re.compile("new title"))24 with pytest.raises(AssertionError):25 expect(page).to_have_title("not the current title", timeout=100)26 with pytest.raises(AssertionError):27 expect(page).to_have_title(re.compile("not the current title"), timeout=100)28 with pytest.raises(AssertionError):29 expect(page).not_to_have_title(re.compile("new title"), timeout=100)30 with pytest.raises(AssertionError):31 expect(page).not_to_have_title("new title", timeout=100)32 expect(page).not_to_have_title("great title", timeout=100)33 page.evaluate(34 """35 setTimeout(() => {36 document.title = 'great title';37 }, 2000);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 """...
test_search.py
Source: test_search.py
...33 expect(result_page.search_input).to_have_value(phrase)34 # And the search result links pertain to the phrase35 assert result_page.result_link_titles_contain_phrase(phrase)36 # And the search result title contains the phrase...
Playwright error connection refused in docker
playwright-python advanced setup
How to select an input according to a parent sibling label
Error when installing Microsoft Playwright
Trouble waiting for changes to complete that are triggered by Python Playwright `select_option`
Capturing and Storing Request Data Using Playwright for Python
Can Playwright be used to launch a browser instance
Trouble in Clicking on Log in Google Button of Pop Up Menu Playwright Python
Scrapy Playwright get date by clicking button
React locator example
I solved my problem. In fact my docker container (frontend) is called "app" which is also domain name of fronend application. My application is running locally on http. Chromium and geko drivers force httpS connection for some domain names one of which is "app". So i have to change name for my docker container wich contains frontend application.
Check out the latest blogs from LambdaTest on this topic:
The sky’s the limit (and even beyond that) when you want to run test automation. Technology has developed so much that you can reduce time and stay more productive than you used to 10 years ago. You needn’t put up with the limitations brought to you by Selenium if that’s your go-to automation testing tool. Instead, you can pick from various test automation frameworks and tools to write effective test cases and run them successfully.
When it comes to web automation testing, there are a number of frameworks like Selenium, Cypress, PlayWright, Puppeteer, etc., that make it to the ‘preferred list’ of frameworks. The choice of test automation framework depends on a range of parameters like type, complexity, scale, along with the framework expertise available within the team. However, it’s no surprise that Selenium is still the most preferred framework among developers and QAs.
Playwright is a framework that I’ve always heard great things about but never had a chance to pick up until earlier this year. And since then, it’s become one of my favorite test automation frameworks to use when building a new automation project. It’s easy to set up, feature-packed, and one of the fastest, most reliable frameworks I’ve worked with.
The speed at which tests are executed and the “dearth of smartness” in testing are the two major problems developers and testers encounter.
With the rapidly evolving technology due to its ever-increasing demand in today’s world, Digital Security has become a major concern for the Software Industry. There are various ways through which Digital Security can be achieved, Captcha being one of them.Captcha is easy for humans to solve but hard for “bots” and other malicious software to figure out. However, Captcha has always been tricky for the testers to automate, as many of them don’t know how to handle captcha in Selenium or using any other test automation framework.
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!!