Dr0ptp4kt has uploaded a new change for review. https://gerrit.wikimedia.org/r/151986
Change subject: Support CasperJS check for unified design banner ...................................................................... Support CasperJS check for unified design banner Change-Id: I8a2093573983b4084dfb131532a2305269bc6be6 --- M maintenance/phantom/job.sh M maintenance/phantom/zero_automated_tests.js 2 files changed, 57 insertions(+), 20 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroPortal refs/changes/86/151986/1 diff --git a/maintenance/phantom/job.sh b/maintenance/phantom/job.sh index 6158033..1c3762b 100755 --- a/maintenance/phantom/job.sh +++ b/maintenance/phantom/job.sh @@ -2,13 +2,14 @@ export PATH=/bin:$PATH rm caps/* +rm unified-caps/* rm status rm report.zip curl https://zero.wikimedia.org/ echo "AUTOMATED TESTS STARTED" casperjs zero_automated_tests.js --username=zerobdd --passwordfile=pw > 000log.txt 2>&1 echo "AUTOMATED TESTS FINISHED" -zip report.zip 000log.txt caps/* +zip report.zip 000log.txt caps/* unified-caps/* A=`date --rfc-3339=seconds` CASPERSTATUS=`cat status` EMAILMINOR=`cat emailminor` diff --git a/maintenance/phantom/zero_automated_tests.js b/maintenance/phantom/zero_automated_tests.js index 359d08b..a9dba73 100644 --- a/maintenance/phantom/zero_automated_tests.js +++ b/maintenance/phantom/zero_automated_tests.js @@ -14,11 +14,11 @@ casper.start('https://zero.wikimedia.org/w/index.php?title=Special:UserLogin', function() { - this.echo('STARTING'); - this.fill('form[name="userlogin"]', { - wpName: username, - wpPassword: password - }, true); + this.echo('STARTING'); + this.fill('form[name="userlogin"]', { + wpName: username, + wpPassword: password + }, true); }); casper.thenOpen('https://zero.wikimedia.org/w/api.php?action=zeroportal&type=carriersnoips'); @@ -28,7 +28,8 @@ }); casper.then(function() { - var config, xcs, comment, enabled, directReceiver, langs, sites, subdomains, s, l, enabledForPair, url, fileName; + var config, xcs, comment, enabled, directReceiver, langs, sites, subdomains, s, l, enabledForPair, url, + apiUrl, js, fileName; for (config in configs) { if (configs.hasOwnProperty(config)) { xcs = config; @@ -70,8 +71,11 @@ for ( l = 0; l < langs.length; l++ ) { enabledForPair = enabled && (directReceiver.whitelistedLangs.length === 0 || directReceiver.whitelistedLangs.indexOf(langs[l]) !== -1); url = 'http://' + langs[l] + '.' + subdomains[s] + '.wikipedia.org/wiki/Main_Page'; + apiUrl = 'http://' + langs[l] + '.' + subdomains[s] + '.wikipedia.org/wiki/Special:ZeroRatedMobileAccess?zcmd=js-banner'; fileName = 'caps/' + (enabledForPair ? 'enabled-' : 'NOT-enabled-') + xcs + '-' + langs[l] + '.' + subdomains[s] + '.png'; - queuedLinks.push({f: fileName, u: url, x: xcs, efp: enabledForPair}); + queuedLinks.push({f: fileName, u: url, x: xcs, efp: enabledForPair, js: false}); + // now do the stuff for the unified design tests + queuedLinks.push({f: 'unified-' + fileName, u: url, x: xcs, efp: enabledForPair, js: true, au: apiUrl}); } } } @@ -80,19 +84,51 @@ casper.then(function() { casper.each(queuedLinks, function(self, link) { + /* + if (this.page.customHeaders['X-CS']) { + delete this.page.customHeaders['X-CS']; + } + */ self.echo('QUEUED:' + link.x + ':' + link.u); - self.thenOpen(link.u, - { method: 'get', headers: { 'X-CS': link.x } }, - function() { - this.capture(link.f, {top:0, left:0, width:320, height:240}); - if ( (link.efp && !this.exists('#zero-rated-banner-text'))) { - testStatus = 'FAILED'; - this.echo('FAIL:banner not found:' + link.x + ':' + link.u + ':' + link.f); - } else if (!link.efp && this.exists('#zero-rated-banner-text')) { - testStatus = 'FAILED'; - this.echo('FAIL:unexpected banner found:' + link.x + ':' + link.u + ':' + link.f); - } - }); + + if (link.js) { + // If we're trying to process under the unified design, let's just go after the banner directly. + // The page JavaScript should in theory manipulate the DOM, but + // casper.waitForSelector('#zero-rated-banner-text') didn't produce the expected results, even with a long + // timeout. Use of this.page.customHeaders seemed to not achieve the desired outcome, or created + // inconsistent results at best. this.page.customHeaders didn't work so well, even if trying to use + // JavaScript's delete operator (e.g., delete this.page.customHeaders['X-CS'];) to avoid staleness upfront. + self.thenOpen(link.au, { method: 'get', headers: { 'X-CS': link.x, 'Accept': 'application/json' } }, + function() { + var json = this.getPageContent(), + enabled = /window\.mw\.zeroConfig=\{"enabled":true/.exec(json); + if (link.efp && !enabled) { + testStatus = 'FAILED'; + this.echo('FAIL:JavaScript banner disabled when it should be disabled:' + link.x + ':' + link.au + ':' + link.f); + } else if (!link.efp && enabled) { + testStatus = 'FAILED'; + this.echo('FAIL:JavaScript banner enabled when it should be disabled:' + link.x + ':' + link.u + ':' + link.f); + } + this.capture(link.f, {top:0, left:0, width:320, height:240}); + } + ); + } else { + // if we're trying to process under the old design + self.thenOpen(link.u, { method: 'get', headers: { 'X-CS': link.x } }, + function() { + if ( (link.efp && !this.exists('#zero-rated-banner-text'))) { + testStatus = 'FAILED'; + this.echo('FAIL:banner not found:' + link.x + ':' + link.u + ':' + link.f); + } else if (!link.efp && this.exists('#zero-rated-banner-text')) { + testStatus = 'FAILED'; + this.echo('FAIL:unexpected banner found:' + link.x + ':' + link.u + ':' + link.f); + } + this.capture(link.f, {top:0, left:0, width:320, height:240}); + } + ); + + } + }); }); -- To view, visit https://gerrit.wikimedia.org/r/151986 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8a2093573983b4084dfb131532a2305269bc6be6 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ZeroPortal Gerrit-Branch: master Gerrit-Owner: Dr0ptp4kt <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
