Skip to content

Commit

Permalink
Functional harness implemented (DevExpress#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgiy Abbasov committed Dec 25, 2015
1 parent 6345875 commit e29bc79
Show file tree
Hide file tree
Showing 12 changed files with 440 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ gulp.task('lint', function () {
'!src/client/**/*.js', //TODO: fix it
//'test/**/*.js', //TODO: fix it
'test/server/**.js',
'test/functional/**/*.js',
'test/report-design-viewer/*.js',
'Gulpfile.js'
])
Expand Down Expand Up @@ -257,3 +258,13 @@ gulp.task('publish', ['test-server'], function () {
// TODO switch publish tag once we'll be ready to release
return publish({ tag: 'alpha' });
});

gulp.task('test-functional', ['build'], function () {
return gulp
.src('test/functional/**/*-test.js')
.pipe(mocha({
ui: 'bdd',
reporter: 'spec',
timeout: typeof v8debug === 'undefined' ? 600000 : Infinity // NOTE: disable timeouts in debug
}));
});
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@
"devDependencies": {
"babel": "^5.8.23",
"babel-eslint": "^4.0.10",
"caller": "^1.0.1",
"chai": "^3.0.0",
"del": "^1.2.0",
"eslint-plugin-babel": "^2.1.1",
"express": "^4.13.3",
"gulp": "^3.9.0",
"gulp-babel": "^5.2.1",
"gulp-eslint": "^1.0.0",
Expand All @@ -65,6 +67,7 @@
"gulp-webmake": "0.0.4",
"publish-please": "^1.0.1",
"request": "^2.58.0",
"saucelabs-connector": "^0.0.2",
"tmp": "0.0.28"
},
"files": [
Expand Down
21 changes: 21 additions & 0 deletions test/functional/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"rules": {
"max-nested-callbacks": [2, 5]
},
"env": {
"browser": true,
"jquery": true,
"mocha": true
},
"globals": {
/* testcafe api */
"act": true,
"inIFrame": true,
"ok": true,
"notOk": true,
"eq": true,
"notEq": true,
/* functional harness */
"runTests": true
}
}
43 changes: 43 additions & 0 deletions test/functional/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var os = require('os');

var isTravisEnvironment = !!process.env.TRAVIS;
var hostname = isTravisEnvironment ? os.hostname() : '127.0.0.1';

module.exports = {
isTravisTask: isTravisEnvironment,
sauceLabs: {
username: process.env.SAUCE_USERNAME,
accessKey: process.env.SAUCE_ACCESS_KEY,
build: process.env.TRAVIS_JOB_ID || '',
tags: [process.env.TRAVIS_BRANCH || 'master'],
name: 'testcafe functional tests'
},
browsers: [
{
platform: 'Windows 10',
browserName: 'internet explorer',
version: '11.0',
alias: 'ie'
},
{
platform: 'Windows 10',
browserName: 'firefox',
alias: 'ff'
},
{
platform: 'Windows 10',
browserName: 'chrome',
alias: 'chrome'
}
],
testCafe: {
hostname: hostname,
port1: 2000,
port2: 2001
},
site: {
viewsPath: './test/functional/fixtures/',
port1: 3000,
port2: 3001
}
};
27 changes: 27 additions & 0 deletions test/functional/fixtures/runner/api/click/click-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var expect = require('chai').expect;

describe('api click test', function () {
it('Should fail when the first argument is invisible', function () {
return runTests('click.test.js', 'Should fail when the first argument is invisible', { shouldFail: true })
.catch(function (err) {
var expectedError = [
'Error at step "1.Click on invisible element":',
'',
'act.click($input);',
'',
'A target element \<input id="input"\> of the click action is not visible.',
'If this element should appear when you are hovering over another',
'element, make sure that you properly recorded the hover action.'
].join(' ');

expect(err).eql(expectedError);
});
});

it('Pointer events test (T191183) [ONLY:ie]', function () {
return runTests('click.test.js', 'Pointer events test (T191183) [ONLY:ie]')
.then(function (err) {
expect(err).eql('');
});
});
});
50 changes: 50 additions & 0 deletions test/functional/fixtures/runner/api/click/click.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'@fixture click';
'@page ./runner/api/click/index.html';


var userAgent = window.navigator.userAgent.toLowerCase();
var isMSEdge = !!/edge\//.test(userAgent);

var isIE11 = !!(navigator.appCodeName === 'Mozilla' &&
/trident\/7.0/.test(userAgent));


'@test'['Pointer events test (T191183) [ONLY:ie]'] = {
'1.Bind pointer event handlers and call click': function () {
var input = $('#input')[0];
var shared = this;

shared.events = [];

function pointerHandler (e) {
shared.events.push(e.type.toLowerCase().replace('ms', ''));

eq(e.pointerType, isIE11 || isMSEdge ? 'mouse' : 4);
eq(e.button, 0);
eq(e.buttons, 1);
}

if (isMSEdge) {
input.onpointerdown = pointerHandler;
input.onpointerup = pointerHandler;
}
else {
input.onmspointerdown = pointerHandler;
input.onmspointerup = pointerHandler;
}

act.click(input);
},

'2.Check that handlers were called': function () {
eq(this.events, ['pointerdown', 'pointerup']);
}
};

'@test'['Should fail when the first argument is invisible'] = {
'1.Click on invisible element': function () {
var $input = $('#input').css('visibility', 'hidden');

act.click($input);
}
};
9 changes: 9 additions & 0 deletions test/functional/fixtures/runner/api/click/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Click</title>
</head>
<body style="height: 1500px;">
<input type="button" id="input" style="position: absolute; margin-left: 100px; margin-top: 100px;"/>
</body>
</html>
3 changes: 3 additions & 0 deletions test/functional/fixtures/test_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"baseUrl": "http://localhost:3000"
}
56 changes: 56 additions & 0 deletions test/functional/helpers/report-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function isBrowserRelevant (test, browserAlias) {
var matchesOnly = test.match(/\[ONLY\:([,\s\w]*)\]/);
var matchesSkip = test.match(/\[SKIP\:([,\s\w]*)\]/);

var only = true;
var skip = false;

if (matchesOnly !== null)
only = matchesOnly[1].indexOf(browserAlias) > -1;

if (matchesSkip !== null)
skip = matchesSkip[1].indexOf(browserAlias) > -1;

return only && !skip;
}

function filterErrors (errors, userAgents) {
return errors.filter(function (error) {
return userAgents.indexOf(error.split('\n')[0]) > -1;
});
}

function getTestError (testReport, browsersInfo) {
var testError = '';

var actualUserAgents = browsersInfo
.filter(function (browserInfo) {
return isBrowserRelevant(testReport.name, browserInfo.settings.alias);
})
.map(function (browserInfo) {
return browserInfo.connection.userAgent;
});

var actualBrowsersCount = actualUserAgents.length;
var actualErrors = filterErrors(testReport.errs, actualUserAgents);
var actualErrorsCount = actualErrors.length;

if (actualErrorsCount) {
//NOTE: if the test failed in different browsers with the same error we join it to one error
if (actualErrorsCount !== actualBrowsersCount)
testError = actualErrors.join('\n');
else {
testError = actualErrors[0]
.split('\n')
.slice(1)
.map(function (str) {
return str.trim();
})
.join(' ');
}
}

return testError;
}

module.exports = getTestError;
Loading

0 comments on commit e29bc79

Please sign in to comment.