【问题标题】:Execute batch file in the middle of protractor test在量角器测试中间执行批处理文件
【发布时间】:2018-11-05 12:20:10
【问题描述】:

我为我的 Web 应用程序的某些部分编写了一个测试。我需要在测试运行过程中运行批处理文件 (batch.exe)。我的测试是:

var exec = require('child_process').execFile;

describe('Sample Test', function () {

    describe('When click on browse', function () {
        beforeEach(function () {
            browser.get('http://192.168.1.152/public/documents');
            element(by.linkText('upload')).click();
            element(by.css(".dropzone")).click();


            browser.sleep(5000);

            // <---------- **** this place need to run file
            exec('file-upload.exe', function(err, data) {
                console.log(err);
                console.log(data.toString());
            });

            element(by.css("button")).click();
        });

        it('Should be', function () {
            expect(element(by.css("span")).getText()).toBe('file uploaded');
        });
    });
});

我使用了child_process节点模块,但它不起作用?我该怎么办?有没有办法解决这个问题?

【问题讨论】:

  • 它不起作用 - 什么不起作用?如果您依赖它的结果,这显然无法正常工作,因为execFile 是异步的。使用execFileSync 或承诺。
  • 请写正确的代码
  • 什么代码?你没有说明问题是什么。
  • 我解决了问题

标签: javascript node.js protractor e2e-testing


【解决方案1】:

我用这段代码解决了问题:

var exec = require('child_process').execFile;

describe('Sample Test', function () {

    describe('When click on browse', function () {
        beforeEach(function () {
            browser.get('http://192.168.1.152/public/documents');
            element(by.linkText('upload')).click();
            element(by.css(".dropzone")).click();


            browser.sleep(5000);

            // <---------- **** this place need to run file
             setTimeout(function () {
                execFile('file-upload.exe', function(error, stdout, stderr) {
                   if (error) {
                      throw error;
                   }
                   console.log(stdout);
                });
            },3000);

            element(by.css("button")).click();
        });

        it('Should be', function () {
            expect(element(by.css("span")).getText()).toBe('file uploaded');
        });
    });
});

由于 execFile 在beforeAll 函数之前运行,并且我需要暂停它多秒,我将execFile 函数放在setTimeOut 中进行延迟。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-11
    • 1970-01-01
    • 2021-11-24
    相关资源
    最近更新 更多