mic*_*kov 24 javascript integration-testing phantomjs casperjs
我有简单的页面用javascript验证输入中写的电子邮件:
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>
Run Code Online (Sandbox Code Playgroud)
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;
};
Run Code Online (Sandbox Code Playgroud)
我想使用CasperJS测试验证功能.这是我的测试用例:
测试/ 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();
});
});
Run Code Online (Sandbox Code Playgroud)
但是当我使用测试时,在测试casperjs test test/validator.test.js信息之后总会出现错误:
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.
怎么了?
PhantomJS版本:1.9.8
Jak*_*aur 18
最近的PhantomJS(1.9.8)引入了此错误消息.除了在退出PhantomJS时混淆日志行之外,它不会引起任何实际问题.
它是在未发布的1.9分支中修复的:https: //github.com/ariya/phantomjs/pull/12720
| 归档时间: |
|
| 查看次数: |
13149 次 |
| 最近记录: |