簡體   English   中英

異步創建TestCafe的動態測試

[英]Create dynamic tests for TestCafe asynchronously

我在TestCafe中創建測試。 目標是用小黃瓜編寫測試。 我看了一些將Cucumber和TestCafe集成在一起的GitHub存儲庫,但我嘗試使用另一個角度。

我想使用小黃瓜解析器並跳過黃瓜。 相反,我將創建自己的實現以運行測試步驟。 但是目前,我一直試圖讓TestCafe運行測試。

如果我是正確的,那么問題在於TestCafe正在運行我的測試文件,然后在任何地方都看不到任何固定裝置或測試。 這是正確的,因為Gherkin解析器正在使用流API(它使用單獨的Go進程來解析功能文件)來傳遞數據,這意味着在我當前的代碼中,當TestCafe退出時,Promise仍處於待處理狀態。 或者,如果我刪除該end回調尚未發生。

我的分析正確嗎? 如果是,我如何從流中獲取所有數據並創建測試,以便TestCafe可以運行它?

gherkin_executor.js

var Gherkin = require('gherkin');

console.log('start')

const getParsedGherkin = new Promise((resolve, reject) => {
    let stream = Gherkin.fromPaths(['file.feature'])

    let data = []
    stream.on('data', (chunk) => {
        if(chunk.hasOwnProperty('source')){
            data.push({source: chunk.source, name: null, pickles: []})
        }
        else if (chunk.hasOwnProperty('gherkinDocument')){
            data[data.length-1].name = chunk.gherkinDocument.feature.name
        }
        else {
            data[data.length-1].pickles.push(chunk.pickle)
        }
    })
    stream.on('end', () => {
        resolve(data)
    })
})
let data = getParsedGherkin.then((data) => {return data})
console.log(data)

function createTests(data){
    for(let feature of data){
        fixture(feature.name)
        for(let testcase of feature.pickles){
            test(testcase.name, async t => {
                console.log('test')
            })
        }
    }
}

file.feature

Feature: A test feature

    Scenario: A test case
        Given some data
        When doing some action
        Then there is some result

不錯的倡議!

為了進一步發展,方法createTests必須在至少一個JavaScript或TypeScript文件中生成TestCafe代碼。 然后,您必須從這些文件啟動TestCafe運行程序。

因此,現在,要進一步進行開發,必須編寫一個TestCafe源代碼生成器。

在TestCafe團隊正式支持Cucumber之前,也許GitHub上的hdorgeval/testcafe-starter回購可能是替代方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM