在量角器测试中执行批处理文件
Execute batch file in the middle of protractor test
我为 Web 应用程序的某些部分编写了测试。我需要在测试 运行ning 中 运行 批处理文件 (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
节点模块,但它不起作用?我应该怎么办?有什么办法可以解决这个问题吗?
我用这段代码解决了问题:
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
里做延迟。
我为 Web 应用程序的某些部分编写了测试。我需要在测试 运行ning 中 运行 批处理文件 (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
节点模块,但它不起作用?我应该怎么办?有什么办法可以解决这个问题吗?
我用这段代码解决了问题:
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
里做延迟。