Best Python code snippet using playwright-python
_assertions.py
Source:_assertions.py
...493 self._actual = response494 @property495 def _not(self) -> "APIResponseAssertions":496 return APIResponseAssertions(self._actual, not self._is_not)497 async def to_be_ok(498 self,499 ) -> None:500 __tracebackhide__ = True501 if self._is_not is not self._actual.ok:502 return503 message = f"Response status expected to be within [200..299] range, was '{self._actual.status}'"504 if self._is_not:505 message = message.replace("expected to", "expected not to")506 log_list = await self._actual._fetch_log()507 log = "\n".join(log_list).strip()508 if log:509 message += f"\n Call log:\n{log}"510 raise AssertionError(message)511 async def not_to_be_ok(self) -> None:512 __tracebackhide__ = True513 await self._not.to_be_ok()514def expected_regex(515 pattern: Pattern, match_substring: bool, normalize_white_space: bool516) -> ExpectedTextValue:517 expected = ExpectedTextValue(518 regexSource=pattern.pattern,519 regexFlags=escape_regex_flags(pattern),520 matchSubstring=match_substring,521 normalizeWhiteSpace=normalize_white_space,522 )523 return expected524def to_expected_text_values(525 items: Union[List[Pattern], List[str], List[Union[str, Pattern]]],526 match_substring: bool = False,527 normalize_white_space: bool = False,...
test_assertions.py
Source:test_assertions.py
...231 )232 expect(page.locator("div")).to_have_text(re.compile(r"^line2$", re.MULTILINE))233def test_assertions_response_is_ok_pass(page: Page, server: Server) -> None:234 response = page.request.get(server.EMPTY_PAGE)235 expect(response).to_be_ok()236def test_assertions_response_is_ok_pass_with_not(page: Page, server: Server) -> None:237 response = page.request.get(server.PREFIX + "/unknown")238 expect(response).not_to_be_ok()239def test_assertions_response_is_ok_fail(page: Page, server: Server) -> None:240 response = page.request.get(server.PREFIX + "/unknown")241 with pytest.raises(AssertionError) as excinfo:242 expect(response).to_be_ok()243 error_message = str(excinfo.value)244 assert ("â GET " + server.PREFIX + "/unknown") in error_message...
conftest.py
Source:conftest.py
...59 gh_username: str,60 gh_project_name: str) -> dict:61 resource = f'/users/{gh_username}/projects'62 response = gh_context.get(resource)63 expect(response).to_be_ok()64 65 name_match = lambda x: x['name'] == gh_project_name66 filtered = filter(name_match, response.json())67 project = list(filtered)[0]68 assert project69 return project70@pytest.fixture()71def project_columns(72 gh_context: APIRequestContext,73 gh_project: dict) -> list[dict]:74 75 response = gh_context.get(gh_project['columns_url'])76 expect(response).to_be_ok()77 columns = response.json()78 assert len(columns) >= 279 return columns80@pytest.fixture()81def project_column_ids(project_columns: list[dict]) -> list[str]:...
test_github_project.py
Source:test_github_project.py
...18 # Create a new card19 c_response = gh_context.post(20 f'/projects/columns/{project_column_ids[0]}/cards',21 data={'note': note})22 expect(c_response).to_be_ok()23 assert c_response.json()['note'] == note24 # Retrieve the newly created card25 card_id = c_response.json()['id']26 r_response = gh_context.get(f'/projects/columns/cards/{card_id}')27 expect(r_response).to_be_ok()28 assert r_response.json() == c_response.json()29# ------------------------------------------------------------30# A hybrid UI/API test31# ------------------------------------------------------------32def test_move_project_card(33 gh_context: APIRequestContext,34 gh_project: dict,35 project_column_ids: list[str],36 page: Page,37 gh_username: str,38 gh_password: str) -> None:39 # Prep test data40 source_col = project_column_ids[0]41 dest_col = project_column_ids[1]42 now = time.time()43 note = f'Move this card at {now}'44 # Create a new card via API45 c_response = gh_context.post(46 f'/projects/columns/{source_col}/cards',47 data={'note': note})48 expect(c_response).to_be_ok()49 # Log in via UI50 page.goto(f'https://github.com/login')51 page.locator('id=login_field').fill(gh_username)52 page.locator('id=password').fill(gh_password)53 page.locator('input[name="commit"]').click()54 # Load the project page55 page.goto(f'https://github.com/users/{gh_username}/projects/{gh_project["number"]}')56 # Verify the card appears in the first column57 card_xpath = f'//div[@id="column-cards-{source_col}"]//p[contains(text(), "{note}")]'58 expect(page.locator(card_xpath)).to_be_visible()59 # Move a card to the second column via web UI60 page.drag_and_drop(f'text="{note}"', f'id=column-cards-{dest_col}')61 # Verify the card is in the second column via UI62 card_xpath = f'//div[@id="column-cards-{dest_col}"]//p[contains(text(), "{note}")]'63 expect(page.locator(card_xpath)).to_be_visible()64 # Verify the backend is updated via API65 card_id = c_response.json()['id']66 r_response = gh_context.get(f'/projects/columns/cards/{card_id}')67 expect(r_response).to_be_ok()...
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!!