Skip to content

Commit 6260823

Browse files
committed
explicit expect message
1 parent 19b20d2 commit 6260823

4 files changed

Lines changed: 55 additions & 97 deletions

File tree

src/Playwright.Tests/Assertions/LocatorAssertionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ public async Task ShouldSupportToContainText()
438438
var exeption = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(() => Expect(Page.Locator("#node")).ToContainTextAsync(new Regex("ex2"), new() { Timeout = 100 }));
439439
StringAssert.Contains("Locator expected text matching regex 'ex2'", exeption.Message);
440440
StringAssert.Contains("But was: 'Text content'", exeption.Message);
441-
StringAssert.Contains("Expect \"ToHaveTextAsync\" with timeout 100ms", exeption.Message);
441+
StringAssert.Contains("Expect \"ToContainTextAsync\" with timeout 100ms", exeption.Message);
442442
}
443443
{
444444
await Page.SetContentAsync("<div id=node><span></span>Text \ncontent&nbsp; </div>");

src/Playwright/Core/AssertionsBase.cs

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@ public AssertionsBase(ILocator actual, bool isNot)
5252

5353
protected Locator ActualLocator { get; }
5454

55-
protected async Task ExpectImplAsync(string expression, ExpectedTextValue textValue, object expected, string message, FrameExpectOptions options)
55+
protected async Task ExpectImplAsync(string expression, ExpectedTextValue textValue, object expected, string message, string title, FrameExpectOptions options)
5656
{
57-
await ExpectImplAsync(expression, new ExpectedTextValue[] { textValue }, expected, message, options).ConfigureAwait(false);
57+
await ExpectImplAsync(expression, new ExpectedTextValue[] { textValue }, expected, message, title, options).ConfigureAwait(false);
5858
}
5959

60-
protected async Task ExpectImplAsync(string expression, ExpectedTextValue[]? expectedText, object? expected, string message, FrameExpectOptions options)
60+
protected async Task ExpectImplAsync(string expression, ExpectedTextValue[]? expectedText, object? expected, string message, string title, FrameExpectOptions options)
6161
{
6262
options ??= new();
6363
options.ExpectedText = expectedText;
6464
options.IsNot = IsNot;
65-
await ExpectImplAsync(expression, options, expected, message).ConfigureAwait(false);
65+
await ExpectImplAsync(expression, options, expected, message, title).ConfigureAwait(false);
6666
}
6767

68-
protected async Task ExpectImplAsync(string expression, FrameExpectOptions expectOptions, object? expected, string message)
68+
protected async Task ExpectImplAsync(string expression, FrameExpectOptions expectOptions, object? expected, string message, string title)
6969
{
7070
if (expectOptions.Timeout == null)
7171
{
@@ -75,7 +75,7 @@ protected async Task ExpectImplAsync(string expression, FrameExpectOptions expec
7575
{
7676
message = message.Replace("expected to", "expected not to");
7777
}
78-
var result = await ActualLocator.ExpectAsync(expression, expectOptions, ExpectExpressionToTitle(expression)).ConfigureAwait(false);
78+
var result = await ActualLocator.ExpectAsync(expression, expectOptions, title).ConfigureAwait(false);
7979
if (result.Matches == IsNot)
8080
{
8181
var actual = result.Received;
@@ -123,48 +123,6 @@ private string FormatValue(object value)
123123
return value.ToString();
124124
}
125125

126-
private string? ExpectExpressionToTitle(string expression)
127-
{
128-
switch (expression)
129-
{
130-
case "to.be.attached": return "Expect \"ToBeAttachedAsync\"";
131-
case "to.be.checked": return "Expect \"ToBeCheckedAsync\"";
132-
case "to.be.detached": return "Expect \"ToBeDetachedAsync\"";
133-
case "to.be.disabled": return "Expect \"ToBeDisabledAsync\"";
134-
case "to.be.editable": return "Expect \"ToBeEditableAsync\"";
135-
case "to.be.empty": return "Expect \"ToBeEmptyAsync\"";
136-
case "to.be.enabled": return "Expect \"ToBeEnabledAsync\"";
137-
case "to.be.focused": return "Expect \"ToBeFocusedAsync\"";
138-
case "to.be.hidden": return "Expect \"ToBeHiddenAsync\"";
139-
case "to.be.in.viewport": return "Expect \"ToBeInViewportAsync\"";
140-
case "to.be.readonly": return "Expect \"ToBeReadonlyAsync\"";
141-
case "to.be.visible": return "Expect \"ToBeVisibleAsync\"";
142-
case "to.contain.class": return "Expect \"ToContainClassAsync\"";
143-
case "to.contain.class.array": return "Expect \"ToHaveClassAsync\"";
144-
case "to.contain.text": return "Expect \"ToContainTextAsync\"";
145-
case "to.contain.text.array": return "Expect \"ToContainTextAsync\"";
146-
case "to.have.accessible.description": return "Expect \"ToHaveAccessibleDescriptionAsync\"";
147-
case "to.have.accessible.error.message": return "Expect \"ToHaveAccessibleErrorMessageAsync\"";
148-
case "to.have.accessible.name": return "Expect \"ToHaveAccessibleNameAsync\"";
149-
case "to.have.attribute.value": return "Expect \"ToHaveAttributeValueAsync\"";
150-
case "to.have.css": return "Expect \"ToHaveCSSAsync\"";
151-
case "to.have.class": return "Expect \"ToHaveClassAsync\"";
152-
case "to.have.class.array": return "Expect \"ToHaveClassAsync\"";
153-
case "to.have.count": return "Expect \"ToHaveCountAsync\"";
154-
case "to.have.id": return "Expect \"ToHaveIdAsync\"";
155-
case "to.have.property": return "Expect \"ToHaveJSPropertyAsync\"";
156-
case "to.have.role": return "Expect \"ToHaveRoleAsync\"";
157-
case "to.have.text": return "Expect \"ToHaveTextAsync\"";
158-
case "to.have.text.array": return "Expect \"ToHaveTextAsync\"";
159-
case "to.have.title": return "Expect \"ToHaveTitleAsync\"";
160-
case "to.have.url": return "Expect \"ToHaveURLAsync\"";
161-
case "to.have.value": return "Expect \"ToHaveValueAsync\"";
162-
case "to.have.values": return "Expect \"ToHaveValuesAsync\"";
163-
case "to.match.aria": return "Expect \"ToMatchAriaSnapshotAsync\"";
164-
}
165-
throw new PlaywrightException($"Unknown expect expression: {expression}");
166-
}
167-
168126
public static void SetDefaultTimeout(float timeout)
169127
=> _defaultTimeout = timeout;
170128
}

0 commit comments

Comments
 (0)