2017-07-11 27 views
0

我正在嘗試啓動測試時遇到量角器惱人的問題。量角器「 - 失敗:無法讀取屬性」ver「爲空」

量角器版本:5.1.2

protractor.conf.js

var SpecReporter = require('jasmine-spec-reporter'); 

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

終端到終端的測試文件 「app.comp.e2e-spec.js」

import { browser, element, by, $ } from 'protractor'; 

describe('testproject App', function() { 

    it('should display message saying app works', (done) => { 
    browser.get('/'); 
    expect($('.my-span').isPresent()).toBe(true); 
    return done(); 
    }); 

}); 

我每次啓動測試(量角器protractor.conf.js)時遇到以下錯誤消息:

1) testproject App should display message saying app works 
- Failed: Cannot read property 'ver' of null 

Executed 1 of 1 spec (1 FAILED) in 0.984 sec. 
[11:27:52] I/launcher - 0 instance(s) of WebDriver still running 
[11:27:52] I/launcher - chrome #01 failed 1 test(s) 
[11:27:52] I/launcher - overall: 1 failed spec(s) 
[11:27:52] E/launcher - Process exited with error code 1 

我當然有一個在localhost:8080/index上運行的Angular應用程序,當用瀏覽器手動訪問時,它完美的工作。有人會有任何想法來解決這個問題嗎?在此先感謝

+0

Thnx的所有信息,但這是真正的所有日誌,你有沒有參考日誌中的文件? – wswebcreation

+0

@wswebcreation請在這裏找到完整的命令輸出:https://pastebin.com/3tLdGGvw – Bil5

+0

我記得在jasmine-spec-reporter中有一個選項可以在日誌中啓用堆棧跟蹤,你可以打開它或禁用'jasmine-spec-reporter'並將日誌放在這裏? – wswebcreation

回答

-1
expect($('.my-span').isPresent()).toBe(true); 

isPresent()返回承諾不是真或假。

要檢查元件存在時,使用許諾返回值:

element(anyFinder).isPresent().then(function(isPresent) { 
    if (isPresent) { 
    // The element is present 
    } else { 
    // The element is not present 
} 
}); 
+2

這是部分正確。茉莉花你仍然可以使用'期待TOBE(真)($()isPresent()「我的跨度。」);',它會解決它從內部茉莉花 – wswebcreation

+1

感謝Dharam但wswebcreation說,它仍然是可能的與您的代碼使用的其他方式,反正我有同樣的錯誤信息 – Bil5

+0

一些等待添加到您的代碼,並也通過 .isDisplayed())toEqual(錯誤檢查)。 – Dharam

0

在我的情況,當應用程序的配置/負載期間觸發意外的警報消息升至此錯誤。這是由於未能與外部系統進行通信而發生的,這隻發生在Travis CI中。由於這是唯一的錯誤信息,因此需要很長時間才能確定真正的原因。 (尤里卡時刻是當我在正常和錯誤處理程序中用一個.then()調用browser.get()時單獨故意失敗的expect()測試;這會用更多信息和有用的替代'ver'失敗關於意外警報的故障消息。)

解決方案是取消對外部系統的依賴關係(首先不應該在測試配置中)。