Protractor 如何在量角器中使用外部函数.js文件

Protractor 如何在量角器中使用外部函数.js文件,protractor,external,Protractor,External,我有一些重复函数,我想将它们隔离在另一个文件中,以便在量角器中使用。我不想把它们和测试放在同一个文件中。我该怎么做?我在外部非角度网站上运行量角器,如下所示: protractor conf.js 因此,在spec.js中,我只想重用以下类型的函数: function someFunction() { console.log("We are in a function"); } 如何将它们放在另一个.js文件或类似文件中?谢谢你的建议 my-module.js module.expo

我有一些重复函数,我想将它们隔离在另一个文件中,以便在量角器中使用。我不想把它们和测试放在同一个文件中。我该怎么做?我在外部非角度网站上运行量角器,如下所示:

protractor conf.js
因此,在spec.js中,我只想重用以下类型的函数:

function someFunction() {
    console.log("We are in a function");
}
如何将它们放在另一个.js文件或类似文件中?谢谢你的建议

my-module.js

module.exports = {
    custom_function: function() {
        console.log("whatever")
    }
};
规格js

const custom_function = (require("./my-module.js")).custom_function;

describe("Suite: UCare - Provider Search - 'Places' tab", () => {

    it("1", async () => {
        custom_function();
    });
});
my-module.js

module.exports = {
    custom_function: function() {
        console.log("whatever")
    }
};
规格js

const custom_function = (require("./my-module.js")).custom_function;

describe("Suite: UCare - Provider Search - 'Places' tab", () => {

    it("1", async () => {
        custom_function();
    });
});

你可以创建另一个文件,把你想要的函数放进去,然后导出模块

module.exports = {
    someFunctions: {

        someFunction: () => {
            console.log("We are in a function");
        };

    }
}
将其“导入”到等级库文件中:

const functionsPageObject = require('../your/path/functionsFile');
然后使用它们:

functionsPageObject.someFunctions.someFunction();

你可以创建另一个文件,把你想要的函数放进去,然后导出模块

module.exports = {
    someFunctions: {

        someFunction: () => {
            console.log("We are in a function");
        };

    }
}
将其“导入”到等级库文件中:

const functionsPageObject = require('../your/path/functionsFile');
然后使用它们:

functionsPageObject.someFunctions.someFunction();

谢谢同时,我无意中发现了,但这也是正确的答案。谢谢!同时,我偶然发现了,但这也是正确的答案。