Skip to content

Commit

Permalink
chore: try using a second page
Browse files Browse the repository at this point in the history
  • Loading branch information
JuroUhlar committed Jan 3, 2024
1 parent dd6c2e5 commit 2b966ca
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions e2e/bot-firewall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test.describe('Bot Firewall Demo', () => {
await resetScenarios(page);
});

test('Should display bot visit a allow blocking IP address', async ({ page }) => {
test('Should display bot visit a allow blocking IP address', async ({ page, context }) => {
// Record bot visit in web-scraping page
await page.goto('/web-scraping');
await expect(page.getByTestId(TEST_IDS.common.alert)).toContainText('Malicious bot detected');
Expand All @@ -18,25 +18,26 @@ test.describe('Bot Firewall Demo', () => {
await page.goto('/bot-firewall');
await page.getByRole('button', { name: BOT_FIREWALL_COPY.blockIp }).first().click();
await page.getByText('was blocked in the application firewall').waitFor();
await page.waitForTimeout(10000);
await page.waitForTimeout(3000);

/**
* Try to visit web-scraping page, should be blocked by Cloudflare
* Checking the response code here as parsing the actual page if flaky for some reason
*/
const responsePromise = page.waitForResponse('https://staging.fingerprinthub.com/web-scraping');
page.goto('https://staging.fingerprinthub.com/web-scraping');
const secondPage = await context.newPage();
const responsePromise = secondPage.waitForResponse('https://staging.fingerprinthub.com/web-scraping');
await secondPage.goto('https://staging.fingerprinthub.com/web-scraping');
expect((await responsePromise).status()).toBe(403);

Check failure on line 30 in e2e/bot-firewall.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright e2e tests (1, 3)

[chromium] › bot-firewall.spec.ts:12:7 › Bot Firewall Demo › Should display bot visit a allow blocking IP address

1) [chromium] › bot-firewall.spec.ts:12:7 › Bot Firewall Demo › Should display bot visit a allow blocking IP address Error: expect(received).toBe(expected) // Object.is equality Expected: 403 Received: 200 28 | const responsePromise = secondPage.waitForResponse('https://staging.fingerprinthub.com/web-scraping'); 29 | await secondPage.goto('https://staging.fingerprinthub.com/web-scraping'); > 30 | expect((await responsePromise).status()).toBe(403); | ^ 31 | 32 | // Unblock IP 33 | await page.goto('/bot-firewall'); at /home/runner/work/fingerprintjs-pro-use-cases/fingerprintjs-pro-use-cases/e2e/bot-firewall.spec.ts:30:46

Check failure on line 30 in e2e/bot-firewall.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright e2e tests (1, 3)

[chromium] › bot-firewall.spec.ts:12:7 › Bot Firewall Demo › Should display bot visit a allow blocking IP address

1) [chromium] › bot-firewall.spec.ts:12:7 › Bot Firewall Demo › Should display bot visit a allow blocking IP address Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBe(expected) // Object.is equality Expected: 403 Received: 200 28 | const responsePromise = secondPage.waitForResponse('https://staging.fingerprinthub.com/web-scraping'); 29 | await secondPage.goto('https://staging.fingerprinthub.com/web-scraping'); > 30 | expect((await responsePromise).status()).toBe(403); | ^ 31 | 32 | // Unblock IP 33 | await page.goto('/bot-firewall'); at /home/runner/work/fingerprintjs-pro-use-cases/fingerprintjs-pro-use-cases/e2e/bot-firewall.spec.ts:30:46

// Unblock IP
await page.goto('/bot-firewall');
await page.getByRole('button', { name: BOT_FIREWALL_COPY.unblockIp }).first().click();
await page.getByText('was unblocked in the application firewall').waitFor();
await page.waitForTimeout(10000);
await page.waitForTimeout(3000);

// Try to visit web-scraping page, should be allowed again
await page.goto('https://staging.fingerprinthub.com/web-scraping');
await page.reload();
await expect(page.getByTestId(TEST_IDS.common.alert)).toContainText('Malicious bot detected');
await secondPage.goto('https://staging.fingerprinthub.com/web-scraping');
await secondPage.reload();
await expect(secondPage.getByTestId(TEST_IDS.common.alert)).toContainText('Malicious bot detected');

Check failure on line 41 in e2e/bot-firewall.spec.ts

View workflow job for this annotation

GitHub Actions / Playwright e2e tests (1, 3)

[chromium] › bot-firewall.spec.ts:12:7 › Bot Firewall Demo › Should display bot visit a allow blocking IP address

1) [chromium] › bot-firewall.spec.ts:12:7 › Bot Firewall Demo › Should display bot visit a allow blocking IP address Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toContainText(expected) Locator: getByTestId('alert') Expected string: "Malicious bot detected" Received string: "" Call log: - expect.toContainText with timeout 5000ms - waiting for getByTestId('alert') 39 | await secondPage.goto('https://staging.fingerprinthub.com/web-scraping'); 40 | await secondPage.reload(); > 41 | await expect(secondPage.getByTestId(TEST_IDS.common.alert)).toContainText('Malicious bot detected'); | ^ 42 | }); 43 | }); 44 | at /home/runner/work/fingerprintjs-pro-use-cases/fingerprintjs-pro-use-cases/e2e/bot-firewall.spec.ts:41:65
});
});

0 comments on commit 2b966ca

Please sign in to comment.