Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2e tests #116

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
33 changes: 33 additions & 0 deletions client/app/components/about/about.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
describe('About Route', () => {

// Before each test
beforeEach(() => {

// Navigate to about component
browser.get('http://localhost:3000/about');
});

// About component should be visible
it('should be visible', () => {

// Expect home component to be visible
expect(element(by.tagName('about')).isDisplayed()).toBe(true);
});

// Link to Home navigates to Home Component
it('should navigate to Home if Home link clicked', () => {

// Click navigation to Home route
element(by.css('[ui-sref="home"]'))
.click()
.then(() => {

// Expect Home Component to be visible
expect(element(by.tagName('home')).isDisplayed()).toBe(true);

// Expect About component to be not be present
expect(element(by.tagName('about')).isPresent()).toBe(false);
})
});

});
34 changes: 34 additions & 0 deletions client/app/components/home/home.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
describe('Home Route', () => {

// Before each test
beforeEach(() => {

// Navigate to home component
browser.get('http://localhost:3000');
});


// Home component should be visible
it('should be visible', () => {

// Expect home component to be visible
expect(element(by.tagName('home')).isDisplayed()).toBe(true);
});

// Link to About navigates to About Component
it('should navigate to About if About link clicked', () => {

// Click navigation to About route
element(by.css('[ui-sref="about"]'))
.click()
.then(() => {

// Expect About Component to be visible
expect(element(by.tagName('about')).isDisplayed()).toBe(true);

// Expect Home component to not be present
expect(element(by.tagName('home')).isPresent()).toBe(false);
})
});

});
16 changes: 16 additions & 0 deletions generator/component/temp.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
describe('<%= upCaseName %> Route', () => {

// Before each test
beforeEach(() => {

// Navigate to <%= name %> component
browser.get('http://localhost:3000/<%= name %>');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

urls called with browser get are relative to the base (you dont need to put localhost:3000 there)

});

// <%= upCaseName %> component should be visible
it('should be visible', () => {

// Expect <%= upCaseName %> component to be visible
expect(element(by.tagName('<%= name %>')).isDisplayed()).toBe(true);
});
});
9 changes: 9 additions & 0 deletions generator/component/temp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ let <%= name %>Module = angular.module('<%= name %>', [
uiRouter
])

.config(($stateProvider) => {
"ngInject";
$stateProvider
.state('<%= name %>', {
url: '/<%= name %>',
template: '<<%= name %>></<%= name %>>'
});
})

.component('<%= name %>', <%= name %>Component);

export default <%= name %>Module;
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"mocha": "^2.3.0",
"ng-annotate-loader": "0.0.10",
"node-libs-browser": "^0.5.0",
"protractor": "3.1.1",
"raw-loader": "^0.5.1",
"run-sequence": "^1.1.0",
"style-loader": "^0.12.2",
Expand All @@ -44,6 +45,10 @@
"yargs": "^3.9.0"
},
"scripts": {
"preupdate-webdriver": "npm install",
"update-webdriver": "webdriver-manager update",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe run it as postinstall script?

"pree2e": "npm run update-webdriver",
"e2e": "protractor protractor.conf.js",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should move this to gulpfile, since it have all needed info about server host and port.

"test": "karma start"
},
"keywords": [
Expand Down
30 changes: 30 additions & 0 deletions protractor.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const webpackConfig = require('./webpack.config');

exports.config = {
framework: "jasmine",
baseUrl: `http://localhost:3000`,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be introspected from the configs

seleniumAddress: 'http://localhost:4444/wd/hub',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of using this, get protractor to auto download the selenium jar if it doesnt exist, and run its own server.

Just remove this line, and presto, mission accomplished!

specs: [
'client/**/**.e2e.js',
'client/**/*.e2e.js'
],
jasmineNodeOpts: {
showTiming: true,
showColors: true,
isVerbose: true,
includeStackTrace: true,
defaultTimeoutInterval: 400000
},
directConnect: true,
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['show-fps-counter=true']
}
},
allScriptsTimeout: 30000,
onPrepare: function () {
require("babel-core/register")({ retainLines: true });
browser.ignoreSynchronization = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not best practice and should be avoided. If you want to ignore synchronization, do it on a test-by-test basis rather than app wide.

}
}