Javascript 如何在量角器中的套件之间共享相同的测试用例

Javascript 如何在量角器中的套件之间共享相同的测试用例,javascript,angular,selenium,jasmine,protractor,Javascript,Angular,Selenium,Jasmine,Protractor,我有一些测试用例可以在测试套件之间共享 假设套件x和套件y共享同一组测试用例(it功能) 我已经创建了一个单独的.js文件,其中包含类似下面这样的共享代码 module.exports = function(a,b){ //... test cases.. //.... } 我正在尝试在x和y中使用此模块 这就是x的样子 var common = require('./module'); describe("description", module(a,b); 这能做到吗?还有别的办法吗

我有一些测试用例可以在测试套件之间共享

假设套件x和套件y共享同一组测试用例(it功能)

我已经创建了一个单独的.js文件,其中包含类似下面这样的共享代码

module.exports = function(a,b){
//...
test cases..
//....
}
我正在尝试在x和y中使用此模块

这就是x的样子

var common = require('./module');

describe("description", module(a,b);
这能做到吗?还有别的办法吗

我的代码中常见的js如下所示

module.exports = function(a,b) {

beforeAll(function(){
//some code
}
afterAll(function(){
//some code
}

It(‘ads’, function(){
code
}

it(‘ads’, function(){
code
}

it(‘ads’, function(){
code
}


}
我想在另外两个套件中使用此参数作为descripe函数的函数参数,该函数具有可通过的参数

套房1

var common = ('./common');
describe('this is a test case', common(a,b);

这可能吗?

如果您的common.js文件类似于

module.exports = function(a,b){
//...
test cases..
//....
}
以及您的test.js文件:

var common = require('./common'); // <-- note the change

describe("description", common); // <-- you were calling module*
还有你的测试

var other = require('./other');

describe("description", function() {
    it('should pass', function() {
        expect(other.testOne()).toEqual(false);
    });
});

据我所知,您不能直接从另一个文件运行“it”。但是,您可以运行函数,函数可以完成“it”所能完成的一切。例如:

Helper.js(这是您的函数文件)

然后在您的测试中
Test1:

const helper = require('relative/path/to/file/helper.js');
describe('Doing test 1 stuff',function(){
  it('Should run test',function(){
    helper.itFunctionOne();
    helper.itFunctionTwo();
  }
}
Test2:

const helper = require('relative/path/to/file/helper.js');
describe('Doing test 2 stuff',function(){
  it('Should run test',function(){
    helper.itFunctionOne();
    helper.itFunctionTwo();
  }
}

编写方法,例如,
openBrowser(…)
,并在两套套装中运行此方法。您能否向所有人解释一下您的输入?我已修改了问题,最后一部分是我当前的代码是什么样子的。请让我知道,如果我的请求是可能的,我也依靠之前和之后的功能登录和注销用户。我无法将任何参数传递给helper函数
const helper = require('relative/path/to/file/helper.js');
describe('Doing test 1 stuff',function(){
  it('Should run test',function(){
    helper.itFunctionOne();
    helper.itFunctionTwo();
  }
}
const helper = require('relative/path/to/file/helper.js');
describe('Doing test 2 stuff',function(){
  it('Should run test',function(){
    helper.itFunctionOne();
    helper.itFunctionTwo();
  }
}