Slide 19
Slide 19 text
モックAPI
• HTTPとHTTPSのネットワークトラフィックをモック及び変更するためのAPI
• ページが行うすべての要求はモックできる。
• データベースの状態を抜きにしてUIをテストしたいときに有効
// Intercept the route to the fruit API
await page.RouteAsync("*/**/api/v1/fruits", async route => {
var json = new[] { new { name = "Strawberry", id = 21 } };
// fulfill the route with the mock data
await route.FulfillAsync(new()
{
Json = json
});
});
// Go to the page
await page.GotoAsync("https://demo.playwright.dev/api-mocking");
// Assert that the Strawberry fruit is visible
await Expect(page.GetByTextAsync("Strawberry")).ToBeVisibleAsync();