0

在 cmd 中运行时不需要参数。基本上,它将参数作为参数并在整个文件中搜索该参数并运行所有文件,如果有任何匹配该参数,它不限于特定的。

像文件一样

1.login_account_spec.js

代码:

    var frisby = require("frisby");
    const Joi = frisby.Joi;

   console.log(process.argv)

    /**
    * Commandline parameter includes
    */
    /*  
    var name = process.env['name'];
    var password = process.env['password'];
    var dateTime = record.getDateTime();

    frisby.globalSetup({
        request: { 
            headers : { 
                    "accept": "application/json", 
                    "content-type" : "application/json", 
            }
        }
    });

    it("Test login_account" + dateTime, function (done){
        frisby.get(url)
        .expect("status", 200)
        .expect("header", "content-type", "application/json; charset=utf-8")
        .expect("jsonTypes", "data", {
            "message" : Joi.string(),
            })
        .then(function(res) {
            var body = res.body;
            body = JSON.parse(body);
            expect(body.data.message).toBeDefined();

        })
        .then(function(res) {
            record.createLogFile("login_account" + dateTime, null, res);
        })
        .done(done);
    }); 

2.get_device_details_spec.js

代码:

 var frisby = require("frisby");
 const Joi = frisby.Joi;

    console.log(process.argv)


    frisby.globalSetup({
        request: { 
            headers : { 
                "Accept": "application/json", 
                "content-type" : "application/json" 
            }
        }
    });

    it("Test get_device_details" + dateTime, function(done){
        frisby.get(url)
        .expect("status", 200)
        .expect("header", "content-type", "application/json; charset=utf-8")
        .expect("jsonTypes", "data", {
            "description": Joi.string(),
        })
            .then(function(res) {
                var body = res.body;
                body = JSON.parse(body);
                expect(body.data.description).toBeDefined();
            })  
        .after(function(res) {
            record.createLogFile("get_device_details" + dateTime, err, res);
        })
        .done(done);
});

Unit_test.bat包含脚本(这里只有两个)

@echo off
set URL=%1
set NAME=%2
set PASSWORD=%3

set /a var2=1
set /a var=0
set /a varx=0
IF /I "%ITERATION%" NEQ "0" (
    SET var2=%ITERATION%
    SET /a ITERATION=1
)

for /L %%n in (1,%ITERATION%,%var2%) do @(

    jest login_account_spec.js %URL% %NAME% %PASSWORD% 

    REM jest get_device_details_spec.js %URL%  %NAME% %PASSWORD% 

)

在 CMD 中:

Unit_Test.bat 192.168.1.17:XXXX 测试1 123

然后它给出了这两个文件的结果,并且这些 js 文件与 Frisby 相关。

所以我想只运行(login_account_spec.js)带有我在 cmd 中传递的参数的文件。但是,它给出了我不想要的两个脚本的结果,它也没有接受我传递的参数。

4

1 回答 1

0

.bat 文件

@echo off
set URL=%1
set HTTPMODE=%2
set USERNAME=%3
set PASSWORD=%4
set ENCRYPTION=%5
set ITERATION=%6
set COMPANYID=%7

REM call current_time.bat   
        REM set config={"httpMode": "%HTTPMODE%","url": "%URL%","encryption": "%ENCRYPTION%","username": "%USERNAME%@gmail.com","password": "%PASSWORD%","companyId": "%COMPANYID%","role": "Owner"}

在 .js 文件中:

var objConfig = JSON.parse(process.env.config);

var username = objConfig.username;
var encryption = objConfig.encryption;

最后在 cmd 上运行:xx.bat 用户名密码...

希望对其他人有所帮助

于 2019-02-01T06:43:25.100 回答