From 2201c9062fe33ea3eded15d5cd63a6468a77ac08 Mon Sep 17 00:00:00 2001 From: Yuma Matsuura Date: Thu, 19 Jul 2018 13:17:41 +0900 Subject: [PATCH] Add UItest for http request --- .../nodes/core/core/20-inject_page.js | 9 +- .../nodes/core/core/58-debug_page.js | 19 ++ .../nodes/core/core/80-function_page.js | 35 +++ .../nodes/core/core/80-template_page.js | 55 ++++ .../nodes/core/io/21-httpin_page.js | 51 ++++ .../nodes/core/io/21-httprequest_page.js | 59 ++++ .../nodes/core/io/21-httpresponse_page.js | 27 ++ .../nodes/core/logic/15-change_page.js | 48 +++- .../nodes/core/parsers/70-HTML_page.js | 31 ++ .../pageobjects/nodes/nodefactory_page.js | 13 + .../pageobjects/workspace/palette_page.js | 6 + test/editor/specs/scenario/cookbook_uispec.js | 272 +++++++++++++++++- 12 files changed, 620 insertions(+), 5 deletions(-) create mode 100644 test/editor/pageobjects/nodes/core/core/80-function_page.js create mode 100644 test/editor/pageobjects/nodes/core/core/80-template_page.js create mode 100644 test/editor/pageobjects/nodes/core/io/21-httpin_page.js create mode 100644 test/editor/pageobjects/nodes/core/io/21-httprequest_page.js create mode 100644 test/editor/pageobjects/nodes/core/io/21-httpresponse_page.js create mode 100644 test/editor/pageobjects/nodes/core/parsers/70-HTML_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 09248f268..3ba0b26d3 100644 --- a/test/editor/pageobjects/nodes/core/core/20-inject_page.js +++ b/test/editor/pageobjects/nodes/core/core/20-inject_page.js @@ -27,7 +27,7 @@ util.inherits(injectNode, nodePage); var payloadType = { "flow": 1, "global": 2, - "string": 3, + "str": 3, "num": 4, "bool": 5, "json": 6, @@ -43,6 +43,13 @@ var timeType = { "atASpecificTime": 4, }; +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")]'); diff --git a/test/editor/pageobjects/nodes/core/core/58-debug_page.js b/test/editor/pageobjects/nodes/core/core/58-debug_page.js index f87f29646..b04e4a228 100644 --- a/test/editor/pageobjects/nodes/core/core/58-debug_page.js +++ b/test/editor/pageobjects/nodes/core/core/58-debug_page.js @@ -24,4 +24,23 @@ function debugNode(id) { util.inherits(debugNode, nodePage); +var target = { + "msg": 1, + "full": 2 +}; + +debugNode.prototype.setTarget = function(type, value) { + // Open a payload type list. + browser.clickWithWait('//*[contains(@class, "red-ui-typedInput-container")]/button'); + // Select a payload type. + var xPath = '/html/body/div[11]/a[' + target[type] + ']'; + browser.clickWithWait(xPath); + if (value) { + browser.clickWithWait('//*[contains(@class, "red-ui-typedInput-input")]/input'); + browser.keys(['Control', 'a', 'Control']); + browser.keys(['Delete']); + browser.setValue('//*[contains(@class, "red-ui-typedInput-input")]/input', value); + } +} + module.exports = debugNode; diff --git a/test/editor/pageobjects/nodes/core/core/80-function_page.js b/test/editor/pageobjects/nodes/core/core/80-function_page.js new file mode 100644 index 000000000..1cd47f8b9 --- /dev/null +++ b/test/editor/pageobjects/nodes/core/core/80-function_page.js @@ -0,0 +1,35 @@ +/** + * 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. + **/ + +var util = require("util"); + +var nodePage = require("../../node_page"); + +function functionNode(id) { + nodePage.call(this, id); +} + +util.inherits(functionNode, nodePage); + +functionNode.prototype.setCode = function(value) { + browser.click('#node-input-func-editor'); + browser.keys(['Control', 'Home', 'Control']); + for (var i=0; iNode-RED'); + }); + + it('set the URL of a request using a template', function() { + var injectNode = workspace.addNode("inject"); + var changeNode = workspace.addNode("change", nodeWidth * 1.5); + var httpRequetNode = workspace.addNode("httpRequest", nodeWidth * 2.5); + var debugNode = workspace.addNode("debug", nodeWidth * 3.5); + + injectNode.edit(); + injectNode.setPayload("str", 'settings'); + injectNode.clickOk(); + + changeNode.edit(); + changeNode.ruleSet("query", "msg", "payload", "msg"); + changeNode.clickOk(); + + httpRequetNode.edit(); + httpRequetNode.setUrl(helper.url() + "/{{{query}}}"); + httpRequetNode.clickOk(); + + injectNode.connect(changeNode); + changeNode.connect(httpRequetNode); + httpRequetNode.connect(debugNode); + + workspace.deploy(); + + debugTab.open(); + debugTab.clearMessage(); + injectNode.clickLeftButton(); + debugTab.getMessage().should.containEql('httpNodeRoot'); + }); + + it('set the query string parameters', function() { + var injectNode = workspace.addNode("inject"); + var changeNode = workspace.addNode("change", nodeWidth); + var httpRequetNode = workspace.addNode("httpRequest", nodeWidth * 2); + var debugNode = workspace.addNode("debug", nodeWidth * 3); + + injectNode.edit(); + injectNode.setPayload("str", 'Nick'); + injectNode.clickOk(); + + changeNode.edit(); + changeNode.ruleSet("query", "msg", "payload", "msg"); + changeNode.clickOk(); + + httpRequetNode.edit(); + httpRequetNode.setUrl(helper.url() + httpNodeRoot + '/set-query?q={{{query}}}'); + httpRequetNode.clickOk(); + + injectNode.connect(changeNode); + changeNode.connect(httpRequetNode); + httpRequetNode.connect(debugNode); + + // The code for confirmation starts from here. + var httpinNode = workspace.addNode("httpin", 0, nodeHeight); + var templateNode = workspace.addNode("template", nodeWidth, nodeHeight); + var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 2, nodeHeight); + + httpinNode.edit(); + httpinNode.setMethod("get"); + httpinNode.setUrl("/set-query"); + httpinNode.clickOk(); + + templateNode.edit(); + templateNode.setSyntax("mustache"); + templateNode.setFormat("handlebars"); + templateNode.setTemplate("Hello {{req.query.q}}"); + templateNode.clickOk(); + + httpinNode.connect(templateNode); + templateNode.connect(httpResponseNode); + // The code for confirmation ends here. + + workspace.deploy(); + debugTab.open(); + debugTab.clearMessage(); + injectNode.clickLeftButton(); + debugTab.getMessage().should.eql('"Hello Nick"'); + }); + + it('get a parsed JSON response', function() { + var injectNode = workspace.addNode("inject"); + var changeNode_setPost = workspace.addNode("change", nodeWidth); + var httpRequetNode = workspace.addNode("httpRequest", nodeWidth * 2); + var debugNode = workspace.addNode("debug", nodeWidth * 3); + + injectNode.edit(); + injectNode.setPayload("str", "json-response"); + injectNode.clickOk(); + + changeNode_setPost.edit(); + changeNode_setPost.ruleSet("post", "msg", "payload", "msg"); + changeNode_setPost.clickOk(); + + httpRequetNode.edit(); + httpRequetNode.setMethod("get"); + var url = helper.url() + httpNodeRoot + "/{{post}}"; + httpRequetNode.setUrl(url); + httpRequetNode.setRet("obj"); + httpRequetNode.clickOk(); + + debugNode.edit(); + debugNode.setTarget("msg", "payload.title"); + debugNode.clickOk(); + + injectNode.connect(changeNode_setPost); + changeNode_setPost.connect(httpRequetNode); + httpRequetNode.connect(debugNode); + + // The code for confirmation starts from here. + var httpinNode = workspace.addNode("httpin", 0, nodeHeight); + var templateNode = workspace.addNode("template", nodeWidth * 1.5, nodeHeight); + var changeNode_setHeader = workspace.addNode("change", nodeWidth * 2.5, nodeHeight); + var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 3.5, nodeHeight); + + httpinNode.edit(); + httpinNode.setMethod("get"); + httpinNode.setUrl("/json-response"); + httpinNode.clickOk(); + + templateNode.edit(); + templateNode.setSyntax("mustache"); + templateNode.setFormat("handlebars"); + templateNode.setTemplate("{\"title\": \"Hello\"}"); + templateNode.clickOk(); + + changeNode_setHeader.edit(); + changeNode_setHeader.ruleSet("headers", "msg", "{\"content-type\":\"application/json\"}", "json"); + changeNode_setHeader.clickOk(); + + httpinNode.connect(templateNode); + templateNode.connect(changeNode_setHeader); + changeNode_setHeader.connect(httpResponseNode); + // The code for confirmation ends here. + + workspace.deploy(); + debugTab.open(); + debugTab.clearMessage(); + injectNode.clickLeftButton(); + debugTab.getMessage().should.eql('"Hello"'); + }); + + it('get a binary response', function() { + var injectNode = workspace.addNode("inject"); + var httpRequetNode = workspace.addNode("httpRequest", nodeWidth); + var debugNode = workspace.addNode("debug", nodeWidth * 2); + + httpRequetNode.edit(); + httpRequetNode.setMethod("get"); + httpRequetNode.setUrl(helper.url() + "/settings"); + httpRequetNode.setRet("bin"); + httpRequetNode.clickOk(); + + injectNode.connect(httpRequetNode); + httpRequetNode.connect(debugNode); + + workspace.deploy(); + + debugTab.open(); + debugTab.clearMessage(); + injectNode.clickLeftButton(); + + debugTab.getMessage().should.eql(['123', '34', '104', '116', '116', '112', '78', '111', '100', '101']); + }); + + it('set a request header', function() { + var injectNode = workspace.addNode("inject"); + var functionNode = workspace.addNode("function", nodeWidth); + var httpRequetNode = workspace.addNode("httpRequest", nodeWidth * 2); + var debugNode = workspace.addNode("debug", nodeWidth * 3); + + functionNode.edit(); + functionNode.setCode("msg.payload = \"data to post\";"); + functionNode.clickOk(); + + httpRequetNode.edit(); + httpRequetNode.setMethod("post"); + var url = helper.url() + httpNodeRoot + "/set-header"; + httpRequetNode.setUrl(url); + httpRequetNode.clickOk(); + + injectNode.connect(functionNode); + functionNode.connect(httpRequetNode); + httpRequetNode.connect(debugNode); + + // The code for confirmation starts from here. + var httpinNode = workspace.addNode("httpin", 0, nodeHeight); + var templateNode = workspace.addNode("template", nodeWidth * 1.5, nodeHeight); + var httpResponseNode = workspace.addNode("httpResponse", nodeWidth * 2.5, nodeHeight); + + httpinNode.edit(); + httpinNode.setMethod("post"); + httpinNode.setUrl("/set-header"); + httpinNode.clickOk(); + + templateNode.edit(); + templateNode.setSyntax("mustache"); + templateNode.setFormat("handlebars"); + templateNode.setTemplate("{{ payload }}"); + templateNode.clickOk(); + + httpinNode.connect(templateNode); + templateNode.connect(httpResponseNode); + // The code for confirmation ends here. + + workspace.deploy(); + debugTab.open(); + debugTab.clearMessage(); + injectNode.clickLeftButton(); + debugTab.getMessage().should.eql('"data to post"'); + }); + }); });