2014-12-30 3 views
2

과 비교하십시오. 사용자가 파일을 업로드하는 시스템을 구축 중입니다. Protractor로 파일 업로드를 테스트했지만 이제는 서버에서 원시 파일을 요청할 때 응답이 업로드 된 파일과 동일하다는 것을 확인해야합니다.각도기를 클릭하고 서버 응답을 파일

사용자가 링크를 클릭하여 파일을 다운로드하면 파일에 대한 일반적인 GET 요청이 트리거됩니다. 일반 텍스트 파일을 다루므로 다운로드 한 파일은 첨부 파일로 제공되지 않고 대신 브라우저에 표시됩니다. 관련 PHP 코드는 다음과 같습니다

header('Content-Type: text/plain'); 
header('Content-Length: ' . $file->getSize()); 
header('Content-Disposition: filename="file.txt"'); 

$file->openFile('rb')->fpassthru(); 

나는 두 가지 문제를 가지고 :

  1. 어떻게 전체 파일이 다운로드 될 때까지 내가 각도기 대기해야합니까?
  2. 다운로드 한 파일을 업로드 한 것과 어떻게 비교합니까?

는 여기에 지금까지 가지고있는 작업은 다음과 같습니다

var path = require('path'); 

function uploadFile(filename) { 
    var absolutPath = path.resolve(__dirname, filename); 
    $('input#fileupload').sendKeys(absolutPath); 
} 

describe('Download', function() { 

    it('should be exactly the same as an uploaded text file', function() { 
     uploadFile('data/2.txt'); 

     browser.wait(function() { 
      return element(by.id('download-button')).isPresent(); 
     }); 

     element(by.id('download-button')).click(); 

     // Wait until page is loaded 
     // Compare uploaded file with downloaded file 
    }); 
}); 
+1

당신은 [이 답변] (http://stackoverflow.com/a/27031924/771848)가 도움이 될 수 :

내가 여기,하지만이 시도하지 않은 작동 수있는 몇 가지 코드입니다. – alecxe

답변

1

sendKeys 등 대부분의 다른 각도기 API 호출이 promise을 반환합니다. 올바른 방법은 uploadFile 도우미 메서드가 해당 약속을 반환하도록하고 then을 사용하여 다음 단계를 수행하는 것입니다.

function uploadFile(filename) { 
    var absolutPath = path.resolve(__dirname, filename); 
    return $('input#fileupload').sendKeys(absolutPath); 
} 

describe('Download', function() { 

    it('should be exactly the same as an uploaded text file', function() { 
    uploadFile('data/2.txt').then(function() { 
     // add test code here if you want to 
     ... 
     element(by.id('download-button')).click().then(function() { 
     // now you should be all set to do your test 
     ... 
    }); 
    }); 
}); 
+0

시간 내 주셔서 감사합니다.하지만 제 질문은 다운로드 버튼을 클릭 할 때받은 파일과 업로드 된 파일을 비교하는 방법이었습니다. 그 점이 불투명하다면 유감입니다. –

관련 문제