Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

refs #987 - Support Phantomjs 2.0 #1137

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions bin/bootstrap.js
Expand Up @@ -79,9 +79,11 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
/*jshint maxstatements:99*/
"use strict";
// phantom args
// NOTE: we can't use require('system').args here for some very obscure reason
// do not even attempt at using it as it creates infinite recursion
var phantomArgs = phantom.args;
var sysargs = require('system').args;
var phantomArgs = [];
for (var i = 1; i < sysargs.length; i++) {
phantomArgs.push(sysargs[i]);
}

if (phantom.casperLoaded) {
return;
Expand Down Expand Up @@ -161,7 +163,7 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
// CasperJS root path
if (!phantom.casperPath) {
try {
phantom.casperPath = phantom.args.map(function _map(arg) {
phantom.casperPath = phantomArgs.map(function _map(arg) {
var match = arg.match(/^--casper-path=(.*)/);
if (match) {
return fs.absolute(match[1]);
Expand Down
5 changes: 3 additions & 2 deletions modules/casper.js
Expand Up @@ -1498,8 +1498,9 @@ Casper.prototype.resourceExists = function resourceExists(test) {
break;
case "function":
testFn = test;
if (phantom.casperEngine !== "slimerjs")
testFn.name = "_testResourceExists_Function";
// if (phantom.casperEngine !== "slimerjs") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this to work, what is the issue with slimerjs at this point ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this point was problem with bug in Phantom, not Slimer. The code is not removed, because I need your opinion.

After this edit, test passed in both engines.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 , CasperJS will be the first and only tool to support triffleJS, phantomJS (1&2) and slimerJS.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌈

// testFn.name = "_testResourceExists_Function";
// }
break;
default:
throw new CasperError("Invalid type");
Expand Down
1 change: 0 additions & 1 deletion tests/sample_modules/csmodule.coffee

This file was deleted.

8 changes: 7 additions & 1 deletion tests/suites/casper/agent.js
@@ -1,3 +1,5 @@
const YES_HEADER_EXIST = true

/*global casper*/
/*jshint strict:false*/
function testUA(ua, match) {
Expand All @@ -7,10 +9,14 @@ function testUA(ua, match) {
}

function fetchUA(requestData, request) {

// [{"name":"User-Agent","value":"plop"}]
var headers = requestData.headers.filter(function(header) {
return header.name === "User-Agent";
});
casper.test.assert(headers.length > 0);
if (headers[0].name == 'User-Agent' && headers[0].value == 'plop') {
casper.test.assert(YES_HEADER_EXIST, "Yes, header exist");
}
testUA(headers.pop().value, /plop/);
}

Expand Down
38 changes: 0 additions & 38 deletions tests/suites/casper/flow.coffee

This file was deleted.

49 changes: 49 additions & 0 deletions tests/suites/casper/flow.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 0 additions & 103 deletions tests/suites/casper/request.coffee

This file was deleted.

107 changes: 106 additions & 1 deletion tests/suites/casper/request.js
@@ -1,6 +1,6 @@
/*global casper*/
/*jshint strict:false*/
var currentRequest;
var currentRequest, utils = require("utils");

function onResourceRequested(requestData, request) {
currentRequest = requestData;
Expand Down Expand Up @@ -46,3 +46,108 @@ casper.test.begin('requests tests', 3, {
});
}
});

// from request.coffee

var CHANGED_URL, ORIGINAL_URL, SERVER, onResourceReceived, onResourceReceivedWithChangeURL, onResourceRequested, onResourceRequestedWithAbort, onResourceRequestedWithChangeURL, requestURLReceived, requestURLRequested, setToTrueOnResourceReceived, setToTrueOnResourceRequested, setUp, setUpWithAbort, setUpWithChangeURL, tearDown, utils;

utils = require("utils");

SERVER = 'http://localhost:54321/';
ORIGINAL_URL = "tests/site/index.html";
CHANGED_URL = "tests/site/index.html?foo=bar";
setToTrueOnResourceRequested = false;
setToTrueOnResourceReceived = false;
requestURLRequested = '';
requestURLReceived = '';
onResourceRequested = function(casper, requestData, request) {
if (requestData.url === (SERVER + ORIGINAL_URL)) {
setToTrueOnResourceRequested = true;
return requestURLRequested = requestData.url;
}
};
onResourceRequestedWithAbort = function(casper, requestData, request) {
if (requestData.url === (SERVER + ORIGINAL_URL)) {
return request.abort();
}
};
onResourceRequestedWithChangeURL = function(casper, requestData, request) {
if (requestData.url === (SERVER + ORIGINAL_URL)) {
return request.changeUrl(SERVER + CHANGED_URL);
}
};
onResourceReceived = function(casper, response) {
if (response.url === (SERVER + ORIGINAL_URL)) {
setToTrueOnResourceReceived = true;
return requestURLReceived = response.url;
}
};
onResourceReceivedWithChangeURL = function(casper, response) {
if (response.url === (SERVER + CHANGED_URL)) {
return requestURLReceived = response.url;
}
};
setUp = function(test) {
casper.options.onResourceRequested = onResourceRequested;
casper.options.onResourceReceived = onResourceReceived;
return casper.start();
};
setUpWithAbort = function(test) {
casper.options.onResourceRequested = onResourceRequestedWithAbort;
casper.options.onResourceReceived = onResourceReceived;
return casper.start();
};
setUpWithChangeURL = function(test) {
casper.options.onResourceRequested = onResourceRequestedWithChangeURL;
casper.options.onResourceReceived = onResourceReceivedWithChangeURL;
return casper.start();
};
tearDown = function(test) {
setToTrueOnResourceRequested = false;
setToTrueOnResourceReceived = false;
casper.options.onResourceRequested = null;
return casper.options.onResourceReceived = null;
};

casper.test.begin("onResourceRequested tests without abort/override", 4, {
setUp: setUp,
tearDown: tearDown,
test: function(test) {
casper.open(ORIGINAL_URL).then(function() {});
casper.wait(200, function() {
test.assertEquals(setToTrueOnResourceRequested, true, "Casper.options.onResourceRequested called successfully");
test.assertEquals(requestURLRequested, SERVER + ORIGINAL_URL, "request url successfully recorded");
test.assertEquals(setToTrueOnResourceReceived, true, "Casper.options.onResourceReceived called successfully");
return test.assertEquals(requestURLReceived, SERVER + ORIGINAL_URL, "response url successfully recorded");
});
return casper.run(function() {
return test.done();
});
}
});
casper.test.begin("onResourceRequested tests with request.abort()", 1, {
setUp: setUpWithAbort,
tearDown: tearDown,
test: function(test) {
casper.open(ORIGINAL_URL).then(function() {});
casper.wait(200, function() {
return test.assertNotEquals(setToTrueOnResourceReceived, true, "Casper.options.onResourceReceived correctly never called");
});
return casper.run(function() {
return test.done();
});
}
});
casper.test.begin("onResourceRequested tests with request.changeUrl()", 1, {
setUp: setUpWithChangeURL,
tearDown: tearDown,
test: function(test) {
casper.open(ORIGINAL_URL).then(function() {});
casper.wait(200, function() {
return test.assertEquals(requestURLReceived, SERVER + CHANGED_URL, "response url successfully changed");
});
return casper.run(function() {
return test.done();
});
}
});
20 changes: 0 additions & 20 deletions tests/suites/coffee.coffee

This file was deleted.