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

[dev-v5] [Playwright] Update the way to test a value #2966

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@page "/button/default"

<div>
Current count: @Value
Current count: <span data-testid="current-value">@Value</span>
</div>
<FluentButton Appearance="ButtonAppearance.Primary" OnClick="@Increment">Increment</FluentButton>

Expand Down
9 changes: 3 additions & 6 deletions tests/Integration/Components/Button/FluentButtonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@ public async Task FluentButton_IncrementCounter()

// Act
await page.ClickAsync("fluent-button");
await Task.Delay(100); // Wait for page to render

// Assert
var content = await page.ContentAsync();
await Assertions.Expect(page.GetByTestId("current-value"))
.ToContainTextAsync("1");

await page.ScreenshotAsync(new()
{
Path = $"{Server.ScreenshotsFolder}FluentButton_IncrementCounter.png"
});

Trace.WriteLine(content);

Assert.Contains("Current count: 1", content);
}
}

26 changes: 20 additions & 6 deletions tests/Integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,33 @@ public class FluentButtonTests : FluentPlaywrightBaseTest
public async Task FluentButton_IncrementCounter()
{
// Arrange
var page = await WaitOpenPageAsync($"/button/default");
var page = await WaitOpenPageAsync($"/button/default", openDevTools: false);

// Act
await page.ClickAsync("fluent-button");
await Task.Delay(100); // Wait for page to render


// Assert
var content = await page.ContentAsync();
Assert.Contains("Current count: 1", content);
await Assertions.Expect(page.GetByTestId("current-value"))
.ToContainTextAsync("1");
}
}
```

```razor
@page "/button/default"

<div>
Current count: <span data-testid="current-value">@Value</span>
</div>
<FluentButton Appearance="ButtonAppearance.Primary" OnClick="@Increment">Increment</FluentButton>

@code
{
private int Value = 0;
private void Increment() => Value++;
}
```

> ⚠️ **Notes:**
>
> If you interrupt a test abruptly (for example, by pressing the Stop button on the Test Explorer)
Expand Down