Best Python code snippet using playwright-python
_assertions.py
Source:_assertions.py
...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",...
test_assertions.py
Source:test_assertions.py
...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(...
test_boolean_type.py
Source:test_boolean_type.py
...100def 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)...
test_records.py
Source:test_records.py
...47 cell3 = page.locator(".cell:has-text('6606612') .cell-wrapper")48 cell1.click()49 expect(cell1).to_have_class(re.compile("is-active"))50 page.keyboard.press('ArrowLeft')51 expect(cell1).not_to_have_class(re.compile("is-active"))52 expect(cell2).to_have_class(re.compile("is-active"))53 page.keyboard.press('ArrowRight')54 expect(cell1).to_have_class(re.compile("is-active"))55 expect(cell2).not_to_have_class(re.compile("is-active"))56 page.keyboard.press('ArrowDown')57 expect(cell1).not_to_have_class(re.compile("is-active"))58 expect(cell3).to_have_class(re.compile("is-active"))59 page.keyboard.press('ArrowUp')60 expect(cell1).to_have_class(re.compile("is-active"))...
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!!