Best Python code snippet using playwright-python
_assertions.py
Source: _assertions.py
...167 timeout: float = None,168 ) -> None:169 __tracebackhide__ = True170 await self._not.to_have_attribute(name, value, timeout)171 async def to_have_class(172 self,173 expected: Union[List[Union[Pattern, str]], Pattern, str],174 timeout: float = None,175 ) -> None:176 __tracebackhide__ = True177 if isinstance(expected, list):178 expected_text = to_expected_text_values(expected)179 await self._expect_impl(180 "to.have.class.array",181 FrameExpectOptions(expectedText=expected_text, timeout=timeout),182 expected,183 "Locator expected to have class",184 )185 else:186 expected_text = to_expected_text_values([expected])187 await self._expect_impl(188 "to.have.class",189 FrameExpectOptions(expectedText=expected_text, timeout=timeout),190 expected,191 "Locator expected to have class",192 )193 async def not_to_have_class(194 self,195 expected: Union[List[Union[Pattern, str]], Pattern, str],196 timeout: float = None,197 ) -> None:198 __tracebackhide__ = True199 await self._not.to_have_class(expected, timeout)200 async def to_have_count(201 self,202 count: int,203 timeout: float = None,204 ) -> None:205 __tracebackhide__ = True206 await self._expect_impl(207 "to.have.count",208 FrameExpectOptions(expectedNumber=count, timeout=timeout),209 count,210 "Locator expected to have count",211 )212 async def not_to_have_count(213 self,...
test_assertions.py
Source: test_assertions.py
...86 expect(page.locator("div#foobar")).to_have_attribute("id", re.compile("foobar"))87 expect(page.locator("div#foobar")).not_to_have_attribute("id", "kek", timeout=100)88 with pytest.raises(AssertionError):89 expect(page.locator("div#foobar")).to_have_attribute("id", "koko", timeout=100)90def test_assertions_locator_to_have_class(page: Page, server: Server) -> None:91 page.goto(server.EMPTY_PAGE)92 page.set_content("<div class=foobar>kek</div>")93 expect(page.locator("div.foobar")).to_have_class("foobar")94 expect(page.locator("div.foobar")).to_have_class(["foobar"])95 expect(page.locator("div.foobar")).to_have_class(re.compile("foobar"))96 expect(page.locator("div.foobar")).to_have_class([re.compile("foobar")])97 expect(page.locator("div.foobar")).not_to_have_class("kekstar", timeout=100)98 with pytest.raises(AssertionError):99 expect(page.locator("div.foobar")).to_have_class("oh-no", timeout=100)100def test_assertions_locator_to_have_count(page: Page, server: Server) -> None:101 page.goto(server.EMPTY_PAGE)102 page.set_content("<div class=foobar>kek</div><div class=foobar>kek</div>")103 expect(page.locator("div.foobar")).to_have_count(2)104 expect(page.locator("div.foobar")).not_to_have_count(42, timeout=100)105 with pytest.raises(AssertionError):106 expect(page.locator("div.foobar")).to_have_count(42, timeout=100)107def test_assertions_locator_to_have_css(page: Page, server: Server) -> None:108 page.goto(server.EMPTY_PAGE)109 page.set_content("<div class=foobar style='color: rgb(234, 74, 90);'>kek</div>")110 expect(page.locator("div.foobar")).to_have_css("color", "rgb(234, 74, 90)")111 expect(page.locator("div.foobar")).not_to_have_css(112 "color", "rgb(42, 42, 42)", timeout=100113 )...
test_boolean_type.py
Source: test_boolean_type.py
...50 expect(false_custom_label_option_locator).to_be_visible()51 expect(false_custom_label_option_locator).to_have_value("false")52 page.fill(false_custom_label_option_selector, "")53 expect(page.locator(".type-options-content")).to_contain_text("This is a required field", use_inner_text=True)54 expect(false_custom_label_option_locator).to_have_class(re.compile("has-error"))55 page.fill(true_custom_label_option_selector, "Truthy Value")56 page.fill(false_custom_label_option_selector, "Falsy Value")57 page.click("button:has-text('Save')")58 expect(page.locator(".dropdown.column-opts-content")).not_to_be_visible()59 second_row_cell_selector = get_cell_selector(page, table_with_all_types, 2, "boolean_cb")60 expect(page.locator(second_row_cell_selector)).to_contain_text("Truthy Value", use_inner_text=True)61 third_row_cell_selector = get_cell_selector(page, table_with_all_types, 3, "boolean_cb")62 expect(page.locator(third_row_cell_selector)).to_contain_text("Falsy Value", use_inner_text=True)63def test_boolean_disp_dropdown_to_checkbox(page, table_with_all_types, go_to_all_types_table):64 expect_table_to_open(page)65 open_column_options_and_verify_type(page, "boolean_dd", "Boolean", "BOOLEAN")66 page.locator(display_tab_selector).click()67 display_as_option_locator = page.locator(display_as_option_selector)68 custom_label_option_locator = page.locator(use_custom_label_option_selector)69 expect(display_as_option_locator).to_be_visible()70 expect(display_as_option_locator).to_contain_text("Dropdown", use_inner_text=True)71 expect(custom_label_option_locator).to_be_visible()72 change_select_input_value(page, display_as_option_locator, "Checkbox")73 expect(custom_label_option_locator).not_to_be_visible()74 page.click("button:has-text('Save')")75 expect(page.locator(".dropdown.column-opts-content")).not_to_be_visible()76 second_row_cell_selector = get_cell_selector(page, table_with_all_types, 2, "boolean_dd")77 second_row_checkbox_selector = f"{second_row_cell_selector} [type=checkbox]"78 assert page.is_checked(second_row_checkbox_selector) is True79 third_row_cell_selector = get_cell_selector(page, table_with_all_types, 3, "boolean_dd")80 third_row_checkbox_selector = f"{third_row_cell_selector} [type=checkbox]"81 assert page.is_checked(third_row_checkbox_selector) is False82def test_boolean_cell_checkbox_input(page, table_with_all_types, go_to_all_types_table):83 expect_table_to_open(page)84 first_row_cell_selector = get_cell_selector(page, table_with_all_types, 1, "boolean_cb")85 first_row_checkbox_selector = f"{first_row_cell_selector} [type=checkbox]"86 assert page.locator(first_row_checkbox_selector).element_handle().evaluate("node => node.indeterminate") is True87 page.check(first_row_checkbox_selector)88 assert page.locator(first_row_checkbox_selector).element_handle().evaluate("node => node.indeterminate") is False89 assert page.is_checked(first_row_checkbox_selector) is True90 page.uncheck(first_row_checkbox_selector)91 assert page.is_checked(first_row_checkbox_selector) is False92 page.check(first_row_checkbox_selector)93 assert page.is_checked(first_row_checkbox_selector) is True94 second_row_cell_selector = get_cell_selector(page, table_with_all_types, 2, "boolean_cb")95 second_row_checkbox_selector = f"{second_row_cell_selector} [type=checkbox]"96 assert page.is_checked(second_row_checkbox_selector) is True97 third_row_cell_selector = get_cell_selector(page, table_with_all_types, 3, "boolean_cb")98 third_row_checkbox_selector = f"{third_row_cell_selector} [type=checkbox]"99 assert page.is_checked(third_row_checkbox_selector) is False100def test_boolean_cell_checkbox_click_behavior(page, table_with_all_types, go_to_all_types_table):101 expect_table_to_open(page)102 cell_selector = get_cell_selector(page, table_with_all_types, 1, "boolean_cb")103 checkbox_selector = f"{cell_selector} [type=checkbox]"104 expect(page.locator(cell_selector)).not_to_have_class(re.compile("is-active"))105 assert page.locator(checkbox_selector).element_handle().evaluate("node => node.indeterminate") is True106 page.click(cell_selector)107 expect(page.locator(cell_selector)).to_have_class(re.compile("is-active"))108 assert page.locator(checkbox_selector).element_handle().evaluate("node => node.indeterminate") is True109 page.click(cell_selector)110 assert page.is_checked(checkbox_selector) is True111 page.click(cell_selector)112 assert page.is_checked(checkbox_selector) is False113def test_boolean_cell_checkbox_key_behavior(page, table_with_all_types, go_to_all_types_table):114 expect_table_to_open(page)115 cell_selector = get_cell_selector(page, table_with_all_types, 1, "boolean_cb")116 checkbox_selector = f"{cell_selector} [type=checkbox]"117 page.click(cell_selector)118 expect(page.locator(cell_selector)).to_have_class(re.compile("is-active"))119 assert page.locator(checkbox_selector).element_handle().evaluate("node => node.indeterminate") is True120 page.keyboard.press("Enter")121 assert page.is_checked(checkbox_selector) is True122 page.keyboard.press("Enter")123 assert page.is_checked(checkbox_selector) is False124def test_boolean_cell_dropdown_input(page, table_with_all_types, go_to_all_types_table):125 expect_table_to_open(page)126 first_row_cell_selector = get_cell_selector(page, table_with_all_types, 1, "boolean_dd")127 first_row_cell_locator = page.locator(first_row_cell_selector)128 expect(first_row_cell_locator).to_contain_text("NULL", use_inner_text=True)129 expect(first_row_cell_locator).not_to_have_class(re.compile("is-active"))130 page.click(first_row_cell_selector)131 expect(first_row_cell_locator).to_have_class(re.compile("is-active"))132 dropdown_id = page.locator(f"{first_row_cell_selector} .cell-wrapper").get_attribute("aria-controls")133 dropdown_selector = f".dropdown.single-select-cell-dropdown:has(ul#{dropdown_id})"134 expect(page.locator(dropdown_selector)).not_to_be_visible()135 page.click(first_row_cell_selector)136 expect(page.locator(f"{first_row_cell_selector} .cell-wrapper")).to_be_focused()137 expect(page.locator(dropdown_selector)).to_be_visible()138 expect(page.locator(f"{dropdown_selector} li")).to_contain_text(["true", "false"])139 page.click(f"{dropdown_selector} li:has-text('true')")140 expect(page.locator(dropdown_selector)).not_to_be_visible()141 expect(first_row_cell_locator).to_contain_text("true", use_inner_text=True)142 expect(page.locator(f"{first_row_cell_selector} .cell-wrapper")).to_be_focused()143 page.click(first_row_cell_selector)144 expect(page.locator(dropdown_selector)).to_be_visible()145 page.click(f"{dropdown_selector} li:has-text('false')")146 expect(page.locator(dropdown_selector)).not_to_be_visible()147 expect(first_row_cell_locator).to_contain_text("false", use_inner_text=True)148 expect(page.locator(f"{first_row_cell_selector} .cell-wrapper")).to_be_focused()149 second_row_cell_selector = get_cell_selector(page, table_with_all_types, 2, "boolean_dd")150 expect(page.locator(second_row_cell_selector)).to_contain_text("true", use_inner_text=True)151 third_row_cell_selector = get_cell_selector(page, table_with_all_types, 3, "boolean_dd")152 expect(page.locator(third_row_cell_selector)).to_contain_text("false", use_inner_text=True)153def test_boolean_cell_dropdown_key_behavior(page, table_with_all_types, go_to_all_types_table):154 expect_table_to_open(page)155 cell_selector = get_cell_selector(page, table_with_all_types, 1, "boolean_dd")156 cell_locator = page.locator(cell_selector)157 page.click(cell_selector)158 expect(cell_locator).to_have_class(re.compile("is-active"))159 dropdown_id = page.locator(f"{cell_selector} .cell-wrapper").get_attribute("aria-controls")160 dropdown_selector = f".dropdown.single-select-cell-dropdown:has(ul#{dropdown_id})"161 expect(page.locator(dropdown_selector)).not_to_be_visible()162 expect(page.locator(f"{cell_selector} .cell-wrapper")).to_be_focused()163 page.keyboard.press("Enter")164 expect(page.locator(dropdown_selector)).to_be_visible()165 page.keyboard.press("ArrowDown")166 page.keyboard.press("Enter")167 expect(page.locator(dropdown_selector)).not_to_be_visible()168 expect(cell_locator).to_contain_text("true", use_inner_text=True)...
test_text_type.py
Source: test_text_type.py
...28 open_and_verify_column_type(page, "varchar", "VARCHAR")29 expect(page.locator(restrict_field_size_option_locator)).to_be_checked()30 field_size_input = page.locator(field_size_limit_locator)31 expect(field_size_input).to_be_visible()32 expect(field_size_input).to_have_class(re.compile("has-error"))33 expect(field_size_input).to_be_empty()34 expect(page.locator(".type-options-content")).to_contain_text("This is a required field", use_inner_text=True)35def test_varchar_n_options(page, go_to_all_types_table):36 expect_table_to_open(page)37 open_and_verify_column_type(page, "varchar_n", "VARCHAR")38 expect(page.locator(restrict_field_size_option_locator)).to_be_checked()39 field_size_input = page.locator(field_size_limit_locator)40 expect(field_size_input).to_be_visible()41 expect(field_size_input).to_have_value("100")42def test_char_options(page, go_to_all_types_table):43 expect_table_to_open(page)44 open_and_verify_column_type(page, "char", "CHAR")45 expect(page.locator(restrict_field_size_option_locator)).to_be_checked()46 field_size_input = page.locator(field_size_limit_locator)...
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!!