From 9f5767ea16848302a8b8507615cc551f0f5ca1ff Mon Sep 17 00:00:00 2001 From: nakanishi Date: Thu, 12 Jul 2018 15:28:40 +0900 Subject: [PATCH] Added test cases of flow control on cookbook --- .../nodes/core/core/20-inject_page.js | 20 +++++++++ .../editor/pageobjects/util/spec_util_page.js | 23 ++++++++++ .../pageobjects/workspace/workspace_page.js | 1 + test/editor/specs/scenario/cookbook_uispec.js | 43 +++++++++++++++++++ test/editor/wdio.conf.js | 2 +- 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 test/editor/pageobjects/util/spec_util_page.js diff --git a/test/editor/pageobjects/nodes/core/core/20-inject_page.js b/test/editor/pageobjects/nodes/core/core/20-inject_page.js index e30400423..09248f268 100644 --- a/test/editor/pageobjects/nodes/core/core/20-inject_page.js +++ b/test/editor/pageobjects/nodes/core/core/20-inject_page.js @@ -36,6 +36,13 @@ var payloadType = { "env": 9, }; +var timeType = { + "none": 1, + "interval": 2, + "intervalBetweenTimes": 3, + "atASpecificTime": 4, +}; + injectNode.prototype.setPayload = function(type, value) { // Open a payload type list. browser.clickWithWait('//*[contains(@class, "red-ui-typedInput-container")]'); @@ -50,4 +57,17 @@ injectNode.prototype.setTopic = function(value) { browser.setValue('#node-input-topic', value); } +injectNode.prototype.setOnce = function(value) { + browser.clickWithWait('#node-input-once'); +} + +injectNode.prototype.setTimeType = function(type) { + var timeTypeXPath = '//*[@id="inject-time-type-select"]/option[' + timeType[type] + ']'; + browser.clickWithWait(timeTypeXPath); +} + +injectNode.prototype.setRepeat = function(sec) { + browser.setValue('#inject-time-interval-count', sec); +} + module.exports = injectNode; diff --git a/test/editor/pageobjects/util/spec_util_page.js b/test/editor/pageobjects/util/spec_util_page.js new file mode 100644 index 000000000..f64743664 --- /dev/null +++ b/test/editor/pageobjects/util/spec_util_page.js @@ -0,0 +1,23 @@ +/** + * Copyright JS Foundation and other contributors, http://js.foundation + * + * 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. + **/ + +function pause(msec) { + browser.pause(msec); +} + + module.exports = { + pause: pause, + }; diff --git a/test/editor/pageobjects/workspace/workspace_page.js b/test/editor/pageobjects/workspace/workspace_page.js index 6c802486d..e62eb686f 100644 --- a/test/editor/pageobjects/workspace/workspace_page.js +++ b/test/editor/pageobjects/workspace/workspace_page.js @@ -36,6 +36,7 @@ function addNode(type, x, y) { } function deleteAllNodes() { + browser.click('.innerCanvas'); browser.keys(['Control', 'a', 'a', 'Control']); // call twice to release the keys. browser.keys(['Delete']); } diff --git a/test/editor/specs/scenario/cookbook_uispec.js b/test/editor/specs/scenario/cookbook_uispec.js index fb3b5705e..a29fa5891 100644 --- a/test/editor/specs/scenario/cookbook_uispec.js +++ b/test/editor/specs/scenario/cookbook_uispec.js @@ -21,6 +21,7 @@ var fs = require('fs-extra'); var helper = require("../../editor_helper"); var debugTab = require('../../pageobjects/workspace/debugTab_page'); var workspace = require('../../pageobjects/workspace/workspace_page'); +var specUtil = require('../../pageobjects/util/spec_util_page'); var nodeWidth = 200; @@ -142,4 +143,46 @@ describe('cookbook', function() { debugTab.getMessage(3).should.be.equal('5'); }); }); + + describe('flow control', function() { + it('trigger a flow whenever Node-RED starts', function() { + var injectNode = workspace.addNode("inject"); + var debugNode = workspace.addNode("debug", nodeWidth * 2); + + injectNode.edit(); + injectNode.setPayload("string", "Started!") + injectNode.setOnce(true); + injectNode.clickOk(); + injectNode.connect(debugNode); + + debugTab.open(); + debugTab.clearMessage(); + workspace.deploy(); + debugTab.getMessage().should.be.equal('"Started!"'); + }); + + it('trigger a flow at regular intervals', function() { + var injectNode = workspace.addNode("inject"); + var debugNode = workspace.addNode("debug", nodeWidth * 2); + + injectNode.edit(); + injectNode.setTimeType("interval"); + injectNode.setRepeat(1); + injectNode.clickOk(); + injectNode.connect(debugNode); + + 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); + }); + + // skip this case since it needs up to one minite. + it.skip('trigger a flow at a specific time'); + }); }); diff --git a/test/editor/wdio.conf.js b/test/editor/wdio.conf.js index eb23a9a2c..b545c205f 100644 --- a/test/editor/wdio.conf.js +++ b/test/editor/wdio.conf.js @@ -155,7 +155,7 @@ exports.config = { // Options to be passed to Mocha. // See the full list at http://mochajs.org/ mochaOpts: { - timeout: 20000, + timeout: 60000, ui: 'bdd' }, //