1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Fixed UI test problems caused by timing

This commit is contained in:
nakanishi 2018-10-31 09:27:33 +09:00
parent c0d8f904b3
commit d033c24fe5
12 changed files with 75 additions and 60 deletions

View File

@ -75,7 +75,6 @@ module.exports = {
var flowFilename = getFlowFilename(); var flowFilename = getFlowFilename();
browser.windowHandleMaximize(); browser.windowHandleMaximize();
browser.call(function () { browser.call(function () {
// return when.promise(function(resolve, reject) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
cleanup(flowFilename); cleanup(flowFilename);
app.use("/",express.static("public")); app.use("/",express.static("public"));

View File

@ -14,8 +14,13 @@
* limitations under the License. * limitations under the License.
**/ **/
function open() { function open(retainMessage) {
browser.clickWithWait('#red-ui-tab-debug-link-button'); browser.clickWithWait('#red-ui-tab-debug-link-button');
if (!retainMessage) {
// Clear old messages
browser.clickWithWait('//a[@id="debug-tab-clear"]');
}
} }
function getMessage(index) { function getMessage(index) {

View File

@ -73,6 +73,8 @@ function deploy() {
}); });
}); });
browser.waitForText('#btn-deploy', 2000); browser.waitForText('#btn-deploy', 2000);
// Need additional wait until buttons becomes clickable.
browser.pause(50);
} }
function init(width, height) { function init(width, height) {

View File

@ -34,7 +34,7 @@ functionNode.prototype.setFunction = function(func) {
browser.keys(['Control', 'Shift', 'End', 'Shift', 'Control']); browser.keys(['Control', 'Shift', 'End', 'Shift', 'Control']);
browser.keys(['Delete']); browser.keys(['Delete']);
// Need to wait until ace editor correctly checks the syntax. // Need to wait until ace editor correctly checks the syntax.
browser.pause(50); browser.pause(300);
} }
module.exports = functionNode; module.exports = functionNode;

View File

@ -41,6 +41,8 @@ templateNode.prototype.setTemplate = function(template) {
} }
browser.keys(['Control', 'Shift', 'End', 'Shift', 'Control']); browser.keys(['Control', 'Shift', 'End', 'Shift', 'Control']);
browser.keys(['Delete']); browser.keys(['Delete']);
// Need to wait until ace editor correctly checks the syntax.
browser.pause(300);
} }
module.exports = templateNode; module.exports = templateNode;

View File

@ -29,6 +29,7 @@ Node.prototype.clickOk = function() {
browser.clickWithWait('#node-dialog-ok'); browser.clickWithWait('#node-dialog-ok');
// Wait untile an edit dialog closes. // Wait untile an edit dialog closes.
browser.waitForVisible('#node-dialog-ok', 2000, true); browser.waitForVisible('#node-dialog-ok', 2000, true);
browser.pause(50);
} }
Node.prototype.connect = function(targetNode) { Node.prototype.connect = function(targetNode) {

View File

@ -14,35 +14,68 @@
* limitations under the License. * limitations under the License.
**/ **/
var waitTime = 5000;
function repeatUntilSuccess(operation, args) {
// Wait at most 10 seconds.
for (var i = 0; i < 200; i++) {
try {
var ret = operation(args);
return ret;
} catch (e) {
if (i === 199) {
console.trace();
throw e;
}
browser.pause(50);
}
}
}
function init() { function init() {
browser.addCommand("clickWithWait", function(selector) { browser.addCommand("clickWithWait", function(selector) {
browser.waitForVisible(selector); try {
// Wait at most 10 seconds. // This is necessary because there is a case that the target may exist but still moving.
for (var i = 0; i < 50; i++) { browser.pause(50);
try { browser.waitForVisible(selector);
var ret = browser.click(selector);
return ret; var ret = repeatUntilSuccess(function(selector) {
} catch (err) { return browser.click(selector);
if (err.message.indexOf('is not clickable') !== -1) { }, selector);
browser.pause(200); return ret;
} else { } catch (e) {
throw err; console.trace();
} throw e;
}
} }
}, false); }, false);
browser.addCommand("getTextWithWait", function(selector) { browser.addCommand("getTextWithWait", function(selector) {
browser.waitForExist(selector); try {
browser.waitForValue(selector); browser.waitForExist(selector);
var ret = browser.getText(selector); browser.waitForValue(selector);
return ret;
var ret = repeatUntilSuccess(function(selector) {
return browser.getText(selector);
}, selector);
return ret;
} catch (e) {
console.trace();
throw e;
}
}, false); }, false);
browser.addCommand("selectWithWait", function(selector, value) { browser.addCommand("selectWithWait", function(selector, value) {
browser.waitForVisible(selector, 5000); try {
var ret = browser.selectByValue(selector, value); browser.waitForVisible(selector, waitTime);
return ret;
var ret = repeatUntilSuccess(function(args) {
return browser.selectByValue(args[0], args[1]);
}, [selector, value]);
return ret;
} catch (e) {
console.trace();
throw e;
}
}, false); }, false);
} }

View File

@ -48,7 +48,6 @@ describe('Workspace', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.within(1500000000000, 3000000000000); debugTab.getMessage().should.within(1500000000000, 3000000000000);
}); });

