2017-08-03 84 views
0

我是Bitbucket流水线的新手,所以我努力尝试在构建上运行我的Angular 2应用程序的量角器E2E测试。我的到位桶,pipelines.yml看起来像这样在Bitbucket流水线中运行Angular 2量角器

image: adrianmarinica/bitbucket-pipelines-protractor 

pipelines: 
    default: 
    - step: 
     caches: 
      - node 
     script: # Modify the commands below to build your repository. 
      - npm install 
      - protractor protractor.conf.js 

当所有依赖安装和量角器开始ruuning,我得到这个错误

enter image description here

如何运行我的测试中,我成功地做我的本地机器?

回答

1

为了在bitbucket流水线上进行e2e测试,我必须对bitbucket-pipelines.yml,package.json和protractor.conf.js进行一些更改。

首先,bitbucket-pipelines.yml看起来像这样。我们使用了adrianmarinica提供的码头图像,而不是默认的节点图像。

# You can specify a custom docker image from Docker Hub as your build environment. 
image: adrianmarinica/bitbucket-pipelines-protractor 

pipelines: 
    branches: 
     master: 
      - step: 
       caches: 
        - node 
       script: 
        - npm install 
        - npm start 
        - protractor protractor.conf.js 

然后,的package.json看起来像这样

"scripts": { 
    ... 
    "start": "ng serve &" 
    ... 
    } 

这里的关键变化是启动命令的 “&”。这将在后台运行,允许量角器命令被解雇。

最后,一些调整至protractor.conf.js

const { SpecReporter } = require('jasmine-spec-reporter'); 

exports.config = { 
    allScriptsTimeout: 1800000, 
    specs: [ 
    './e2e/**/*.e2e-spec.ts' 
    ], 
    getPageTimeout: 120000, 
    capabilities: { 
    'browserName': 'chrome', 
    'chromeOptions': { 
     'args': [ 
     '--no-sandbox', 
     '--disable-gpu' 
     ] 
    } 
    }, 
    useAllAngular2AppRoots: true, 
    directConnect: true, 
    baseUrl: 'http://localhost:4200/', 
    framework: 'jasmine', 
    jasmineNodeOpts: { 
    showColors: true, 
    defaultTimeoutInterval: 120000, 
    print: function() { } 
    }, 
    beforeLaunch: function() { 
    require('ts-node').register({ 
     project: 'e2e/tsconfig.e2e.json' 
    }); 
    }, 
    onPrepare() { 
    jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 
    } 
}; 

如果测试成功地在本地运行,他们也应该在管道,按照这个配置,环境应该是相同的。

-1

默认情况下,Protractor等待角度变量出现在网页中。它等待10秒的默认时间,然后超时。如果您的应用程序不是一个角度应用程序,你可以通过设置

browser.waitForAngularEnabled(false); 
describe

,在it部分之前将其关闭。

PS - 如果上述不起作用,请在it部分之前,在您的第一个describe块中尝试browser.ignoreSynchronization = true;,这将使量角器不等待角度承诺。

+0

这实际上是一个角度2的应用程序 – MarBVI

+0

这个肩膀适用于Angular 1/2甚至是Angular 4. – demouser123

+0

但是为了运行E2E testa,我需要将该应用程序在端口4200处对吗?我如何在管道中做到这一点?因为,如果我在脚本中放置npm start,它会卡在那里,量角器语句永远不会被触发 – MarBVI

0

这只是我的例子:(非AngularJS APP)

里面来源:test_specs.js,conf.js,bitbucket.pipeline.yml

来源:(到位桶)test_spec.js

 describe("Facebook App test", function(){ 

     beforeEach(function(){ 
     browser.driver.ignoreSynchronization = true; 

     }); 

     it("should launch the browser", function(){ 

     browser.driver.get("https://www.facebook.com");  

     console.log("Launch the browser"); 

     } 

}); 

--------------------------- 

Source: conf.js 

exports.config = { 
directConnect: true, 

allScriptsTimeout: 20000, 
capabilities: { 
'browserName': 'chrome' 
}, 

// Framework to use. Jasmine is recommended. 
framework: 'jasmine', 

// Spec patterns are relative to the current working directory when 
// protractor is called. 
specs: ['test_spec.js'], 

// Options to be passed to Jasmine. 
jasmineNodeOpts: { 
//showColors: true, 
defaultTimeoutInterval: 30000 

} 
}; 

----------------------------- 

bitbucket.pipeline.yml (**Is this correct?**) 

pipelines: 
    branches: 
     master: 
      - step: 
       caches: 
        - node 
       script: 
        - npm install 
        - npm start 
        - protractor protractor.conf.js 
+0

你应该解释为什么这是正确的解决方案。 – Difster