2017-08-03 83 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