【发布时间】:2021-05-18 23:08:57
【问题描述】:
我有一个现有的 Angular v5 应用程序,并且有用于我的环境(如 DEV、测试、生产等)的 environment.json 文件。环境文件存储在如下目录中:src/Environments/DEV/environment.json。
这是一个开发environment.json 文件的示例:
{
"Comment": "Environment=DEV",
"API_ORIGIN": "https://myapp-dev",
"ORIGIN": "https://myapp-dev/index.html",
}
src 文件夹中有一个根 environment.json 文件,我的应用程序将从该文件夹中读取。当我想使用特定环境时,我只需将该环境内容复制到根目录并运行应用程序即可。
现在有了 Cucumber 和 Protractor,有没有一种方法可以传递一些命令行参数来根据我的设置指定要使用的 environment.json 文件?我在这些environment.json 文件中有网址,所以我需要一种方法来告诉 Cucumber 和 Protractor 使用哪个环境。如果我必须将所有environment.json 文件复制到适合我的 e2e 文件夹中。以防我需要使用的解决方案取决于我在这里使用的工具是我的tsconfig.e2e.json 文件。如有不妥请告知:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/e2e",
"baseUrl": "./",
"module": "commonjs",
"target": "es5",
"types": [
"chai",
"cucumber",
"node"
]
}
}
这是protractor.conf.js 文件。如果不正确,请告诉我:
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/features/**/*.feature'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
cucumberOpts: {
// require step definition files before executing features
require: ['./e2e/steps/**/*.ts'],
// <string[]> (expression) only execute the features or scenarios with tags matching the expression
tags: [],
// <string[]> ("extension:module") require files with the given EXTENSION after requiring MODULE (repeatable)
compiler: []
},
// Enable TypeScript for the tests
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
}
};
如果这很重要,我也会使用npm。我正在使用 angular 提供的 ng e2e 命令运行这些测试。
【问题讨论】:
标签: json protractor cucumber