View File

@ -72,7 +72,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().indexOf('Hello World!').should.not.eql(-1); debugTab.getMessage().indexOf('Hello World!').should.not.eql(-1);
}); });
@ -112,7 +111,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1); debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1);
}); });
@ -152,7 +150,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().indexOf('Hello Dave!').should.not.eql(-1); debugTab.getMessage().indexOf('Hello Dave!').should.not.eql(-1);
}); });
@ -198,7 +195,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().indexOf('Mozilla').should.not.eql(-1); debugTab.getMessage().indexOf('Mozilla').should.not.eql(-1);
}); });
@ -257,7 +253,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNodeTimestamp.clickLeftButton(); injectNodeTimestamp.clickLeftButton();
injectNodeCheck.clickLeftButton(); injectNodeCheck.clickLeftButton();
var index = debugTab.getMessage().indexOf('Time: ') + 6; var index = debugTab.getMessage().indexOf('Time: ') + 6;
@ -294,6 +289,7 @@ describe('cookbook', function() {
// The code for confirmation starts from here. // The code for confirmation starts from here.
var injectNode = workspace.addNode("inject", 0, 200); var injectNode = workspace.addNode("inject", 0, 200);
var httpRequestNode = workspace.addNode("httpRequest"); var httpRequestNode = workspace.addNode("httpRequest");
var changeNodeCheck = workspace.addNode("change");
var debugNode = workspace.addNode("debug"); var debugNode = workspace.addNode("debug");
httpRequestNode.edit(); httpRequestNode.edit();
@ -301,21 +297,20 @@ describe('cookbook', function() {
httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-json'); httpRequestNode.setUrl(helper.url() + httpNodeRoot + '/hello-json');
httpRequestNode.clickOk(); httpRequestNode.clickOk();
debugNode.edit(); changeNodeCheck.edit();
debugNode.setOutput("headers"); changeNodeCheck.ruleSet("payload", "msg", "headers.content-type", "msg", "1");
debugNode.clickOk(); changeNodeCheck.clickOk();
injectNode.connect(httpRequestNode); injectNode.connect(httpRequestNode);
httpRequestNode.connect(debugNode); httpRequestNode.connect(changeNodeCheck);
changeNodeCheck.connect(debugNode);
// The code for confirmation ends here. // The code for confirmation ends here.
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
var messages = debugTab.getMessage(); var messages = debugTab.getMessage();
var contents = messages.join([separator = ""]); messages.indexOf('application/json').should.not.eql(-1);
contents.indexOf('application/json').should.not.eql(-1);
}); });
it('serve a local file', function () { it('serve a local file', function () {
@ -360,7 +355,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().indexOf('Text file').should.not.eql(-1); debugTab.getMessage().indexOf('Text file').should.not.eql(-1);
}); });
@ -404,7 +398,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1); debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1);
}); });
@ -454,7 +447,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1); debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1);
}); });
@ -504,7 +496,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1); debugTab.getMessage().indexOf('Hello Nick!').should.not.eql(-1);
}); });

