Skip to content

Commit

Permalink
add new longform e2e tests (prebid#4206)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnellbaker authored and jaiminpanchal27 committed Oct 7, 2019
1 parent 1aecd87 commit 4ac3582
Show file tree
Hide file tree
Showing 4 changed files with 434 additions and 0 deletions.
145 changes: 145 additions & 0 deletions integrationExamples/longform/basic_w_bidderSettings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<!Doctype html>
<html>

<head>
<title>Prebid Freewheel Integration Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- <script async src="//acdn.adnxs.com/prebid/not-for-prod/1/prebid.js"></script> -->
<script src="/build/dev/prebid.js" async=true></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome.css" />
<!-- <script type="text/javascript" src="//adm.fwmrm.net/p/vitest-js/AdManager.js"></script> -->
<script type="text/javascript" src="https://mssl.fwmrm.net/libs/adm/6.24.0/AdManager-debug.js"></script>
<!-- <script type="text/javascript" src="player.js"></script> -->
<link rel="stylesheet" href="longform_testpages_style.css">
<script src="longformTestUtils.js"></script>
<script>
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

var videoAdUnit = [{
code: 'sample-code',
sizes: [640, 480],
mediaTypes: {
video: {
context: 'adpod',
playerSize: [640, 480],
adPodDurationSec: 300,
durationRangeSec: [15, 30],
requireExactDuration: false
}
},
bids: [
{
bidder: 'appnexus',
params: {
placementId: 15394006
}
}
]
}];

pbjs.que.push(function () {
pbjs.addAdUnits(videoAdUnit);
pbjs.bidderSettings = {
appnexus: {
adserverTargeting : [{
key: 'hb_pb',
val: function(bid) {
bid.pbMg = '40.00';
return bid.pbMg;
}
}],
bidCpmAdjustment: function(bidCpm) {
return bidCpm - 1;
}
}
}
pbjs.setConfig({
debug: true,
cache: {
url: 'https://prebid.adnxs.com/pbc/v1/cache'
},
adpod: {
brandCategoryExclusion: true
}
});
});

function loadPrebidRequest() {
pbjs.que.push(function () {
pbjs.requestBids({
bidsBackHandler: function (bids) {
pbjs.adServers.freewheel.getTargeting({
callback: function (err, targeting) {
prebidTestUtils.loadKv(targeting);
prebidTestUtils.loadBids(targeting, true);
console.log(targeting);
}
});
}
});
});
}

</script>
</head>

<body>
<h1 style="margin:20px">Prebid Freewheel Test Page</h1>
<h2 style="margin:20px">requireExactDuration = false</h2>
<div class="row" style="margin: 20px">
<div class="col-lg-6">
<button id="loadPrebidRequestBtn" class="btn btn-secondary" type="button" onclick="loadPrebidRequest()">Load
Prebid</button>
<div class="row">
<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header" id="headingTwo">
<h2 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseTwo"
aria-expanded="false" aria-controls="collapseTwo">
Bids Sent to Freewheel
</button>
</h2>
</div>
<div id="collapseTwo" class="collapse show" aria-labelledby="headingTwo">
<div class="card-body">
// bids
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingThree">
<h2 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseThree"
aria-expanded="false" aria-controls="collapseThree">
Key Value Pairs Sent to Freewheel
</button>
</h2>
</div>
<div id="collapseThree" class="collapse show" aria-labelledby="headingThree">
<div class="card-body">
// bids
</div>
</div>
</div>
</div>
</div>
</div>
</div>

</body>

</html>
153 changes: 153 additions & 0 deletions integrationExamples/longform/basic_w_priceGran.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<!Doctype html>
<html>

<head>
<title>Prebid Freewheel Integration Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- <script async src="//acdn.adnxs.com/prebid/not-for-prod/1/prebid.js"></script> -->
<script src="/build/dev/prebid.js" async=true></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome.css" />
<!-- <script type="text/javascript" src="//adm.fwmrm.net/p/vitest-js/AdManager.js"></script> -->
<script type="text/javascript" src="https://mssl.fwmrm.net/libs/adm/6.24.0/AdManager-debug.js"></script>
<!-- <script type="text/javascript" src="player.js"></script> -->
<link rel="stylesheet" href="longform_testpages_style.css">
<script src="longformTestUtils.js"></script>
<script>
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

var videoAdUnit = [{
code: 'sample-code',
sizes: [640, 480],
mediaTypes: {
video: {
context: 'adpod',
playerSize: [640, 480],
adPodDurationSec: 300,
durationRangeSec: [15, 30],
requireExactDuration: false
}
},
bids: [
{
bidder: 'appnexus',
params: {
placementId: 15394006
}
}
]
}];

const customConfigObject = {
'buckets': [{
'precision': 2, // default is 2 if omitted - means 2.1234 rounded to 2 decimal places = 2.12
'min': 0,
'max': 5,
'increment': 0.01 // from $0 to $5, 1-cent increments
},
{
'precision': 2,
'min': 5,
'max': 8,
'increment': 0.05 // from $5 to $8, round down to the previous 5-cent increment
},
{
'precision': 2,
'min': 8,
'max': 40,
'increment': 0.5 // from $8 to $40, round down to the previous 50-cent increment
}]
};

pbjs.que.push(function () {
pbjs.addAdUnits(videoAdUnit);
pbjs.setConfig({
debug: true,
cache: {
url: 'https://prebid.adnxs.com/pbc/v1/cache'
},
adpod: {
brandCategoryExclusion: true
},
priceGranularity: customConfigObject
});
});

function loadPrebidRequest() {
pbjs.que.push(function () {
pbjs.requestBids({
bidsBackHandler: function (bids) {
pbjs.adServers.freewheel.getTargeting({
callback: function (err, targeting) {
prebidTestUtils.loadKv(targeting);
prebidTestUtils.loadBids(targeting, true);
console.log(targeting);
}
});
}
});
});
}

</script>
</head>

<body>
<h1 style="margin:20px">Prebid Freewheel Test Page</h1>
<h2 style="margin:20px">requireExactDuration = false</h2>
<div class="row" style="margin: 20px">
<div class="col-lg-6">
<button id="loadPrebidRequestBtn" class="btn btn-secondary" type="button" onclick="loadPrebidRequest()">Load
Prebid</button>
<div class="row">
<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header" id="headingTwo">
<h2 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseTwo"
aria-expanded="false" aria-controls="collapseTwo">
Bids Sent to Freewheel
</button>
</h2>
</div>
<div id="collapseTwo" class="collapse show" aria-labelledby="headingTwo">
<div class="card-body">
// bids
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingThree">
<h2 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseThree"
aria-expanded="false" aria-controls="collapseThree">
Key Value Pairs Sent to Freewheel
</button>
</h2>
</div>
<div id="collapseThree" class="collapse show" aria-labelledby="headingThree">
<div class="card-body">
// bids
</div>
</div>
</div>
</div>
</div>
</div>
</div>

</body>

</html>
68 changes: 68 additions & 0 deletions test/spec/e2e/longform/basic_w_bidderSettings.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const includes = require('core-js/library/fn/array/includes');
const expect = require('chai').expect;
const testServer = require('../../../helpers/testing-utils');

const host = testServer.host;
const protocol = testServer.protocol;

const validDurations = ['15s', '30s'];
const validCats = ['Food', 'Retail Stores/Chains', 'Pet Food/Supplies', 'Travel/Hotels/Airlines', 'Automotive', 'Health Care Services'];
const validCpms = ['14.00', '13.00', '12.00', '9.00'];
const customKeyRegex = /\d{2}\.\d{2}_\d{1,3}_\d{2}s/;
const uuidRegex = /(\d|\w){8}-((\d|\w){4}-){3}(\d|\w){12}/;

describe('longform ads not using requireExactDuration field', function() {
this.retries(3);
it('process the bids successfully', function() {
browser
.url(protocol + '://' + host + ':9999/integrationExamples/longform/basic_w_bidderSettings.html?pbjs_debug=true')
.pause(10000);

const loadPrebidBtnXpath = '//*[@id="loadPrebidRequestBtn"]';
browser.waitForExist(loadPrebidBtnXpath);
$(loadPrebidBtnXpath).click();
browser.pause(3000);

const listOfCpmsXpath = '/html/body/div[1]/div/div/div/div[1]/div[2]/div/table/tbody/tr/td[2]';
const listOfCategoriesXpath = '/html/body/div[1]/div/div/div/div[1]/div[2]/div/table/tbody/tr/td[3]';
const listOfDurationsXpath = '/html/body/div[1]/div/div/div/div[1]/div[2]/div/table/tbody/tr/td[4]';

browser.waitForExist(listOfCpmsXpath);

let listOfCpms = $$(listOfCpmsXpath);
let listOfCats = $$(listOfCategoriesXpath);
let listOfDuras = $$(listOfDurationsXpath);

expect(listOfCpms.length).to.equal(listOfCats.length).and.to.equal(listOfDuras.length);
for (let i = 0; i < listOfCpms.length; i++) {
let cpm = listOfCpms[i].getText();
let cat = listOfCats[i].getText();
let dura = listOfDuras[i].getText();
expect(includes(validCpms, cpm), `Could not find CPM ${cpm} in accepted list`).to.equal(true);
expect(includes(validCats, cat), `Could not find Category ${cat} in accepted list`).to.equal(true);
expect(includes(validDurations, dura), `Could not find Duration ${dura} in accepted list`).to.equal(true);
}
});

it('formats the targeting keys properly', function () {
const listOfKeyElementsXpath = '/html/body/div[1]/div/div/div/div[2]/div[2]/div/table/tbody/tr/td[1]';
const listOfKeyValuesXpath = '/html/body/div[1]/div/div/div/div[2]/div[2]/div/table/tbody/tr/td[2]';
browser.waitForExist(listOfKeyElementsXpath);
browser.waitForExist(listOfKeyValuesXpath);

let listOfKeyElements = $$(listOfKeyElementsXpath);
let listOfKeyValues = $$(listOfKeyValuesXpath);

let firstKey = listOfKeyElements[0].getText();
expect(firstKey).to.equal('hb_pb_cat_dur');

let firstKeyValue = listOfKeyValues[0].getText();
expect(firstKeyValue).match(customKeyRegex);

let lastKey = listOfKeyElements[listOfKeyElements.length - 1].getText();
expect(lastKey).to.equal('hb_cache_id');

let lastKeyValue = listOfKeyValues[listOfKeyValues.length - 1].getText();
expect(lastKeyValue).to.match(uuidRegex);
});
})
Loading

0 comments on commit 4ac3582

Please sign in to comment.