diff --git a/package.json b/package.json index c5a32c2..37990e3 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,16 @@ "description": "", "main": "index.js", "scripts": { - "test:a11y": "playwright test tests/accessibility --project=chromium" + "test": "playwright test", + "test:chromium": "playwright test --project=chromium", + "test:firefox": "playwright test --project=firefox", + "test:webkit": "playwright test --project=webkit", + "test:smoke": "playwright test --grep @smoke", + "test:functional": "playwright test --grep @functional", + "test:integration": "playwright test --grep @integration", + "test:negative": "playwright test --grep @negative", + "test:a11y": "playwright test --grep @a11y", + "report": "playwright show-report" }, "keywords": [], "author": "", diff --git a/pages/HomePage.ts b/pages/HomePage.ts index 763e62c..5422824 100644 --- a/pages/HomePage.ts +++ b/pages/HomePage.ts @@ -24,12 +24,22 @@ export class HomePage { } async searchFor(query: string): Promise { + await expect(this.searchInput).toBeVisible({ timeout: 10000 }); + + await this.searchInput.click(); await this.searchInput.fill(query); + await expect(this.searchInput).toHaveValue(query); await Promise.all([ - this.page.waitForURL(/\/search(?:\?|\/|$)/, { - waitUntil: 'domcontentloaded', - }), + this.page.waitForURL( + (url) => + url.pathname === '/search' && + url.searchParams.get('q') === query, + { + waitUntil: 'domcontentloaded', + timeout: 15000, + } + ), this.searchInput.press('Enter'), ]); } diff --git a/pages/SearchResultsPage.ts b/pages/SearchResultsPage.ts index 988b857..3326877 100644 --- a/pages/SearchResultsPage.ts +++ b/pages/SearchResultsPage.ts @@ -17,12 +17,29 @@ export class SearchResultsPage { this.noResultsMessage = page.getByText( /no results|nothing found|did not match|try a different search/i ); + +} + +private async expectSearchUrlContainsQuery(query: string): Promise { + await expect(this.page).toHaveURL(/\/search(?:\?|\/|$)/); + + await expect + .poll( + () => { + const currentUrl = new URL(this.page.url()); + return currentUrl.searchParams.get('q') ?? ''; + }, + { + message: `Expected search URL to contain query: ${query}`, + timeout: 10000, + } + ) + .toBe(query); } async expectSearchResultsPageLoaded(query: string): Promise { - await expect(this.page).toHaveURL(/\/search(\?|\/|$)/); - await expect(this.mainContent).toContainText(query, { timeout: 10000 }); - } + await this.expectSearchUrlContainsQuery(query); +} async expectResultContainingText(expectedText: string): Promise { const matchingResult = this.page @@ -52,8 +69,7 @@ export class SearchResultsPage { } async expectGracefulNoResultState(query: string): Promise { - await expect(this.page).toHaveURL(/\/search(?:\?|\/|$)/); - await expect(this.mainContent).toContainText(query, { timeout: 10000 }); + await this.expectSearchUrlContainsQuery(query); await expect(this.mainContent).not.toContainText( /server error|something went wrong|application error|internal error/i