Best Python code snippet using playwright-python
_assertions.py
Source:_assertions.py
...143 timeout: float = None,144 ) -> None:145 __tracebackhide__ = True146 await self._not.to_contain_text(expected, use_inner_text, timeout)147 async def to_have_attribute(148 self,149 name: str,150 value: Union[str, Pattern],151 timeout: float = None,152 ) -> None:153 __tracebackhide__ = True154 expected_text = to_expected_text_values([value])155 await self._expect_impl(156 "to.have.attribute",157 FrameExpectOptions(158 expressionArg=name, expectedText=expected_text, timeout=timeout159 ),160 value,161 "Locator expected to have attribute",162 )163 async def not_to_have_attribute(164 self,165 name: str,166 value: Union[str, Pattern],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 )...
base.py
Source:base.py
...48 if current_state == "true":49 pass50 else:51 locator.click()52 expect(locator).to_have_attribute("aria-checked", "true")53 elif set_state is False:54 if current_state == "false":55 pass56 else:57 locator.click()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):...
test_assertions.py
Source:test_assertions.py
...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")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)...
main.py
Source:main.py
...67 for letter in attempt:68 page.press('#game', letter)69 page.press("#game", "Enter")70 locator = page.locator('[data-key="' + attempt[0] + '"]')71 expect(locator).to_have_attribute("data-state",re.compile(r"^(?:absent|present|correct)$"))72 for letter in attempt:73 locator = page.locator('[data-key="' + letter + '"]')74 if locator.get_attribute("data-state") == "absent":75 grey.append(letter)76 elif locator.get_attribute("data-state") == "present":77 amber.append(letter)78 elif locator.get_attribute("data-state") == "correct":79 green.append(letter)80 browser.close()81 return(grey,amber,green)82if __name__ == "__main__":83 with open('wordlist.txt') as file:84 words = file.readlines()85 words = [word.rstrip() for word in words]...
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!!