Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e test cases. #4101

Closed
wants to merge 10 commits into from
26 changes: 13 additions & 13 deletions browsers.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"bs_edge_16_windows_10": {
"bs_edge_17_windows_10": {
"base": "BrowserStack",
"os_version": "10",
"browser": "edge",
"browser_version": "16.0",
"browser_version": "17.0",
"device": null,
"os": "Windows"
},
"bs_edge_17_windows_10": {
"bs_edge_18_windows_10": {
"base": "BrowserStack",
"os_version": "10",
"browser": "edge",
"browser_version": "17.0",
"browser_version": "18.0",
"device": null,
"os": "Windows"
},
Expand All @@ -23,35 +23,35 @@
"device": null,
"os": "Windows"
},
"bs_chrome_72_windows_10": {
"bs_chrome_74_windows_10": {
"base": "BrowserStack",
"os_version": "10",
"browser": "chrome",
"browser_version": "72.0",
"browser_version": "74.0",
"device": null,
"os": "Windows"
},
"bs_chrome_71_windows_10": {
"bs_chrome_75_windows_10": {
"base": "BrowserStack",
"os_version": "10",
"browser": "chrome",
"browser_version": "71.0",
"browser_version": "75.0",
"device": null,
"os": "Windows"
},
"bs_firefox_65_windows_10": {
"bs_firefox_67_windows_10": {
"base": "BrowserStack",
"os_version": "10",
"browser": "firefox",
"browser_version": "65.0",
"browser_version": "67.0",
"device": null,
"os": "Windows"
},
"bs_firefox_64_windows_10": {
"bs_firefox_68_windows_10": {
"base": "BrowserStack",
"os_version": "10",
"browser": "firefox",
"browser_version": "64.0",
"browser_version": "68.0",
"device": null,
"os": "Windows"
},
Expand All @@ -71,4 +71,4 @@
"device": null,
"os": "OS X"
}
}
}
123 changes: 123 additions & 0 deletions test/pages/native.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<!-- This is a Test Page for Native End-to-End test -->
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Prebid.js Native Ad Unit Example</title>

<!-- Prebid.js -->
<script async src="../../build/dev/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 || [];

// Prebid Native Ad Unit
const adUnits = [{
code: '/19968336/prebid_native_example_1',
sizes: [360, 360],
mediaTypes: {
native: {
title: {
required: true
},
image: {
required: true
},
sponsoredBy: {
required: true
}
}
},
bids: [{
bidder: 'appnexus',
params: {
placementId: 13232354,
allowSmallerSizes: true
}
}]
}, {
code: '/19968336/prebid_native_example_2',
sizes: [
[1, 1]
],
mediaTypes: {
native: {
title: {
required: true
},
body: {
required: true
},
image: {
required: true
},
sponsoredBy: {
required: true
},
icon: {
required: false
},
}
},
bids: [{
bidder: 'appnexus',
params: {
placementId: 13232354,
allowSmallerSizes: true
}
}]
}];
</script>

<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];

googletag.cmd.push(() => {
googletag.pubads().disableInitialLoad();
});

pbjs.que.push(() => {
pbjs.addAdUnits(adUnits);
pbjs.requestBids({ bidsBackHandler: sendAdServerRequest });
});

function sendAdServerRequest() {
googletag.cmd.push(() => {
pbjs.que.push(() => {
pbjs.setTargetingForGPTAsync('/19968336/prebid_native_example_1');
googletag.pubads().refresh();
});
});
}
</script>

<script>
// GPT Setup
googletag.cmd.push(() => {
googletag
.defineSlot('/19968336/prebid_native_example_1', [360, 360], 'div-1')
.addService(googletag.pubads());

googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
</head>

<body>
<h2>Prebid.js Native Ad Unit Test</h2>
<div id='div-1'>
<p>No response</p>
<script>
googletag.cmd.push(() => { googletag.display('div-1'); });
</script>
</div>
</body>

</html>
62 changes: 62 additions & 0 deletions test/spec/e2e/native/basic_native_ad.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const expect = require('chai').expect;
const { host, protocol } = require('../../../helpers/testing-utils');

const TEST_PAGE_URL = `${protocol}://${host}:9999/test/pages/native.html`;
const CREATIVE_IFRAME_CSS_SELECTOR = 'iframe[id="google_ads_iframe_/19968336/prebid_native_example_1_0"]';

const EXPECTED_TARGETING_KEYS = {
hb_source: 'client',
hb_source_appnexus: 'client',
hb_pb_appnexus: '10.00',
hb_native_title_appn: 'This is a Prebid Native Creative',
hb_native_linkurl: 'http://prebid.org/dev-docs/show-native-ads.html',
hb_format: 'native',
hb_native_brand: 'Prebid.org',
hb_size: '0x0',
hb_bidder_appnexus: 'appnexus',
hb_native_linkurl_ap: 'http://prebid.org/dev-docs/show-native-ads.html',
hb_native_title: 'This is a Prebid Native Creative',
hb_pb: '10.00',
hb_native_brand_appn: 'Prebid.org',
hb_bidder: 'appnexus',
hb_format_appnexus: 'native',
hb_size_appnexus: '0x0'
}

describe('Prebid.js Native Ad Unit Test', function () {
before(function loadTestPage() {
console.log('running function loadTestPage()');
browser.url(TEST_PAGE_URL).pause(3000);
try {
browser.waitForExist(CREATIVE_IFRAME_CSS_SELECTOR, 2000);
} catch (e) {
// If creative Iframe didn't load, repeat the steps again!
// Due to some reason if the Ad server doesn't respond, the test case will time out after 60000 ms as defined in file wdio.conf.js
console.log('caught an error, ', e);
loadTestPage();
}
});

it('should load the targeting keys with correct values', function () {
const result = browser.execute(function () {
return window.pbjs.getAdserverTargeting('/19968336/prebid_native_example_2');
});

const targetingKeys = result.value['/19968336/prebid_native_example_2'];
expect(targetingKeys).to.include(EXPECTED_TARGETING_KEYS);
expect(targetingKeys.hb_adid).to.be.a('string');
expect(targetingKeys.hb_native_body).to.be.a('string');
expect(targetingKeys.hb_native_body_appne).to.be.a('string');
expect(targetingKeys.hb_native_icon).to.be.a('string');
expect(targetingKeys.hb_native_icon_appne).to.be.a('string');
expect(targetingKeys.hb_native_image).to.be.a('string');
expect(targetingKeys.hb_adid_appnexus).to.be.a('string');
});

it('should render the native ad on the page', function () {
const creativeIframe = $(CREATIVE_IFRAME_CSS_SELECTOR).value;
console.log('creativeIframe', creativeIframe);
browser.frame(creativeIframe);
expect(browser.isVisible('body > div[class="GoogleActiveViewElement"] > div[class="card"]')).to.be.true;
});
});