2014-10-31 11 views
24

ho semplice pagina con javascript che convalida e-mail scritta in ingresso:CasperJS e 'il tentativo Unsafe JavaScript per accedere telaio con URL' errore

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

voglio testare la funzionalità di convalida utilizzando CasperJS. Qui è il mio banco di prova:

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

}); 

Ma quando ho eseguito test utilizzando casperjs test test/validator.test.js, c'è sempre errore dopo informazioni sui test:

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.

Cosa c'è che non va?

PhantomJS versione: 1.9.8

+0

L'hai ristretto a una determinata linea? In caso contrario, aggiungi qualche console.log e prova a restringere il campo a una riga. –

+0

@ArtjomB. Questa riga viene stampata quando viene eseguito il passaggio di prova (dopo "test PASS 2 eseguiti in 2.693s, 2 passati ...") – michaeluskov

+0

@ArtjomB. 1.9.8 – michaeluskov

risposta

18

PhantomJS recenti (1.9.8) ha introdotto questo messaggio di errore. Quando si esce da PhantomJS, non genera alcun problema reale se non quello di confondere le righe di registro.

E 'fissato in inedito 1.9 ramo: https://github.com/ariya/phantomjs/pull/12720

+8

Questa risposta (http://stackoverflow.com/a/26688062/789683) ha una soluzione alternativa per il problema – flipchart

+0

Questo funziona correttamente per me in PhantomJS 2.2.1 –

1

Questo problema è stato risolto nella versione phantomjs 1.9

"phantomjs": "^1.9.9"

per casperJs

casperjs --ssl-protocol=tlsv1 test run.js 
0

Hey ci sono diverse soluzioni alternative per cercare di aggirare questo facendo uscire il fantoccio in un modo diverso come

casperjs --ssl-protocol=tlsv1 test run.js 

CHE NON dose di aiuto e

setTimeout(function(){ 
    phantom.exit(); 
}, 0); 

invece di

this.exit(); 

niente ha funzionato !!!

Ho provato diverse versioni di PhantomJS. La mia uscita arriva come JSON e dopo molte ore di tentativi falliti di JSON.parse (stdout) ho dovuto rinunciare. Ho pensato 'F' sto solo andando a gestire l'errore 'F'ing.

così semplice prima di uscita I

this.echo(',{"error":"'); 

e dopo mando

this.echo('"}]'); 

Quando ottengo i miei risultati indietro ho semplicemente sostituire tutte le interruzioni di riga e ignorare l'errore

stdout = stdout.replace(/(?:\r\n|\r|\n)/g, ''); 

Nota a margine: questo problema è stato provato per essere risolto con 1.9.9 phantom ma invece è focalizzato sulla costruzione di un phantom 2.0 w che non è compatibile con CasperJS

1

Stavo ottenendo lo stesso errore, quindi ho provato l'aggiornamento a phantomjs 1.9.9 (da 1.9.8). Tuttavia, ricevevo un errore di installazione durante il tentativo di installare 1.9.9, quindi ho eseguito il down-rev a phantomjs 1.9.7 e ho risolto questo errore per me. Quindi, sembra che questo sia un problema introdotto in phantomjs 1.9.8.

+0

Grazie! Se qualcuno ha bisogno di file exe precedenti: https://bitbucket.org/ariya/phantomjs/downloads – Aliz

Problemi correlati