View File

@ -105,7 +105,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"22"'); debugTab.getMessage().should.eql('"22"');
}); });
@ -141,7 +140,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"22"'); debugTab.getMessage().should.eql('"22"');
}); });
@ -164,7 +162,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.clearMessage();
// The code for confirmation starts from here. // The code for confirmation starts from here.
var mqttInNode = workspace.addNode("mqttIn", 0, 100); var mqttInNode = workspace.addNode("mqttIn", 0, 100);
@ -178,7 +175,7 @@ describe('cookbook', function() {
// The code for confirmation ends here. // The code for confirmation ends here.
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open(true);
debugTab.getMessage().should.eql('"22"'); debugTab.getMessage().should.eql('"22"');
}); });
@ -218,7 +215,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.eql(['1234', '13']); debugTab.getMessage().should.eql(['1234', '13']);
}); });

View File

@ -55,7 +55,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Hello World!"'); debugTab.getMessage().should.eql('"Hello World!"');
}); });
@ -75,7 +74,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.eql("undefined"); debugTab.getMessage().should.eql("undefined");
}); });
@ -99,7 +97,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Hello"'); debugTab.getMessage().should.eql('"Hello"');
}); });
@ -134,7 +131,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode1.clickLeftButton(); injectNode1.clickLeftButton();
debugTab.getMessage(1).should.eql('0'); debugTab.getMessage(1).should.eql('0');
injectNode2.clickLeftButton(); injectNode2.clickLeftButton();
@ -156,7 +152,6 @@ describe('cookbook', function() {
injectNode.connect(debugNode); injectNode.connect(debugNode);
debugTab.open(); debugTab.open();
debugTab.clearMessage();
workspace.deploy(); workspace.deploy();
debugTab.getMessage().should.eql('"Started!"'); debugTab.getMessage().should.eql('"Started!"');
}); });
@ -174,12 +169,11 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
specUtil.pause(1000); specUtil.pause(1000);
var t1 = Number(debugTab.getMessage(1)); var t1 = Number(debugTab.getMessage(1));
t1.should.within(1500000000000, 3000000000000); t1.should.within(1500000000000, 3000000000000);
specUtil.pause(1000); specUtil.pause(1000);
debugTab.getMessage(2).should.within(t1 + 1000, 3000000000000); debugTab.getMessage(2).should.within(t1 + 900, 3000000000000);
}); });
// skip this case since it needs up to one minite. // skip this case since it needs up to one minite.
@ -209,7 +203,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Node-RED"'); debugTab.getMessage().should.eql('"Node-RED"');
}); });
@ -235,7 +228,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.containEql('<title>Node-RED</title>'); debugTab.getMessage().should.containEql('<title>Node-RED</title>');
}); });
@ -265,7 +257,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.containEql('httpNodeRoot'); debugTab.getMessage().should.containEql('httpNodeRoot');
}); });
@ -314,7 +305,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Hello Nick"'); debugTab.getMessage().should.eql('"Hello Nick"');
}); });
@ -376,7 +366,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Hello"'); debugTab.getMessage().should.eql('"Hello"');
}); });
@ -398,7 +387,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.eql(['123', '34', '104', '116', '116', '112', '78', '111', '100', '101']); debugTab.getMessage().should.eql(['123', '34', '104', '116', '116', '112', '78', '111', '100', '101']);
@ -446,7 +434,6 @@ describe('cookbook', function() {
workspace.deploy(); workspace.deploy();
debugTab.open(); debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton(); injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"data to post"'); debugTab.getMessage().should.eql('"data to post"');
}); });

View File

@ -58,7 +58,7 @@ exports.config = {
// maxInstances can get overwritten per capability. So if you have an in-house Selenium // maxInstances can get overwritten per capability. So if you have an in-house Selenium
// grid with only 5 firefox instances available you can make sure that not more than // grid with only 5 firefox instances available you can make sure that not more than
// 5 instances get started at a time. // 5 instances get started at a time.
maxInstances: 5, maxInstances: 2,
// //
browserName: 'chrome', browserName: 'chrome',
chromeOptions: { chromeOptions: {