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();
browser.windowHandleMaximize();
browser.call(function () {
// return when.promise(function(resolve, reject) {
return new Promise(function(resolve, reject) {
cleanup(flowFilename);
app.use("/",express.static("public"));

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -55,7 +55,6 @@ describe('cookbook', function() {
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Hello World!"');
});
@ -75,7 +74,6 @@ describe('cookbook', function() {
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql("undefined");
});
@ -99,7 +97,6 @@ describe('cookbook', function() {
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Hello"');
});
@ -134,7 +131,6 @@ describe('cookbook', function() {
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode1.clickLeftButton();
debugTab.getMessage(1).should.eql('0');
injectNode2.clickLeftButton();
@ -156,7 +152,6 @@ describe('cookbook', function() {
injectNode.connect(debugNode);
debugTab.open();
debugTab.clearMessage();
workspace.deploy();
debugTab.getMessage().should.eql('"Started!"');
});
@ -174,12 +169,11 @@ describe('cookbook', function() {
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
specUtil.pause(1000);
var t1 = Number(debugTab.getMessage(1));
t1.should.within(1500000000000, 3000000000000);
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.
@ -209,7 +203,6 @@ describe('cookbook', function() {
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Node-RED"');
});
@ -235,7 +228,6 @@ describe('cookbook', function() {
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().should.containEql('<title>Node-RED</title>');
});
@ -265,7 +257,6 @@ describe('cookbook', function() {
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().should.containEql('httpNodeRoot');
});
@ -314,7 +305,6 @@ describe('cookbook', function() {
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Hello Nick"');
});
@ -376,7 +366,6 @@ describe('cookbook', function() {
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql('"Hello"');
});
@ -398,7 +387,6 @@ describe('cookbook', function() {
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
debugTab.getMessage().should.eql(['123', '34', '104', '116', '116', '112', '78', '111', '100', '101']);
@ -446,7 +434,6 @@ describe('cookbook', function() {
workspace.deploy();
debugTab.open();
debugTab.clearMessage();
injectNode.clickLeftButton();
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
// grid with only 5 firefox instances available you can make sure that not more than
// 5 instances get started at a time.
maxInstances: 5,
maxInstances: 2,
//
browserName: 'chrome',
chromeOptions: {