Angular2 Protractor - 安裝
在 cmd 執行以下命令
npm install -g protractor
webdriver-manager update
webdriver-manager start
**在主應用程式根目錄中建立 protractor.conf.js 檔案。
decleare useAllAngular2AppRoots 非常重要:true
const config = {
baseUrl: 'http://localhost:3000/',
specs: [
'./dev/**/*.e2e-spec.js'
],
exclude: [],
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
isVerbose: false,
includeStackTrace: false
},
directConnect: true,
capabilities: {
browserName: 'chrome',
shardTestFiles: false,
chromeOptions: {
'args': ['--disable-web-security ','--no-sandbox', 'disable-extensions', 'start-maximized', 'enable-crash-reporter-for-testing']
}
},
onPrepare: function() {
const SpecReporter = require('jasmine-spec-reporter');
// add jasmine spec reporter
jasmine.getEnv().addReporter(new SpecReporter({ displayStacktrace: true }));
browser.ignoreSynchronization = false;
},
useAllAngular2AppRoots: true
};
if (process.env.TRAVIS) {
config.capabilities = {
browserName: 'firefox'
};
}
exports.config = config;
在 dev 目錄下建立基本測試。
describe('basic test', () => {
beforeEach(() => {
browser.get('http://google.com');
});
it('testing basic test', () => {
browser.sleep(2000).then(function(){
browser.getCurrentUrl().then(function(actualUrl){
expect(actualUrl.indexOf('google') !== -1).toBeTruthy();
});
});
});
});
在 cmd 中執行
protractor conf.js