Mam prostą stronę z javascript, która zatwierdza email napisane na wejściu:CasperJS i 'próba Niebezpieczne JavaScript, żeby uzyskać dostęp do ramki z URL' Błąd
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;
};
Chcę przetestować funkcję sprawdzania poprawności za pomocą CasperJS. Tu jest mój przypadek testowy:
testów/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();
});
});
Ale kiedy uruchomić testy z wykorzystaniem casperjs test test/validator.test.js
, zawsze jest błąd po informacje na temat testów:
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.
Co jest nie tak? Wersja
PhantomJS: 1.9.8
Czy zawęziłeś linię, która to powoduje? Jeśli nie, dodaj plik console.log i spróbuj zawęzić go do jednej linii. –
@ArtjomB. Ta linia jest drukowana po zakończeniu wykonywania testu (po wykonaniu testów "PASS 2" w 2.693s, 2 przeszło ... ") – michaeluskov
@ArtjomB. 1.9.8 – michaeluskov