繁体   English   中英

Angular 4(弹出)和端到端测试(量角器/硒配置)

[英]Angular 4 (ejected) and E2E tests (Protractor/Selenium configuration)

我正在尝试在弹出的Angular 4项目上通过量角器/硒运行E2E测试。

我的package.json

...
"scripts": {
    "pree2e": "webdriver-manager update --standalone false --gecko false --quiet node",
    "e2e": "protractor ./protractor.conf.js"
}
...

我的protractor.conf

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    directConnect: true,
    allScriptsTimeout: 60000,
    getPageTimeout: 60000,
    specs: [
        './src/e2e/**/*.e2e-test.ts'
    ],
    capabilities: {
        'browserName': 'chrome'
    },
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 60000
    },
    onPrepare() {
        require('ts-node').register({
            project: 'tsconfig.e2e.json'
        });

        jasmine.getEnv().addReporter(new SpecReporter({
            spec: {
                displayStacktrace: true
            }
        }));

        browser.driver.manage().timeouts().setScriptTimeout(60000);
    }
};

当运行npm run e2e Chrome会启动,但它会尝试为每个测试打开data:text/html,<html></html> ,然后迅速关闭。 我想念什么? 我尝试将baseUrl添加到我的protractor.conf ,但这没有帮助,因为Selenium似乎没有运行。

我终于找到了解决我问题的方法。 我以某种方式需要运行ng serve ,由于项目被弹出,现在可以通过npm run start来运行它。 这是Travis CI部署(强烈建议),因此请参见before_script

before_script:
    - nohup npm run start &
script:
    - npm run build -aot --target=production --environment=prod
    - npm run test
    - npm run e2e

最终package.json (后仍默认ng eject ):

...
"scripts": {
    "ng": "ng",
    "lint": "ng lint",
    "build": "webpack",
    "start": "webpack-dev-server --port=4200",
    "test": "karma start ./karma.conf.js",
    "pree2e": "webdriver-manager update --standalone false --gecko false --quiet",
    "e2e": "protractor ./protractor.conf.js",
    "postinstall": "npm run build -aot --target=production --environment=prod"
}
...

Final protractor.conf (在ng eject之后仍然是默认值):

exports.config = {
    allScriptsTimeout: 11000,
    specs: [
        './src/e2e/**/*.e2e-test.ts'
    ],
    capabilities: {
        'browserName': 'chrome'
    },
    directConnect: true,
    baseUrl: 'http://localhost:4200/',
    framework: 'jasmine',
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 30000,
        print: function() {}
    },
    beforeLaunch: function() {
        require('ts-node').register({
            project: 'tsconfig.e2e.json'
        });
    },
    onPrepare() {
        jasmine.getEnv().addReporter(new SpecReporter({
            spec: {
                displayStacktrace: true
            }
        }));
    }
};

ng eject时会发生以下情况: https : //github.com/angular/angular-cli/issues/6171

腰了两天半。 谢谢Angular CLI团队针对此错误,确实,谢谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM