簡體   English   中英

將一組文件路徑從命令行傳遞到“npm run test”?

[英]Passing set of file Paths from the command line to on “npm run test”?

我正在使用 Testcafe 將文件上傳到我的應用程序,我需要運行命令“npm run test”。 目前,我已經在我的規范腳本中硬編碼了文件路徑。

我想要實現的是使用 n 個不同的文件在 n 次循環中運行相同的規范。 到目前為止,對我來說實現這一目標的唯一方法是為具有不同文件名的 n 文件編寫 n 規范,但我不想這樣做,因為所有規范都相同。

fixture `Getting Started`
    .page `http://mywebsite.org`;

test
    .before( async t => {
     console.log("User Log Tests");
     })
    ('File_Upload', async t => {
    await t
    .click('.home-search-btn')
    .wait(5000)
    .click('.menu.icon.large-visibility>ul>li:last-
    child>ul>li>.checkbox')
    .setFilesToUpload('input[type="file"]', [
        'home/name/fileDirectory/file.json',
     ])
    .click('.icon.base-upload')
    });

我想知道是否可以自動化,以便可以從某個目錄中讀取文件名並在我的規范中進行替換。

如果您想對多個文件名執行相同的操作,您可以將它們的列表保存在一個文件中,並在夾具內或測試內的循環中使用它。 例如,如果files.js文件中有一組文件路徑,則可以使用以下方法:

// files.js
export default files = ['file1.json', 'file2.json'];

// test.js
import files from './files.js';

fixture `Getting Started`
    .page `http://mywebsite.org`;

for(const file of files) {
    test
    .before( async t => {
        console.log("User Log Tests");
    })
    (`File_Upload - ${file}`, async t => {
        await t
            .click('.home-search-btn')
            .wait(5000)
            .click('.menu.icon.large-visibility>ul>li:last-child>ul>li>.checkbox')
            .setFilesToUpload('input[type="file"]', [file])
            .click('.icon.base-upload')
    });
}

暫無
暫無

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

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