2017-04-17 5 views
0

필자는 테스트 자동화를 위해 각도기 - 오이 - 프레임 워크를 사용하고 있습니다. 여러 개의 기능 파일이 있습니다. 각 기능 파일에는 여러 시나리오가 있습니다. 나는 "cucumber-html-reporter"를 사용하여 테스트 실행에 대한 HTML 보고서를 얻고 있습니다. 이 HTML 보고서는 총 기능 수 및 실행 된 총 시나리오 수에 대한 세부 정보를 제공합니다. 따라서 테스트 실행 후에 만 ​​'총 피쳐 수'와 '총 시나리오 수'를 알게되었습니다.자바 스크립트 테스트 자동화 프로젝트에서 총 기능 수와 시나리오를 얻으려면

각 기능 파일 내 자바 스크립트 테스트 자동화에

시나리오의

  • 총 수를 기능

    • 총 수를 얻을 수있는 모든 명령 또는 사용 가능한 플러그인이 있나요?

  • +0

    이것 좀보세요 - http://stackoverflow.com/questions/18004326/how-can-i-get-a-quick-count-of-the-number-of-scenarios-and-steps- in-a-large-cucu – Grasshopper

    답변

    1

    그위한 다양한 JS 스크립트, 태그 등을 AST에 작은 오이를 사용하여 기능 파일을 구문 분석 및 기능을 계산, 시나리오 포함 .. :

    예 :

    const glob = require('glob') 
    const Gherkin = require('gherkin') 
    const parser = new Gherkin.Parser() 
    
    const AST = glob 
         .sync('./specifications/**/*.feature') 
         .map(path => parser.parse(fs.readFileSync(path).toString())) 
    

    거기에서 AST 객체를 탐색하고 기능/시나리오 수 및 기타 필요한 모든 정보를 추출 할 수 있습니다.

    1

    이것은 플러그인 없이는 매우 간단합니다.

    기능 이름을 키로 사용하고 시나리오 수를 값으로 사용하여 console.log() 키로 개체를 생성하거나 나중에 볼 수 있도록 파일에 저장하는 것이 좋습니다.

    나는 두 가지 방법 (2.x 구문과 1.x 구문을 보여줄 것입니다.

    CucumberJS 2.x를 구문

    let {defineSupportCode} = require('cucumber'), 
        counter = {}; 
    
    defineSupportCode(({registerHandler, Before}) => { 
    
        registerHandler('BeforeFeature', function (feature, callback) { 
         global.featureName = function() { 
          return feature.name; 
         }; 
         callback(); 
        }); 
    
        Before(function (scenario, callback){ 
         counter[featureName()] !== undefined ? counter[featureName()] += 1 : counter[featureName()] = 1; 
         callback(); 
        }); 
    
        registerHandler('AfterFeatures', function (feature, callback) { 
         console.log(JSON.stringify(counter)); 
         callback(); 
        }); 
    }); 
    

    CucumberJS 1.x의 구문

    var counter = {}; 
    
    module.exports = function() { 
    
        this.BeforeFeature(function (feature, callback) { 
         global.featureName = function() { 
          return feature.name; 
         }; 
         callback(); 
        }); 
    
        this.Before(function (scenario, callback){ 
         counter[featureName()] !== undefined ? counter[featureName()] += 1 : counter[featureName()] = 1; 
         callback(); 
        }); 
    
        this.AfterFeatures(function (feature, callback) { 
         console.log(JSON.stringify(counter)); 
         callback(); 
        }); 
    }; 
    

    추가

    파일로이 작업을 저장하려면, 그래서 나중에 그것을 볼 수 있기를 바랍니다. fs-e를 사용하는 것이 좋습니다. xtra 라이브러리. console.log() 대신에, 이것을 사용 :

    fs = require('fs-extra'); 
    fs.writeFileSync("path/to/file.js","let suite = " + JSON.stringify(counter)); 
    

    유의하시기 바랍니다, 파일은 당신이 테스트를 실행 한 곳에서 생성됩니다.

    Given I am running from "frameworks/cucumberjs" 
    When I generate a file from "frameworks/cucumberjs/hooks/counter.js" with the fs library at "./file.js" 
    Then the file "frameworks/cucumberjs/file.js" should exist 
    
    Given I am running from "frameworks/cucumberjs" 
    When I generate a file from "frameworks/cucumberjs/features/support/hooks/counter.js" with the fs library at "./hello/file.js" 
    Then the file "frameworks/cucumberjs/hello/file.js" should exist 
    

    올바른 디렉토리에서 실행 중인지 확인하십시오. 특징

    총 수

    당신은뿐만 아니라 기능의 총 수를 원하는 경우 :

    console.log() 대신에

    :

    console.log(JSON.stringify(counter) + "\nFeature Count: " + Object.keys(counter).length) 
    

    그리고의 WriteFile의 장소 :

    fs.writeFileSync("path/to/file.js","let suite = " + JSON.stringify(counter) + ", featureCount = " + Object.keys(counter).length); 
    

    시나리오 이름을 각 피쳐 이름별로 정렬 했으므로 작성한 객체 내의 키의 양을 알려 주면 피쳐 수를 계산할 수 있습니다.그 구조에서

    +0

    Faims - 세부 설명을 주셔서 대단히 감사합니다. –