e2e tests fixes

This commit is contained in:
Roman Hotsiy 2016-01-17 13:51:21 +02:00
parent 19445857f3
commit 139a0ec1b9
4 changed files with 62 additions and 17 deletions

View File

@ -13,6 +13,9 @@ let config = {
// load APIs.guru list
return loadJson('https://apis-guru.github.io/api-models/api/v1/list.json').then((list) => {
global.apisGuruList = list;
return browser.getCapabilities().then(function (cap) {
browser.isIE = cap.caps_.browserName === 'internet explorer';
});
});
},
//directConnect: true,
@ -20,10 +23,20 @@ let config = {
jasmineNodeOpts: {
showTiming: true,
showColors: true,
defaultTimeoutInterval: 60000,
defaultTimeoutInterval: 120000,
print: function() {}
},
multiCapabilities: [{
multiCapabilities: [
{ browserName: 'chrome' },
{ browserName: 'firefox' }
]
};
if (travis) {
config.sauceUser = process.env.SAUCE_USERNAME;
config.sauceKey = process.env.SAUCE_ACCESS_KEY;
config.sauceSeleniumAddres = 'localhost:4445/wd/hub';
config.multiCapabilities = [{
browserName: 'chrome',
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER,
build: process.env.TRAVIS_BUILD_NUMBER,
@ -45,14 +58,8 @@ let config = {
version: '11.0',
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER,
build: process.env.TRAVIS_BUILD_NUMBER,
name: 'Redoc Firefox Latest/Win build ' + process.env.TRAVIS_BUILD_NUMBER
}]
};
if (travis) {
config.sauceUser = process.env.SAUCE_USERNAME;
config.sauceKey = process.env.SAUCE_ACCESS_KEY;
config.sauceSeleniumAddres = 'localhost:4445/wd/hub';
name: 'Redoc IE11/Win build ' + process.env.TRAVIS_BUILD_NUMBER
}];
} else {
config.directConnect = true;
}

View File

@ -30,12 +30,25 @@ const LogLevel = {
const MAX_ERROR_MESSAGE_SYMBOLS = 128;
//copied from angular/modules/angular2/src/testing/e2e_util.ts
function verifyNoBrowserErrors() {
// IE doesn't support logs method
if (browser.isIE) {
let err = browser.executeScript('return window.redocError');
expect(err).toBeNull();
return;
}
// Bug in ChromeDriver: Need to execute at least one command
// so that the browser logs can be read out!
browser.executeScript('1+1');
browser.manage().logs().get('browser').then(function(browserLog) {
let filteredLog = browserLog.filter((logEntry) => {
let message = logEntry.message;
// skip browser-sync errors
if (message.indexOf('browser-sync') > -1) return false;
// skip firefox-specific warning
if (message.indexOf('mutating the [[Prototype]]') > -1) return false;
if (logEntry.level.value >= LogLevel.INFO) {
if (message.length > MAX_ERROR_MESSAGE_SYMBOLS) {
message = message.substr(0, MAX_ERROR_MESSAGE_SYMBOLS) + '...';
@ -43,8 +56,6 @@ function verifyNoBrowserErrors() {
console.log('>> ' + message);
}
// skip browser-sync errors
if (message.indexOf('browser-sync') > -1) return false;
return logEntry.level.value > LogLevel.WARNING;
});
expect(filteredLog.length).toEqual(0, `Found ${filteredLog.length} browser errors`);
@ -60,8 +71,20 @@ function scrollToEl(selector) {
return browser.driver.executeScript(script);
}
function fixFFTest(done) {
// firefox issue. the first try to access something from webpage fails
// but the second works fine. So skipping first error
$('body').isPresent().then(()=> {
done();
}, () => {
//error skipped
done();
})
}
module.exports = {
loadJson: loadJson,
verifyNoBrowserErrors: verifyNoBrowserErrors,
scrollToEl: scrollToEl
scrollToEl: scrollToEl,
fixFFTest: fixFFTest
}

View File

@ -1,19 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ReDoc</title>
</head>
<body>
<redoc scroll-y-offset="body > nav">
<redoc>
Loading...
</redoc>
<!-- ReDoc built file with all dependencies included -->
<script src="dist/redoc.full.min.js"> </script>
<script>
window.redocError = null;
/* init redoc */
var url = window.location.search.substr(5) || 'swagger.json';
Redoc.init(decodeURIComponent(url));
Redoc.init(decodeURIComponent(url)).then(function() {}, function(err) {
window.redocError = err;
});
</script>
</body>
</html>

View File

@ -1,6 +1,7 @@
'use strict';
const verifyNoBrowserErrors = require('./helpers').verifyNoBrowserErrors;
const scrollToEl = require('./helpers').scrollToEl;
const fixFFTest = require('./helpers').fixFFTest;
const URL = 'index.html';
@ -11,12 +12,16 @@ function basicTests(swaggerUrl, title) {
specUrl += `?url=${encodeURIComponent(swaggerUrl)}`;
}
beforeEach((done) => {
browser.get(specUrl);
fixFFTest(done);
});
afterEach(() => {
verifyNoBrowserErrors();
});
it('should init redoc without errors', () => {
browser.get(specUrl);
let $redoc = $('redoc');
expect($redoc.isPresent()).toBe(true);
let $methods = $$('method');
@ -29,8 +34,14 @@ basicTests(null, 'Extended Petstore');
describe('Scroll sync', () => {
let specUrl = URL;
beforeEach((done) => {
browser.get(specUrl);
fixFFTest(done);
});
it('should update active menu entries on page scroll', () => {
browser.get(URL);
scrollToEl('[tag="store"]').then(function() {
expect($('.menu-cat-header.active').getText()).toBe('STORE');
});