Skip to content

Commit

Permalink
try to fix e2e issues (#9)
Browse files Browse the repository at this point in the history
1. fix E2E errors
2. use http-server to lauch local server on travis
3. use sauce-connect to test on localhost
4. use saucelab timeout parameters
5. only run build on master branch
  • Loading branch information
PinkyJie committed Dec 24, 2015
1 parent 41681b3 commit d97cf5f
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
branches:
only:
- master
language: node_js
node_js:
- stable
script:
- ./publish-to-gh-pages.sh
after_success:
- npm run codecov
- npm run server
- npm run e2e -- --ci --build-id=$TRAVIS_BUILD_NUMBER
env:
global:
- GitHub_REF: github.com/PinkyJie/angular1-webpack-starter.git
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"test:watch": "karma start ./karma.config.js --watch",
"webdriver-update": "webdriver-manager update",
"webdriver-start": "webdriver-manager start",
"e2e": "protractor ./protractor.config.js"
"e2e": "protractor ./protractor.config.js",
"server": "http-server ./build &"
},
"author": {
"name": "马斯特",
Expand Down Expand Up @@ -49,6 +50,7 @@
"extract-text-webpack-plugin": "^0.9.1",
"file-loader": "^0.8.4",
"html-webpack-plugin": "^1.6.1",
"http-server": "^0.8.5",
"isparta-loader": "^1.0.0",
"jade": "^1.11.0",
"jade-html-loader": "0.0.3",
Expand Down
69 changes: 44 additions & 25 deletions protractor.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ const args = require('yargs').argv;
const e2eBaseFolder = './source/test/e2e';

const config = {
baseUrl: `http://localhost:${webpackConfig.devServer.port}`,
framework: 'jasmine2',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
defaultTimeoutInterval: 90000,
// remove ugly protractor dot reporter
print: () => {}
},
Expand All @@ -22,18 +23,20 @@ const config = {
const helper = require('./source/test/e2e/helper'); // eslint-disable-line
browser._BasePageObject = helper.BasePageObject;
browser._ = new helper.E2EHelper();
// screenshot reporter
jasmine.getEnv().addReporter(new HtmlScreenshotReporter({
dest: `${e2eBaseFolder}/screenshots`,
filename: 'e2e-report.html',
captureOnlyFailedSpecs: true,
reportOnlyFailedSpecs: false,
pathBuilder: (currentSpec) => {
// TODO: can not get browser name due to
// https://github.com/mlison/protractor-jasmine2-screenshot-reporter/issues/4
return currentSpec.description.replace(/[ :]/g, '-');
}
}));
if (!args.ci) {
// screenshot reporter
jasmine.getEnv().addReporter(new HtmlScreenshotReporter({
dest: `${e2eBaseFolder}/screenshots`,
filename: 'e2e-report.html',
captureOnlyFailedSpecs: true,
reportOnlyFailedSpecs: false,
pathBuilder: (currentSpec) => {
// TODO: can not get browser name due to
// https://github.com/mlison/protractor-jasmine2-screenshot-reporter/issues/4
return currentSpec.description.replace(/[ :]/g, '-');
}
}));
}
// add jasmine spec reporter
jasmine.getEnv().addReporter(new SpecReporter({
displayStacktrace: 'all',
Expand All @@ -51,50 +54,66 @@ const config = {

if (args.ci) {
// run by sauce lab
config.seleniumAddress = 'http://sd4399340:[email protected]/wd/hub';
config.baseUrl = 'http://localhost:8080/#';
config.sauceUser = 'sd4399340';
config.sauceKey = '5829a37c-41c0-4490-b6c2-061ae4acc5e9';
// https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/
config.multiCapabilities = [
{
name: `chrome-on-windows-${args.buildId}`,
name: `Chrome (build-${args.buildId})`,
build: args.buildId,
browserName: 'chrome',
platform: 'Windows 7'
platform: 'Windows 7',
maxDuration: 3600,
commandTimeout: 600,
idleTimeout: 1000
},
{
name: `safari-on-mac-${args.buildId}`,
name: `Safari (build-${args.buildId})`,
build: args.buildId,
browserName: 'safari',
platform: 'OS X 10.11'
platform: 'OS X 10.11',
maxDuration: 3600,
commandTimeout: 600,
idleTimeout: 1000
},
{
name: `ie9-on-windows-${args.buildId}`,
name: `IE (build-${args.buildId})`,
build: args.buildId,
browserName: 'internet explorer',
platform: 'Windows 7',
version: '9.0'
version: '11.0',
maxDuration: 3600,
commandTimeout: 600,
idleTimeout: 1000
},
{
name: `safari-on-iphone-${args.buildId}`,
name: `iOS (build-${args.buildId})`,
build: args.buildId,
browserName: 'iphone',
platform: 'OS X 10.10',
version: '9.1',
deviceName: 'iPhone 5s',
deviceOrientation: 'portrait'
deviceOrientation: 'portrait',
maxDuration: 3600,
commandTimeout: 600,
idleTimeout: 1000
},
{
name: `chrome-on-andoird-${args.buildId}`,
name: `Android (build-${args.buildId})`,
build: args.buildId,
browserName: 'android',
platform: 'Linux',
version: '4.4',
deviceName: 'Android Emulator',
deviceOrientation: 'portrait'
deviceOrientation: 'portrait',
maxDuration: 3600,
commandTimeout: 600,
idleTimeout: 1000
}
];
} else {
// local run
config.baseUrl = `http://${webpackConfig.devServer.host}:${webpackConfig.devServer.port}/`;
config.capabilities = {
browserName: 'chrome'
};
Expand Down
4 changes: 2 additions & 2 deletions source/test/e2e/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class BasePageObject {
const homeItem = breadcrumb.homeItem;
expect(homeItem.view.isDisplayed()).toBe(true);
expect(homeItem.view.$(homeItem.link).getAttribute('href'))
.toEqual(`${browser.baseUrl}`);
.toEqual(`${browser.baseUrl}/`);
expect(homeItem.view.$(homeItem.icon)).toHaveClass('mdi-action-home');
// items
expect(breadcrumb.breadcrumbItem.view.count()).toEqual(expectedBreadcrumbItems.length);
Expand Down Expand Up @@ -168,7 +168,7 @@ class BasePageObject {

class E2EHelper {
gotoUrl (url) {
browser.get(`${browser.baseUrl}${url}`);
browser.get(`${browser.baseUrl}/${url}`);
}

chooseDate (input, picker, date) {
Expand Down
4 changes: 3 additions & 1 deletion source/test/e2e/specs/phone-add.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ describe('Phone Add Page:', () => {
});

it('should add phone correctly via form', () => {
const now = new Date();
const newPhone = {
Model: 'iPhone 17',
OS: 'iOS',
Price: '9999',
'Screen Size': '9.9',
Manufacturer: 'AppleApple',
'Release Date': 'November 20, 2015',
date: '2015-11-20'
// always use today's date for easy testing
date: `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`
};
page.ele.form.assertEditingForm(newPhone, true);
// back to phone main page
Expand Down

0 comments on commit d97cf5f

Please sign in to comment.