-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve E2E testing of prebid (#1811)
- Loading branch information
Showing
3 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import type { PrebidAuctionInitEvent } from '../../src/lib/header-bidding/prebid-types'; | ||
import { articles } from '../fixtures/pages'; | ||
import { cmpAcceptAll } from '../lib/cmp'; | ||
import { loadPage } from '../lib/load-page'; | ||
|
||
const testPage = articles[0]; | ||
|
||
test.describe('Prebid', () => { | ||
test('should load the prebid script', async ({ page }) => { | ||
const scriptRequestPromise = page.waitForRequest( | ||
/graun\.Prebid\.js\.commercial\.js$/, | ||
); | ||
await loadPage(page, testPage.path); | ||
await cmpAcceptAll(page); | ||
const prebid = await scriptRequestPromise; | ||
|
||
expect(prebid).toBeTruthy(); | ||
}); | ||
|
||
test('should request bids for top-above-nav', async ({ page }) => { | ||
await loadPage(page, testPage.path); | ||
|
||
await cmpAcceptAll(page); | ||
|
||
await page.waitForFunction( | ||
() => { | ||
const events = window.pbjs?.getEvents() ?? []; | ||
return events.find( | ||
(event) => | ||
event.eventType === 'auctionInit' && | ||
event.args.adUnitCodes.includes( | ||
'dfp-ad--top-above-nav', | ||
), | ||
); | ||
}, | ||
{ timeout: 10000 }, | ||
); | ||
|
||
const topAboveNavBidderRequests = await page.evaluate(() => { | ||
const auctionInitEvent = window.pbjs | ||
?.getEvents() | ||
.find( | ||
(event): event is PrebidAuctionInitEvent => | ||
event.eventType === 'auctionInit' && | ||
event.args.adUnitCodes.includes( | ||
'dfp-ad--top-above-nav', | ||
), | ||
); | ||
|
||
return auctionInitEvent?.args.bidderRequests; | ||
}); | ||
|
||
const bidders = topAboveNavBidderRequests?.map( | ||
(request) => request.bidderCode, | ||
); | ||
|
||
expect(bidders).toBeTruthy(); | ||
expect(bidders).toHaveLength(10); | ||
[ | ||
'oxd', | ||
'and', | ||
'pubmatic', | ||
'ix', | ||
'adyoulike', | ||
'ozone', | ||
'xhb', | ||
'criteo', | ||
'ttd', | ||
'rubicon', | ||
].forEach((bidder) => { | ||
expect(bidders).toContain(bidder); | ||
}); | ||
}); | ||
|
||
test('should not find bidderErrors (excluding timeouts)', async ({ | ||
page, | ||
}) => { | ||
await loadPage(page, testPage.path); | ||
|
||
await cmpAcceptAll(page); | ||
|
||
await page.waitForFunction( | ||
() => { | ||
const events = window.pbjs?.getEvents() ?? []; | ||
return events.find((event) => event.eventType === 'auctionEnd'); | ||
}, | ||
{ timeout: 10000 }, | ||
); | ||
|
||
const bidderErrors = await page.evaluate(() => { | ||
return window.pbjs | ||
?.getEvents() | ||
.filter( | ||
(event) => | ||
event.eventType === 'bidderError' && | ||
event.args.error.timedOut !== true, | ||
); | ||
}); | ||
|
||
expect(bidderErrors).toHaveLength(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters