[Intern] Custom registerSuite which allows to add helpers

Using this function it is possible to add helper methods
from helpers.js to this.remote

Change-Id: I6e4e92073e751691fce296822f0f7cfedd5f1fbe
This commit is contained in:
Vitaly Kramskikh 2015-09-03 14:05:25 -05:00
parent f882c428db
commit ee1cee60cb
16 changed files with 117 additions and 50 deletions

View File

@ -14,9 +14,7 @@
* under the License.
**/
define(['underscore',
'tests/functional/pages/modal',
'../../helpers'], function(_, ModalWindow, Helpers) {
define(['underscore', 'tests/functional/pages/modal'], function(_, ModalWindow) {
'use strict';
function ClusterPage(remote) {
this.remote = remote;
@ -26,14 +24,8 @@ define(['underscore',
ClusterPage.prototype = {
constructor: ClusterPage,
goToTab: function(tabName) {
var self = this;
return this.remote
.then(function() {
return Helpers.clickLinkByText(
self.remote,
'.tabs-box .tabs a',
tabName);
});
.clickLinkByText('.tabs-box .tabs a', tabName);
},
removeCluster: function(clusterName) {
var self = this;

View File

@ -1,6 +1,21 @@
/*
* Copyright 2015 Mirantis, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
**/
define([
'underscore',
'intern/node_modules/dojo/node!fs',
'intern/chai!assert',
'../../helpers',
'tests/functional/pages/login',
@ -8,7 +23,7 @@ define([
'tests/functional/pages/cluster',
'tests/functional/pages/clusters'
],
function(_, fs, assert, Helpers, LoginPage, WelcomePage, ClusterPage, ClustersPage) {
function(_, assert, Helpers, LoginPage, WelcomePage, ClusterPage, ClustersPage) {
'use strict';
function CommonMethods(remote) {
this.remote = remote;
@ -23,19 +38,6 @@ define([
pickRandomName: function(prefix) {
return (prefix || 'Item') + ' #' + _.random(1000, 9999);
},
takeScreenshot: function(filename, error) {
return this.remote
.takeScreenshot()
.then(function(buffer) {
if (!filename) {
filename = new Date().toTimeString();
}
fs.writeFileSync('/tmp/' + filename + '.png', buffer);
if (error) {
throw error;
}
});
},
getOut: function() {
var self = this;
return this.remote

View File

@ -1,3 +1,19 @@
/*
* Copyright 2015 Mirantis, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
**/
define([
'intern/chai!assert'
],

View File

@ -16,7 +16,7 @@
define([
'underscore',
'intern!object',
'tests/register_suite',
'intern/chai!assert',
'tests/functional/pages/common',
'tests/functional/pages/cluster',

View File

@ -15,7 +15,7 @@
**/
define([
'intern!object',
'tests/register_suite',
'intern/chai!assert',
'tests/functional/pages/common',
'tests/functional/pages/cluster'

View File

@ -16,7 +16,7 @@
define([
'underscore',
'intern!object',
'tests/register_suite',
'intern/chai!assert',
'tests/functional/pages/common',
'tests/functional/pages/networks',

View File

@ -16,7 +16,7 @@
define([
'underscore',
'intern!object',
'tests/register_suite',
'intern/chai!assert',
'tests/functional/pages/modal',
'tests/functional/pages/common'

View File

@ -16,7 +16,7 @@
define([
'underscore',
'intern!object',
'tests/register_suite',
'intern/chai!assert',
'tests/functional/pages/common',
'tests/functional/pages/cluster'

View File

@ -15,7 +15,7 @@
**/
define([
'intern!object',
'tests/register_suite',
'intern/chai!assert',
'tests/functional/pages/common',
'tests/functional/pages/cluster',

View File

@ -15,7 +15,7 @@
**/
define([
'intern!object',
'tests/register_suite',
'intern/chai!assert',
'tests/functional/pages/common'
], function(registerSuite, assert, Common) {

View File

@ -15,7 +15,7 @@
**/
define([
'intern!object',
'tests/register_suite',
'intern/chai!assert',
'tests/functional/pages/login',
'tests/functional/pages/common'

View File

@ -15,7 +15,7 @@
**/
define([
'intern!object',
'tests/register_suite',
'intern/chai!assert',
'tests/functional/pages/login',
'tests/functional/pages/welcome'

View File

@ -14,9 +14,7 @@
* under the License.
**/
// jshint node:true
define(['underscore'], function(_) {
define(['underscore', 'intern/node_modules/dojo/node!fs'], function(_, fs) {
'use strict';
var serverHost = '127.0.0.1',
@ -29,21 +27,36 @@ define(['underscore'], function(_) {
username: username,
password: password,
serverUrl: serverUrl,
clickLinkByText: function(remote, cssSelector, linkText) {
return remote
.setFindTimeout(1000)
.findAllByCssSelector(cssSelector)
.then(function(links) {
return links.reduce(function(matchFound, link) {
return link.getVisibleText().then(function(text) {
if (_.trim(text) == linkText) {
link.click();
return true;
}
return matchFound;
leadfootHelpers: {
clickLinkByText: function(cssSelector, linkText) {
return new this.constructor(this, function() {
return this.parent
.setFindTimeout(1000)
.findAllByCssSelector(cssSelector)
.then(function(links) {
return links.reduce(function(matchFound, link) {
return link.getVisibleText().then(function(text) {
if (_.trim(text) == linkText) {
link.click();
return true;
}
return matchFound;
});
}, false);
});
}, false);
});
},
takeScreenshotAndSave: function(filename) {
return new this.constructor(this, function() {
return this.parent
.takeScreenshot()
.then(function(buffer) {
if (!filename) filename = new Date().toTimeString();
var targetDir = process.env.ARTIFACTS || process.cwd();
fs.writeFileSync(targetDir + '/' + filename + '.png', buffer);
});
});
}
}
};
});

View File

@ -22,6 +22,9 @@ define(['config'], function(config) {
config.paths.sinon = 'tests/bower/sinon/lib/sinon';
// FIXME(vkramskikh): workaround for https://github.com/theintern/intern/issues/348
delete config.map['*'];
return {
proxyPort: 9057,
proxyUrl: 'http://localhost:9057/',

View File

@ -0,0 +1,40 @@
/*
* Copyright 2015 Mirantis, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
**/
define([
'underscore',
'intern!object',
'intern/dojo/node!leadfoot/Command',
'./helpers'
], function(_, originalRegisterSuite, Command, helpers) {
'use strict';
function registerSuite(originalSuite) {
_.extend(Command.prototype, helpers.leadfootHelpers);
originalSuite = _.isFunction(originalSuite) ? originalSuite() : originalSuite;
var suite = Object.create(originalSuite);
suite.afterEach = function() {
this.remote.takeScreenshotAndSave();
if (originalSuite.afterEach) return originalSuite.afterEach.apply(this, arguments);
};
return originalRegisterSuite(suite);
}
return registerSuite;
});

View File

@ -405,6 +405,7 @@ function run_ui_func_selenium_tests {
{ echo 'Failed to start Nailgun'; return 1; }
SERVER_PORT=$SERVER_PORT \
ARTIFACTS=$artifacts \
${GULP} functional-tests --suites=$testcase
if [ $? -ne 0 ]; then
result=1