How to use to_contain_text method in Playwright Python

Best Python code snippet using playwright-python

test_boolean_type.py

Source:test_boolean_type.py Github

copy

Full Screen

...20 page.locator(display_tab_selector).click()21 display_as_option_locator = page.locator(display_as_option_selector)22 custom_label_option_locator = page.locator(use_custom_label_option_selector)23 expect(display_as_option_locator).to_be_visible()24 expect(display_as_option_locator).to_contain_text("Checkbox", use_inner_text=True)25 expect(custom_label_option_locator).not_to_be_visible()26 open_column_options_and_verify_type(page, "boolean_dd", "Boolean", "BOOLEAN")27 page.locator(display_tab_selector).click()28 display_as_option_locator = page.locator(display_as_option_selector)29 expect(display_as_option_locator).to_be_visible()30 expect(display_as_option_locator).to_contain_text("Dropdown", use_inner_text=True)31 expect(custom_label_option_locator).to_be_visible()32 assert page.is_checked(use_custom_label_option_selector) is False33def test_boolean_disp_checkbox_to_dropdown(page, table_with_all_types, go_to_all_types_table):34 expect_table_to_open(page)35 open_column_options_and_verify_type(page, "boolean_cb", "Boolean", "BOOLEAN")36 page.locator(display_tab_selector).click()37 display_as_option_locator = page.locator(display_as_option_selector)38 custom_label_option_locator = page.locator(use_custom_label_option_selector)39 expect(display_as_option_locator).to_be_visible()40 expect(display_as_option_locator).to_contain_text("Checkbox", use_inner_text=True)41 expect(custom_label_option_locator).not_to_be_visible()42 change_select_input_value(page, display_as_option_locator, "Dropdown")43 expect(custom_label_option_locator).to_be_visible()44 assert page.is_checked(use_custom_label_option_selector) is False45 page.check(use_custom_label_option_selector)46 true_custom_label_option_locator = page.locator(true_custom_label_option_selector)47 false_custom_label_option_locator = page.locator(false_custom_label_option_selector)48 expect(true_custom_label_option_locator).to_be_visible()49 expect(true_custom_label_option_locator).to_have_value("true")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)...

Full Screen

Full Screen

wait.py

Source:wait.py Github

copy

Full Screen

...16 :class:`~screenpy_selenium.abilities.BrowseTheWeb`17 Examples::18 the_actor.attempts_to(Wait.for_the(LOGIN_FORM))19 the_actor.attempts_to(20 Wait.for_the(WELCOME_BANNER).to_contain_text("Welcome!")21 )22 the_actor.attempts_to(Wait.for(CONFETTI).to_disappear())23 the_actor.attempts_to(24 Wait(10).seconds_for_the(PARADE_FLOATS).to(float_on_by)25 )26 the_actor.attempts_to(27 Wait().using(cookies_to_contain).with_("delicious=true")28 )29 the_actor.attempts_to(30 Wait().using(31 cookies_to_contain, "for a cookie that has {0}"32 ).with_("delicious=true")33 )34 """35 args: Iterable[Any]36 @staticmethod37 def for_the(target: Target) -> "Wait":38 """Set the Target to wait for."""39 return Wait(settings.TIMEOUT, [target])40 for_ = for_the41 def seconds_for_the(self, target: Target) -> "Wait":42 """Set the Target to wait for, after changing the default timeout."""43 self.args = [target]44 return self45 second_for = second_for_the = seconds_for = seconds_for_the46 def using(47 self, strategy: Callable[..., Any], log_detail: Optional[str] = None48 ) -> "Wait":49 """Use the given strategy to wait for the Target.50 Args:51 strategy: the condition to use to wait. This can be one of52 Selenium's Expected Conditions, or any custom Callable53 that returns a boolean.54 log_detail: a nicer-looking message to log than the default.55 You can use {0}, {1}, etc. to reference specific arguments56 passed into .with_() or .for_the().57 """58 self.condition = strategy59 self.log_detail = log_detail60 return self61 to = seconds_using = using62 def with_(self, *args: Any) -> "Wait":63 """Set the arguments to pass in to the wait condition."""64 self.args = args65 return self66 def to_appear(self) -> "Wait":67 """Use Selenium's "visibility of element located" strategy."""68 return self.using(EC.visibility_of_element_located, "for the {0} to appear...")69 def to_be_clickable(self) -> "Wait":70 """Use Selenium's "to be clickable" strategy."""71 return self.using(EC.element_to_be_clickable, "for the {0} to be clickable...")72 def to_disappear(self) -> "Wait":73 """Use Selenium's "invisibility of element located" strategy."""74 return self.using(75 EC.invisibility_of_element_located, "for the {0} to disappear..."76 )77 def to_contain_text(self, text: str) -> "Wait":78 """Use Selenium's "text to be present in element" strategy."""79 return self.using(80 EC.text_to_be_present_in_element, 'for "{1}" to appear in the {0}...'81 ).with_(*self.args, text)82 @property83 def log_message(self) -> str:84 """Format the nice log message, or give back the default."""85 if self.log_detail is None:86 return f"using {self.condition.__name__} with {self.args}"87 return self.log_detail.format(*self.args)88 def describe(self) -> str:89 """Describe the Action in present tense."""90 return f"Wait {self.timeout} seconds {self.log_message}."91 @beat("{} waits up to {timeout} seconds {log_message}")...

Full Screen

Full Screen

table_actions.py

Source:table_actions.py Github

copy

Full Screen

...31 return column_header32def open_column_options(page, column_name, column_type):33 page.click(get_column_header_locator(page, column_name))34 type_option = "button.type-switch"35 expect(page.locator(type_option)).to_contain_text(column_type)36 page.click(type_option)37 expect(page.locator(".type-list li.selected")).to_contain_text(column_type)38def open_column_options_and_verify_type(page, column_name, column_type, db_type):39 open_column_options(page, column_name, column_type)40 db_type_text = f"Database type {db_type}"41 expect(page.locator(".type-options-content")).to_contain_text(db_type_text, use_inner_text=True)42def get_cell_selector(page, table, row_number, column_name):43 column_names_to_ids = table.get_column_name_id_bidirectional_map()44 column_id = column_names_to_ids[column_name]45 row_selector = f".table-content .row:has(.row-control .control .number:text('{row_number}'))"46 cell_selector = f"{row_selector} .cell:has([data-column-id='{column_id}'])"47 cell_locator = page.locator(cell_selector)48 expect(cell_locator).to_be_visible()...

Full Screen

Full Screen

test_key_presses.py

Source:test_key_presses.py Github

copy

Full Screen

...27 Perry = self.actor28 given(Perry).was_able_to(Open.their_browser_on(URL))29 when(Perry).attempts_to(30 Enter.the_text(test_text).into_the(ENTRY_INPUT),31 Wait.for_the(RESULT_TEXT).to_contain_text(test_text),32 )33 then(Perry).should(34 See.the(Text.of_the(RESULT_TEXT), ReadsExactly(f"You entered: {test_text}"))35 )36 @act("Perform")37 @scene("Wait with custom")38 def test_wait_with_custom(self) -> None:39 """Can wait using a contrived custom wait function."""40 test_text = "H"41 Perry = self.actor42 def text_to_have_all(43 locator: Tuple[str, str], preamble: str, body: str, suffix: str44 ) -> Callable:45 """A very contrived custom condition."""...

Full Screen

Full Screen

Playwright tutorial

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.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful