-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
20,666 additions
and
179 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Built files | ||
/playwright-report/ | ||
node_modules/ | ||
build | ||
coverage | ||
/build | ||
coverage | ||
dist/ |
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,4 @@ | ||
/playwright-report/ | ||
node_modules/ | ||
/build | ||
coverage |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {test as baseTest} from '@playwright/test'; | ||
import path from 'path'; | ||
|
||
export {expect} from '@playwright/test'; | ||
export const BASE_URL = 'https://www.prebid.org/puc-test/'; | ||
export const PUC_URL = 'https://cdn.jsdelivr.net/npm/prebid-universal-creative@latest/dist/'; | ||
|
||
const REDIRECTS = { | ||
[BASE_URL]: '../pages', | ||
[PUC_URL]: '../../dist' | ||
}; | ||
|
||
export const test = baseTest.extend({ | ||
/** | ||
* Replace requests for "https://www.prebid.org" with the contents of files under "pages", | ||
* and requests for the PUC CDN with contents of files under "dist". | ||
*/ | ||
async context({context}, use) { | ||
await Promise.all( | ||
Object.entries(REDIRECTS).map(([url, localDir]) => { | ||
context.route((u) => u.href.startsWith(url), (route, request) => { | ||
const fpath = request.url().substring(url.length).split('?')[0]; | ||
route.fulfill({ | ||
path: path.resolve(__dirname, localDir, fpath) | ||
}); | ||
}); | ||
}) | ||
); | ||
await use(context); | ||
}, | ||
/** | ||
* await crossLocator(selector): returns a locator for the first element matching 'selector' that appears on the | ||
* page, across all frames. | ||
*/ | ||
async crossLocator({page}, use) { | ||
use(function (selector) { | ||
let n = 0; | ||
return new Promise((resolve, reject) => { | ||
async function frameLocator(frame) { | ||
if (!frame.isDetached()) { | ||
n++; | ||
try { | ||
await frame.waitForSelector(selector); | ||
resolve(frame.locator(selector)); | ||
} catch (e) { | ||
n--; | ||
if (n === 0) { | ||
reject(e); | ||
} | ||
} | ||
} | ||
} | ||
page.on('frameattached', frameLocator); | ||
function walkFrames(frame) { | ||
frameLocator(frame); | ||
frame.childFrames().forEach(walkFrames) | ||
} | ||
walkFrames(page.mainFrame()); | ||
}) | ||
}) | ||
}, | ||
}); |
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,99 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Prebid.js Banner Test</title> | ||
|
||
<!-- Prebid.js --> | ||
<script async src="https://cdn.jsdelivr.net/npm/prebid.js@latest/dist/not-for-prod/prebid.js"></script> | ||
|
||
<!-- Google Publisher Tag --> | ||
<script async src="https://www.googletagservices.com/tag/js/gpt.js"></script> | ||
|
||
<script> | ||
var pbjs = pbjs || {}; | ||
pbjs.que = pbjs.que || []; | ||
window.params = new URLSearchParams(window.location.search); | ||
</script> | ||
|
||
<script> | ||
var googletag = googletag || {}; | ||
googletag.cmd = googletag.cmd || []; | ||
|
||
googletag.cmd.push(function () { | ||
googletag.pubads().disableInitialLoad(); | ||
}); | ||
|
||
pbjs.que.push(function () { | ||
pbjs.setConfig({ | ||
debug: true, | ||
debugging: { | ||
enabled: true, | ||
intercept: [ | ||
{ | ||
when: {}, | ||
then: { | ||
ad: '<p id="the-ad">This is the ad</p>', | ||
mediaType: params.get('mediaType') || 'banner' | ||
} | ||
} | ||
] | ||
} | ||
}); | ||
|
||
pbjs.requestBids({ | ||
bidsBackHandler: sendAdServerRequest, | ||
adUnits: [ | ||
{ | ||
code: 'slot', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250]], | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'appnexus', | ||
params: { | ||
placementId: 123 | ||
} | ||
}] | ||
} | ||
] | ||
}); | ||
}); | ||
|
||
function sendAdServerRequest() { | ||
googletag.cmd.push(function () { | ||
pbjs.que.push(function () { | ||
pbjs.setTargetingForGPTAsync('slot'); | ||
googletag.pubads().refresh(); | ||
}); | ||
}); | ||
} | ||
</script> | ||
|
||
<script> | ||
googletag.cmd.push(function () { | ||
googletag | ||
.defineSlot('/41758329/integ-test', [[300, 250]], 'slot') | ||
.setTargeting('creative', params.get('creative')) | ||
.addService(googletag.pubads()); | ||
|
||
googletag.pubads().enableSingleRequest(); | ||
googletag.enableServices(); | ||
}); | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<h2>Prebid.js Banner Ad Unit Test</h2> | ||
<div id='slot'> | ||
<script> | ||
googletag.cmd.push(function () { | ||
googletag.display('slot'); | ||
}); | ||
</script> | ||
</div> | ||
</body> | ||
</html> |
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,25 @@ | ||
import {test, expect} from '../fixtures/test.js'; | ||
|
||
test.describe('Banner', () => { | ||
Object.entries({ | ||
'safeframe': 'banner-safeframe', | ||
'non safeframe': 'banner-noframe' | ||
}).forEach(([t, creative]) => { | ||
test.describe(t, () => { | ||
test.beforeEach(async ({page}) => { | ||
await page.goto(`banner.html?creative=${creative}`) | ||
}); | ||
test('should display ad', async ({crossLocator}) => { | ||
await expect(await crossLocator('#the-ad')).toBeVisible(); | ||
}); | ||
test('should emit AD_RENDER_SUCCEEDED', async ({page}) => { | ||
await expect.poll(async () => | ||
await page.evaluate(() => | ||
window.pbjs?.getEvents && | ||
window.pbjs.getEvents().filter((ev) => ev.eventType === 'adRenderSucceeded').length > 0 | ||
) | ||
).toBeTruthy(); | ||
}); | ||
}) | ||
}) | ||
}); |
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,24 @@ | ||
import {test, expect} from'../fixtures/test.js'; | ||
|
||
test.describe('video render', () => { | ||
Object.entries({ | ||
// safeframe should not render video ads, and emit AD_RENDER_FAILED | ||
// this does not work currently; mediaType is not in the message payload | ||
// 'safeframe': 'banner-safeframe', | ||
'non safeframe': 'banner-noframe' | ||
}).forEach(([t, creative]) => { | ||
test.describe(t, () => { | ||
test.beforeEach(async ({page}) => { | ||
await page.goto(`banner.html?creative=${creative}&mediaType=video`); | ||
}); | ||
test('should emit AD_RENDER_FAILED', async ({page}) => { | ||
await expect.poll(async () => | ||
await page.evaluate(() => | ||
window.pbjs?.getEvents && | ||
window.pbjs.getEvents().filter(ev => ev.eventType === 'adRenderFailed').length > 0 | ||
) | ||
).toBeTruthy(); | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.