Add a cookie advanced option on the front page

This commit is contained in:
Gaël Métais
2015-05-04 15:24:00 +02:00
parent b2f6f68d1a
commit bb2f0e6c55
6 changed files with 47 additions and 10 deletions
+14
View File
@@ -15,6 +15,10 @@ var cli = meow({
' --device Use "phone" or "tablet" to simulate a mobile device (by user-agent and viewport size).',
' --screenshot Will take a screenshot and use this value as the output path. It needs to end with ".png".',
' --js-deep-analysis When activated, the javascriptExecutionTree will contain sub-requests.',
' --wait-for-selector Once the page is loaded, Phantomas will wait until the given CSS selector matches some elements.',
' --cookie Adds a cookie on the main domain.',
' --auth-user Basic HTTP authentication username.',
' --auth-pass Basic HTTP authentication password.',
''
].join('\n'),
pkg: '../package.json'
@@ -54,6 +58,16 @@ if (cli.flags.jsDeepAnalysis === true || cli.flags.jsDeepAnalysis === 'true') {
// Device simulation
options.device = cli.flags.device || 'desktop';
// Wait for CSS selector
options.waitForSelector = cli.flags.waitForSelector || null;
// Cookie
options.cookie = cli.flags.cookie || null;
// HTTP basic auth
options.authUser = cli.flags.authUser || null;
options.authPass = cli.flags.authPass || null;
(function execute(url, options) {
'use strict';
+5 -1
View File
@@ -10,7 +10,11 @@ apiService.factory('API', ['$location', 'Runs', 'Results', function($location, R
waitForResponse: false,
screenshot: true,
jsTimeline: true,
device: settings.device
device: settings.device,
waitForSelector: settings.waitForSelector,
cookie: settings.cookie,
authUser: settings.authUser,
authPass: settings.authPass,
};
if (settings.waitForSelector && settings.waitForSelector !== '') {
+4 -4
View File
@@ -22,7 +22,7 @@
<span ng-if="settings.authUser || settings.authPass">authentication</span>
</span>
<div class="advanced" ng-show="settings.showAdvanced">
<div>
<!--<div>
<div class="label">
Wait selector
<span class="settingsTooltip">
@@ -31,7 +31,7 @@
</span>
</div>
<div><input type="text" name="waitForSelector" ng-model="settings.waitForSelector" /></div>
</div>
</div>-->
<div>
<div class="label">
Cookie
@@ -42,7 +42,7 @@
</div>
<div><input type="text" name="cookie" ng-model="settings.cookie" /></div>
</div>
<div>
<!--<div>
<div class="label">
Authent
<span class="settingsTooltip">
@@ -60,7 +60,7 @@
<div><input type="text" class="authField" name="authPass" ng-model="settings.authPass" /></div>
</div>
</div>
</div>
</div>-->
<!--<div>
<div class="label">Blocked domains</div>
<div>
+10 -2
View File
@@ -34,7 +34,11 @@ var ApiController = function(app) {
partialResult: req.body.partialResult || null,
screenshot: req.body.screenshot || false,
jsTimeline: req.body.jsTimeline || false,
device: req.body.device || 'desktop'
device: req.body.device || 'desktop',
waitForSelector: req.body.waitForSelector || null,
cookie: req.body.cookie || null,
authUser: req.body.authUser || null,
authPass: req.body.authPass || null
}
};
@@ -68,7 +72,11 @@ var ApiController = function(app) {
var runOptions = {
screenshot: run.params.screenshot ? screenshot.getTmpFilePath() : false,
jsDeepAnalysis: run.params.jsTimeline,
device: run.params.device
device: run.params.device,
waitForSelector: run.params.waitForSelector,
cookie: run.params.cookie,
authUser: run.params.authUser,
authPass: run.params.authPass
};
return ylt(run.params.url, runOptions);
+4 -1
View File
@@ -26,6 +26,10 @@ var PhantomasWrapper = function() {
'tablet': (task.options.device === 'tablet'),
'phone': (task.options.device === 'phone'),
'screenshot': task.options.screenshot || false,
'wait-for-selector': task.options.waitForSelector,
'cookie': task.options.cookie,
'auth-user': task.options.authUser,
'auth-pass': task.options.authPass,
// Mandatory
'reporter': 'json:pretty',
@@ -42,7 +46,6 @@ var PhantomasWrapper = function() {
'jQuery', // overridden
'jserrors', // overridden
'pageSource', // not needed
'waitForSelector', // not needed
'windowPerformance' // overriden
].join(','),
'include-dirs': [
+10 -2
View File
@@ -97,7 +97,11 @@ describe('api', function() {
url: wwwUrl + '/simple-page.html',
waitForResponse: true,
screenshot: true,
device: 'tablet'
device: 'tablet',
waitForSelector: '*',
cookie: 'foo=bar',
authUser: 'joe',
authPass: 'secret'
},
json: true,
headers: {
@@ -165,8 +169,12 @@ describe('api', function() {
body.should.have.a.property('javascriptExecutionTree').that.is.an('object');
body.javascriptExecutionTree.should.deep.equal({});
// Check if the device is set to tablet
// Check if settings are correctly sent and retrieved
body.params.options.should.have.a.property('device').that.equals('tablet');
body.params.options.should.have.a.property('waitForSelector').that.equals('*');
body.params.options.should.have.a.property('cookie').that.equals('foo=bar');
body.params.options.should.have.a.property('authUser').that.equals('joe');
body.params.options.should.have.a.property('authPass').that.equals('secret');
// Check if the screenshot temporary file was correctly removed
body.params.options.should.not.have.a.property('screenshot');