Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Regex flags (RegexOptions) ignored when passed to ILocatorAssertions.ToHaveAttributeAsync() #2581

Closed
cjohnson opened this issue May 18, 2023 · 1 comment · Fixed by #2626
Assignees
Labels

Comments

@cjohnson
Copy link

Context:

  • Playwright Version: 1.33.0
  • Operating System: Windows
  • .NET version: .NET 6
  • Browser: All

Code Snippet

public async Task ShouldSupportToHaveAttributeByRegexAsync()
{
    await Page.SetContentAsync("<img src=\"https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?queryString=true\"/>");
    await Expect(Page.Locator("img")).ToHaveAttributeAsync("src", new Regex("https://playwright.dev/media/photo", RegexOptions.IgnoreCase));
}

Stack Trace

Failed ShouldSupportToHaveAttributeByRegexAsync [7 s]
  Error Message:
   Microsoft.Playwright.PlaywrightException : Locator expected to have attribute 'src' matching regex 'https://playwright.dev/media/photo'
But was: 'https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?queryString=true'
Call log:
LocatorAssertions.ToHaveAttributeAsync with timeout 5000ms
waiting for Locator("img")
  locator resolved to <img src="https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?quer./>
  unexpected value "https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?queryString=true"
  locator resolved to <img src="https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?quer./>
  unexpected value "https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?queryString=true"
  locator resolved to <img src="https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?quer./>
  unexpected value "https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?queryString=true"
  locator resolved to <img src="https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?quer./>
  unexpected value "https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?queryString=true"
  locator resolved to <img src="https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?quer./>
  unexpected value "https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?queryString=true"
  locator resolved to <img src="https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?quer./>
  unexpected value "https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?queryString=true"
  locator resolved to <img src="https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?quer./>
  unexpected value "https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?queryString=true"
  locator resolved to <img src="https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?quer./>
  unexpected value "https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?queryString=true"
  locator resolved to <img src="https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?quer./>
  unexpected value "https://PLAYWRIGHT.dEV/mEDIa/photo.JPG?queryString=true"
  Stack Trace:
     at Microsoft.Playwright.Core.AssertionsBase.ExpectImplAsync(String expression, FrameExpectOptions expectOptions, Object expected, String message) in C:\Users\collin.johnson\source\repos\playwright-dotnet\src\Playwright\Core\AssertionsBase.cs:line 89
   at Microsoft.Playwright.Core.AssertionsBase.ExpectImplAsync(String expression, ExpectedTextValue[] expectedText, Object expected, String message, FrameExpectOptions options) in C:\Users\collin.johnson\source\repos\playwright-dotnet\src\Playwright\Core\AssertionsBase.cs:line 63
   at Microsoft.Playwright.Core.AssertionsBase.ExpectImplAsync(String expression, ExpectedTextValue textValue, Object expected, String message, FrameExpectOptions options) in C:\Users\collin.johnson\source\repos\playwright-dotnet\src\Playwright\Core\AssertionsBase.cs:line 55
   at Microsoft.Playwright.Tests.Assertions.LocatorAssertionsTests.ShouldSupportToHaveAttributeByRegexAsync() in C:\Users\collin.johnson\source\repos\playwright-dotnet\src\Playwright.Tests\Assertions\LocatorAssertionsTests.cs:line 466
   at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted()
   at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter)
   at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke)
   at NUnit.Framework.Internal.Commands.TestMethodCommand.RunTestMethod(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.TestMethodCommand.Execute(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.<Execute>b__0()
   at NUnit.Framework.Internal.Commands.DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)

Describe the bug

While playwright seems to process Regex objects without flags fine, when a flag is passed in, such as IgnoreCase, it seems that the matching operation is still using a case-sensitive setting.

@mxschmitt
Copy link
Member

Thanks for reporting, I was able to reproduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants