本文介绍了CasperJS和'不安全的JavaScript尝试访问带URL的帧'错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的javascript页面,用于验证输入中写的电子邮件:

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;
};

我想使用CasperJS测试验证功能。这是我的测试用例:

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, '[email protected]'), 'green', '[email protected]');
        test.assertEquals(validate(this, 'vnbgfjbndkjnv'), 'red', 'vnbgfjbndkjnv');
    }).run(function() {
        test.done();
    });

});

但是当我使用 casperjs test test / validator.test.js运行测试时,在有关测试的信息后总是出现错误:

But when I run tests using casperjs test test/validator.test.js, there is always error after information about tests:

不安全的JavaScript尝试访问带有以下URL的框架:带有URL文件的框架:/// C:/Users/home/AppData/Roaming/npm/node_modules/casperjs/bin/bootstrap.js。域,协议和端口必须匹配。

出了什么问题?

PhantomJS版本:1.9.8

PhantomJS version: 1.9.8

推荐答案

最近的PhantomJS(1.9.8)引入了此错误消息。它不会导致任何实际问题,除了在退出PhantomJS时混淆日志行。

Recent PhantomJS (1.9.8) introduced this error message. It doesn't cause any real issue, other than confusing log lines when quiting PhantomJS.

它在未释放的1.9分支中修复:

It is fixed in unreleased 1.9 branch:https://github.com/ariya/phantomjs/pull/12720

这篇关于CasperJS和'不安全的JavaScript尝试访问带URL的帧'错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 02:41