问题
I have simple page with javascript which validates email written in input:
email.html:
<!DOCTYPE html>
<html>
<head>
<title>Email validation</title>
<script src="email.js"></script>
</head>
<body>
<span style="padding: 5px;">
<input type="text" id="email-input" placeholder="Email..."></input>
</span>
</body>
</html>
email.js:
var checkEmail = function() {
var regexp = /BIG_REGEX/;
var email = document.getElementById('email-input').value;
if (email === '')
removeFrame();
else if (regexp.test(email))
drawFrame('green');
else
drawFrame('red');
};
var removeFrame = function() {
var input = document.getElementById('email-input');
input.parentNode.style.backgroundColor = input.parentNode.parentNode.style.backgroundColor;
};
var drawFrame = function(color) {
var input = document.getElementById('email-input');
input.parentNode.style.backgroundColor = color;
};
window.onload = function() {
document.getElementById('email-input').onkeyup = checkEmail;
};
I want to test validation functionality using CasperJS. Here is my test case:
test/validator.test.js:
var fillEmail = function(browser, email) {
browser.sendKeys('#email-input', email, {reset: true});
};
var getValidation = function(browser) {
var color = browser.evaluate(function () {
return document.getElementById('email-input').parentNode.style.backgroundColor;
});
return color;
};
var validate = function(browser, email) {
fillEmail(browser, email);
return getValidation(browser);
};
casper.test.begin('Validation testing', function suite(test) {
casper.start('http://localhost:8000/email.html', function() {
test.assertEquals(validate(this, 'uskovm@gmail.com'), 'green', 'uskovm@gmail.com');
test.assertEquals(validate(this, 'vnbgfjbndkjnv'), 'red', 'vnbgfjbndkjnv');
}).run(function() {
test.done();
});
});
But when I run tests using casperjs test test/validator.test.js
, there is always error after information about tests:
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///C:/Users/home/AppData/Roaming/npm/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.
What's wrong?
PhantomJS version: 1.9.8
回答1:
Recent PhantomJS (1.9.8) introduced this error message. It doesn't cause any real issue, other than confusing log lines when quiting PhantomJS.
It is fixed in unreleased 1.9 branch: https://github.com/ariya/phantomjs/pull/12720
回答2:
This issue is fixed in phantomjs version 1.9
"phantomjs": "^1.9.9"
for casperJs
casperjs --ssl-protocol=tlsv1 test run.js
回答3:
I was getting this same error, so I tried updating to phantomjs 1.9.9
(from 1.9.8
). However, I was getting an install error when trying to install 1.9.9
, so I down rev-ed to phantomjs 1.9.7
, and that fixed this error for me. So, it seems like this is an issue introduced in phantomjs 1.9.8
.
回答4:
Hey there are several workarounds to try and get around this by exiting phantom in a different way such as
casperjs --ssl-protocol=tlsv1 test run.js
WHICH DOSE NOT HELP and
setTimeout(function(){
phantom.exit();
}, 0);
instead of
this.exit();
Nothing has worked!!!
I tried several different versions of PhantomJS. My output comes in as JSON and after many hours of failed attempts of JSON.parse(stdout)I had to give up. I figured 'F' it I'm just going to handle the 'F'ing error.
so simple before i exit i
this.echo(',{"error":"');
and After I send
this.echo('"}]');
When i get my results back i simply replace all the line breaks and ignore the error
stdout = stdout.replace(/(?:\r\n|\r|\n)/g, '');
Side note: this problem was tried to be fixed with phantom 1.9.9 but instead the focussed on building phantom 2.0 which is not compatible with CasperJS
来源:https://stackoverflow.com/questions/26670696/casperjs-and-unsafe-javascript-attempt-to-access-frame-with-url-error