2016-08-11 1 views
-1

모카 차이와 악몽으로 테스트를 실행하는 연습을하고 있습니다. 내 평가 블록에 들어갈 때까지 모든 것이 작동하는 것 같습니다.내 악몽 테스트가 내 평가문에 들어 가지 않습니다.

var Nightmare = require('nightmare'), 
    should = require('chai').should() 

describe('Frontend Masters', function() { 
    this.timeout(20000); 

    it('should show form when loaded', function(done) { 
    var nightmare = new Nightmare({show: true}) 
    nightmare 
     .goto('https://frontendmasters.com/') 
     .wait('a[href*="https://frontendmasters.com/login/"]') 
     .click('a[href*="https://frontendmasters.com/login/"]') 
     .wait('#rcp_login_form') 
     .evaluate(function() { 
     return window.document.title; 
     }, function(result) { 
     result.should.equal('Login to Frontend Masters'); 
     done(); 
     }) 
     .run(function(){ 
     console.log('done') 
     }); 
    }); 
}); 

나는 콘솔 로그에 던져 버렸고 평가에 넣지 않았다. 여러 셀렉터를 wait() 함수에 전달하려고 시도했지만 효과가없는 것 같습니다. 내가받는 오류는 시간 초과가 초과되었다는 것입니다. 하지만 내가 얼마나 오랫동안 그것을 설정 중요하지 않습니다

+0

evaluate' '와 함께 할 아무것도하지 않는 것 같습니다. 'wait' 시간 초과가 실패하면 이전 클릭이 작동하지 않거나 사이트가 손상됩니다. 그건 그렇고, 두 번의 대기 호출 중 어느 것이 실패 했습니까? –

+1

환경 변수 DEBUG = "nightmare *"로 실행할 때 유용한 결과를 얻었습니까? – yoz

답변

1

어떤 버전의 악몽을 사용하고 있습니까?

.evaluate()의 서명이 변경되었으며, 문제의 출처가 될 수 있습니다. 전달한 두 번째 함수 (평가 결과를 처리하는 데 사용 된 함수)는 실제로 첫 번째 .evaluate() 인수에 대한 인수로 전달됩니다. 즉, 두 번째 인수는 실행되지 않으며 done()은 호출되지 않으며 테스트가 시간 초과됩니다.

또한 언급 할만한 가치가 있습니다 : .run() is not directly supported. 대신 .then()을 사용하십시오.

마지막으로, 이제 당신이 시작하는 위를 반영하기 위해 소스를 수정할 수 :

var Nightmare = require('nightmare'), 
    should = require('chai') 
    .should() 

describe('Frontend Masters', function() { 
    this.timeout(20000); 

    it('should show form when loaded', function(done) { 
    var nightmare = new Nightmare({ 
     show: true 
    }) 
    nightmare 
     .goto('https://frontendmasters.com/') 
     .wait('a[href*="https://frontendmasters.com/login/"]') 
     .click('a[href*="https://frontendmasters.com/login/"]') 
     .wait('#rcp_login_form') 
     .evaluate(function() { 
     return window.document.title; 
     }) 
     .then(function(result) { 
     result.should.equal('Login to Frontend Masters'); 
     console.log('done') 
     done(); 
     }) 
    }); 
}); 
관련 문제