24

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

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
michaeluskov
  • 1,729
  • 7
  • 27
  • 53
  • Have you narrowed it down which line causes this? If not, add some console.log and try to narrow it down to one line. – Artjom B. Oct 31 '14 at 09:00
  • @ArtjomB. This line is printed when test passing is done (after `PASS 2 tests executed in 2.693s, 2 passed...`) – michaeluskov Oct 31 '14 at 09:03
  • This is because of some change that was introduced in PhantomJS 1.9.8 and there is a [CasperJS issue](https://github.com/n1k0/casperjs/issues/1068) about it. So [this](http://stackoverflow.com/questions/26608391/using-phantomjs-to-embed-all-images-of-a-webpage) might be related, but since this error comes up when the script finished, I don't see what can be done. – Artjom B. Oct 31 '14 at 09:30
  • Ok, this happens when the script exits. I don't see that anything can be done for CasperJS to remove those warnings. I created a [GitHub issue](https://github.com/ariya/phantomjs/issues/12697) for the PhantomJS problem. – Artjom B. Nov 01 '14 at 10:03

4 Answers4

18

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

Jakozaur
  • 1,957
  • 3
  • 18
  • 20
1

This issue is fixed in phantomjs version 1.9

"phantomjs": "^1.9.9"

for casperJs

casperjs --ssl-protocol=tlsv1 test  run.js
PPB
  • 2,937
  • 3
  • 17
  • 12
1

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.

forgivenson
  • 4,394
  • 2
  • 19
  • 28
noobie
  • 11
  • 1
  • Thank you ! If someone needs previous exe files: https://bitbucket.org/ariya/phantomjs/downloads – Aliz Feb 06 '17 at 16:12
0

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

Peter the Russian
  • 1,170
  • 8
  • 9