Angular 2
Hoek 2 - gradenboog
Zoeken…
Navbar-routing testen met gradenboog
Laten we eerst basis navbar.html maken met 3 opties. (Home, Lijst, Maken)
<nav class="navbar navbar-default" role="navigation">
<ul class="nav navbar-nav">
<li>
<a id="home-navbar" routerLink="/home">Home</a>
</li>
<li>
<a id="list-navbar" routerLink="/create" >List</a>
</li>
<li>
<a id="create-navbar" routerLink="/create">Create</a>
</li>
</ul>
tweede laten we navbar.e2e-spec.ts maken
describe('Navbar', () => {
beforeEach(() => {
browser.get('home'); // before each test navigate to home page.
});
it('testing Navbar', () => {
browser.sleep(2000).then(function(){
checkNavbarTexts();
navigateToListPage();
});
});
function checkNavbarTexts(){
element(by.id('home-navbar')).getText().then(function(text){ // Promise
expect(text).toEqual('Home');
});
element(by.id('list-navbar')).getText().then(function(text){ // Promise
expect(text).toEqual('List');
});
element(by.id('create-navbar')).getText().then(function(text){ // Promise
expect(text).toEqual('Create');
});
}
function navigateToListPage(){
element(by.id('list-home')).click().then(function(){ // first find list-home a tag and than click
browser.sleep(2000).then(function(){
browser.getCurrentUrl().then(function(actualUrl){ // promise
expect(actualUrl.indexOf('list') !== -1).toBeTruthy(); // check the current url is list
});
});
});
}
});
Angular2 Gradenboog - Installatie
voer de volgende opdrachten uit op cmd
-
npm install -g protractor
-
webdriver-manager update
-
webdriver-manager start
** maak het bestand protractor.conf.js in de hoofd-root van de app.
zeer belangrijk om gebruik te declareren 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;
maak een basistest op dev directory.
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();
});
});
});
});
uitvoeren in cmd
protractor conf.js
Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow