From ee92bf4d1a204127b76795219f51b97fb6f29ede Mon Sep 17 00:00:00 2001 From: Dominik Klein Date: Thu, 29 Oct 2026 11:13:19 +0100 Subject: [PATCH] Match the whole text in to_have_text --- development/generate_api/example_codes.rb | 2 +- documentation/docs/api/locator_assertions.md | 2 +- lib/playwright/locator_assertions_impl.rb | 2 -- spec/integration/assertions_spec.rb | 17 +++++++++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/development/generate_api/example_codes.rb b/development/generate_api/example_codes.rb index ddda3bb2..c41af1b7 100644 --- a/development/generate_api/example_codes.rb +++ b/development/generate_api/example_codes.rb @@ -1274,7 +1274,7 @@ def example_622cccefcda0bf4d35e338d1bf0c045f64815fc8b81a4792506a912e3e1abf3c(pag def example_eff0600f575bf375d7372280ca8e6dfc51d927ced49fbcb75408c894b9e0564e(page:) page.content = <<~HTML
Pending
- + HTML page.get_by_role("button").click diff --git a/documentation/docs/api/locator_assertions.md b/documentation/docs/api/locator_assertions.md index 03b8c90c..ac5032bb 100644 --- a/documentation/docs/api/locator_assertions.md +++ b/documentation/docs/api/locator_assertions.md @@ -19,7 +19,7 @@ Since the matcher comes with auto-waiting feature, we don't have to describe tri ```ruby page.content = <<~HTML
Pending
- + HTML page.get_by_role("button").click diff --git a/lib/playwright/locator_assertions_impl.rb b/lib/playwright/locator_assertions_impl.rb index 787f35de..b7dcbb22 100644 --- a/lib/playwright/locator_assertions_impl.rb +++ b/lib/playwright/locator_assertions_impl.rb @@ -423,7 +423,6 @@ def to_have_text(expected, ignoreCase: nil, timeout: nil, useInnerText: nil) if expected.respond_to?(:each) expected_text = to_expected_text_values( expected, - match_substring: true, normalize_white_space: true, ignore_case: ignoreCase, ) @@ -441,7 +440,6 @@ def to_have_text(expected, ignoreCase: nil, timeout: nil, useInnerText: nil) else expected_text = to_expected_text_values( [expected], - match_substring: true, normalize_white_space: true, ignore_case: ignoreCase, ) diff --git a/spec/integration/assertions_spec.rb b/spec/integration/assertions_spec.rb index 848fc183..d9bf44a5 100644 --- a/spec/integration/assertions_spec.rb +++ b/spec/integration/assertions_spec.rb @@ -585,6 +585,23 @@ def setup_page(page, aria_invalid_value) end end + it "should not match a substring" do + with_page do |page| + page.goto(server_empty_page) + page.set_content("
Text content
") + expect(page.locator("div")).to not_have_text("Text") + expect { + expect(page.locator("div")).to have_text("Text", timeout: 300) + }.to raise_error(RSpec::Expectations::ExpectationNotMetError) + + page.set_content("") + expect(page.locator("li")).to contain_text(["Text 1", "Text 2", "Text"]) + expect { + expect(page.locator("li")).to have_text(["Text 1", "Text 2", "Text"], timeout: 300) + }.to raise_error(RSpec::Expectations::ExpectationNotMetError) + end + end + it "should ignore case" do with_page do |page| page.goto(server_empty_page)