topological-nodered-wdio 0.5.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,105 +1,105 @@
1
- const common = require('./wdio-common')
2
-
3
- module.exports = function(RED) {
4
- function elementAction(config) {
5
- RED.nodes.createNode(this, config)
6
- const node = this
7
- const context = node.context()
8
- common.clearStatus(node)
9
-
10
- var getTypeInputValue = async (msg, type, value) => {
11
- var r = ''
12
- switch (type) {
13
- case 'msg':
14
- r = RED.util.getMessageProperty(msg, value)
15
- break
16
- case 'flow':
17
- r = context.flow.get(value)
18
- break
19
- case 'global':
20
- r = context.global.get(value)
21
- break
22
- case 'str':
23
- try {
24
- r = unescape(JSON.parse('"' + value + '"'))
25
- } catch (e) {
26
- r = value
27
- }
28
- break
29
- case 'num':
30
- r = parseFloat(value)
31
- break
32
- case 'json':
33
- if (value !== '') {
34
- r = JSON.parse(value)
35
- } else {
36
- r = undefined
37
- }
38
- }
39
- return r
40
- }
41
-
42
- node.on('input', async (msg) => {
43
- try {
44
- let locateUsing = config.locateUsing || msg.locateUsing
45
- let locateValue = config.locateValue || msg.locateValue
46
-
47
- let browser = await common.getBrowser(context)
48
- let capabilities = browser.capabilities
49
- let elementId = await common.getElementId(
50
- browser,
51
- locateUsing,
52
- locateValue
53
- )
54
-
55
- let attribute = config.attribute || msg.attribute
56
-
57
- if (config.action === 'click') {
58
- node.log = `Click on the webelement identified using ${locateUsing}: "${locateValue}".`
59
- await browser.elementClick(elementId)
60
- } else if (config.action === 'clear') {
61
- node.log = `Clear the Value of the webelement identified using ${locateUsing}: "${locateValue}".`
62
- await browser.elementClear(elementId)
63
- } else if (config.action === 'sendKeys') {
64
- let value = await getTypeInputValue(
65
- msg,
66
- config.object,
67
- config.sendKeys
68
- )
69
- node.log = `Enter the Value: "${value}" to the webelement identified using ${locateUsing}: "${locateValue}".`
70
- await browser.elementSendKeys(
71
- elementId,
72
- capabilities.version ? Array.from(value) : value
73
- )
74
- } else if (config.action === 'getValue') {
75
- node.log = `Get the Value of webelement identified using ${locateUsing}: "${locateValue}".`
76
- msg.payload = await browser.getElementAttribute(elementId, 'value')
77
- } else if (config.action === 'getText') {
78
- node.log = `Get the Text of webelement identified using ${locateUsing}: "${locateValue}".`
79
- msg.payload = await browser.getElementText(elementId)
80
- } else if (config.action === 'getAttribute') {
81
- node.log = `Get the Attribute: "${attribute}" of webelement identified using ${locateUsing}: "${locateValue}".`
82
- msg.payload = await browser.getElementAttribute(elementId, attribute)
83
- } else if (config.action === 'takeScreenShot') {
84
- node.log = 'Take the screenshot of the webelement.'
85
- msg.payload = await browser.takeElementScreenshot(elementId)
86
- } else if (config.action === 'hover') {
87
- let element = await common.getElement(
88
- browser,
89
- locateUsing,
90
- locateValue
91
- )
92
- node.log = `Hover on the webelement identified using ${locateUsing}: "${locateValue}".`
93
- msg.payload = await element.moveTo()
94
- }
95
- await common.log(node)
96
- common.successStatus(node)
97
- node.send(msg)
98
- } catch (e) {
99
- await common.log(node)
100
- common.handleError(e, node, msg)
101
- }
102
- })
103
- }
104
- RED.nodes.registerType('element-action', elementAction)
105
- }
1
+ const common = require('./wdio-common')
2
+
3
+ module.exports = function(RED) {
4
+ function elementAction(config) {
5
+ RED.nodes.createNode(this, config)
6
+ const node = this
7
+ const context = node.context()
8
+ common.clearStatus(node)
9
+
10
+ var getTypeInputValue = async (msg, type, value) => {
11
+ var r = ''
12
+ switch (type) {
13
+ case 'msg':
14
+ r = RED.util.getMessageProperty(msg, value)
15
+ break
16
+ case 'flow':
17
+ r = context.flow.get(value)
18
+ break
19
+ case 'global':
20
+ r = context.global.get(value)
21
+ break
22
+ case 'str':
23
+ try {
24
+ r = unescape(JSON.parse('"' + value + '"'))
25
+ } catch (e) {
26
+ r = value
27
+ }
28
+ break
29
+ case 'num':
30
+ r = parseFloat(value)
31
+ break
32
+ case 'json':
33
+ if (value !== '') {
34
+ r = JSON.parse(value)
35
+ } else {
36
+ r = undefined
37
+ }
38
+ }
39
+ return r
40
+ }
41
+
42
+ node.on('input', async (msg) => {
43
+ try {
44
+ let locateUsing = config.locateUsing || msg.locateUsing
45
+ let locateValue = config.locateValue || msg.locateValue
46
+
47
+ let browser = await common.getBrowser(context)
48
+ let capabilities = browser.capabilities
49
+ let elementId = await common.getElementId(
50
+ browser,
51
+ locateUsing,
52
+ locateValue
53
+ )
54
+
55
+ let attribute = config.attribute || msg.attribute
56
+
57
+ if (config.action === 'click') {
58
+ node.log = `Click on the webelement identified using ${locateUsing}: "${locateValue}".`
59
+ await browser.elementClick(elementId)
60
+ } else if (config.action === 'clear') {
61
+ node.log = `Clear the Value of the webelement identified using ${locateUsing}: "${locateValue}".`
62
+ await browser.elementClear(elementId)
63
+ } else if (config.action === 'sendKeys') {
64
+ let value = await getTypeInputValue(
65
+ msg,
66
+ config.object,
67
+ config.sendKeys
68
+ )
69
+ node.log = `Enter the Value: "${value}" to the webelement identified using ${locateUsing}: "${locateValue}".`
70
+ await browser.elementSendKeys(
71
+ elementId,
72
+ capabilities.version ? Array.from(value) : value
73
+ )
74
+ } else if (config.action === 'getValue') {
75
+ node.log = `Get the Value of webelement identified using ${locateUsing}: "${locateValue}".`
76
+ msg.payload = await browser.getElementAttribute(elementId, 'value')
77
+ } else if (config.action === 'getText') {
78
+ node.log = `Get the Text of webelement identified using ${locateUsing}: "${locateValue}".`
79
+ msg.payload = await browser.getElementText(elementId)
80
+ } else if (config.action === 'getAttribute') {
81
+ node.log = `Get the Attribute: "${attribute}" of webelement identified using ${locateUsing}: "${locateValue}".`
82
+ msg.payload = await browser.getElementAttribute(elementId, attribute)
83
+ } else if (config.action === 'takeScreenShot') {
84
+ node.log = 'Take the screenshot of the webelement.'
85
+ msg.payload = await browser.takeElementScreenshot(elementId)
86
+ } else if (config.action === 'hover') {
87
+ let element = await common.getElement(
88
+ browser,
89
+ locateUsing,
90
+ locateValue
91
+ )
92
+ node.log = `Hover on the webelement identified using ${locateUsing}: "${locateValue}".`
93
+ msg.payload = await element.moveTo()
94
+ }
95
+ await common.log(node)
96
+ common.successStatus(node)
97
+ node.send(msg)
98
+ } catch (e) {
99
+ await common.log(node)
100
+ common.handleError(e, node, msg)
101
+ }
102
+ })
103
+ }
104
+ RED.nodes.registerType('element-action', elementAction)
105
+ }
@@ -1,91 +1,91 @@
1
- <script type="text/javascript">
2
- RED.nodes.registerType('element-check', {
3
- category: 'Webdriver IO',
4
- color: '#a6bbcf',
5
- defaults: {
6
- name: { value: '' },
7
- locateUsing: { value: 'xpath' },
8
- locateValue: { value: '' },
9
- check: { value: 'selected' }
10
- },
11
- inputs: 1,
12
- outputs: 1,
13
- icon: 'white-globe.png',
14
- label: function() {
15
- return this.name || 'element check'
16
- }
17
- })
18
- </script>
19
-
20
- <script type="text/x-red" data-template-name="element-check">
21
- <div class="form-row">
22
- <label for="node-input-locateUsing"><i class="fa fa-tasks"></i> Locate Method</label>
23
- <select type="text" id="node-input-locateUsing" style="width:70%;">
24
- <option value="id">id</option>
25
- <option value="name">name</option>
26
- <option value="css selector">CSS selector</option>
27
- <option value="link text">Link text</option>
28
- <option value="partial link text">Partial link text</option>
29
- <option value="tag name">Tag name</option>
30
- <option value="xpath" selected>XPath</option>
31
- </select>
32
- </div>
33
- <div class="form-row">
34
- <label for="node-input-locateValue"><i class="fa fa-tasks"></i> Selector</label>
35
- <input id="node-input-locateValue" type="text">
36
- </div>
37
-
38
- <div class="form-row">
39
- <label for="node-input-check"><i class="fa fa-tasks"></i> Check</label>
40
- <select type="text" id="node-input-check" style="width:70%;">
41
- <option value="clickable">Is Clickable</option>
42
- <option value="displayed">Is Displayed</option>
43
- <option value="displayedInView">Is Displayed in Viewport</option>
44
- <option value="enabled">Is Enabled</option>
45
- <option value="existing">Is Existing</option>
46
- <option value="focused">Is Focused</option>
47
- <option value="selected">Is Selected</option>
48
- </select>
49
- </div>
50
- <div class="form-row">
51
- <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
52
- <input id="node-input-name" type="text">
53
- </div>
54
- </script>
55
-
56
- <script type="text/x-red" data-help-name="element-check">
57
- <h3>Selected action of the node performs a target web element inside the browser.</h3>
58
- <h3>Inputs</h3>
59
- <dl class="message-properties">
60
-
61
- <dt><code>mgs.locateUsing</code>: <span class="property-type">string</span></dt>
62
- <dd>specifies the type of web element identifier:
63
- <ul>
64
- <li>id</li>
65
- <li>name</li>
66
- <li>CSS selector</li>
67
- <li>Link text</li>
68
- <li>Partial link text</li>
69
- <li>Tag name</li>
70
- <li>XPath</li>
71
- </ul>
72
- <br>
73
- </dd>
74
- <dt><code>msg.locateValue</code><span class="property-type">string</span></dt>
75
- <dd>value passed to the web element identifier (Locate Method)<br></dd>
76
-
77
- </dl>
78
-
79
- <h3>Details</h3>
80
- <dl class="message-properties">
81
- <p><b>Locate Method</b> specifies the method used to target the web element. This option can be selected manually from the Properties panel OR it can be received from <code>mgs.locateUsing</code><br></p>
82
- <p><b>Selector</b> value used by the Locate Method to target the web element. This option can be selected manually from the Properties panel OR it can be received from <code>mgs.locateValue</code><br></p>
83
- <p><b>Check</b> specifies the action to be performed on the target web element. Actions includes:
84
- <ul>
85
- <li>Is Element Selected</li>
86
- <li>Is Element Enabled</li>
87
- <li>Is Element Displayed</li>
88
- </ul>
89
- </p>
90
- </dl>
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('element-check', {
3
+ category: 'Webdriver IO',
4
+ color: '#a6bbcf',
5
+ defaults: {
6
+ name: { value: '' },
7
+ locateUsing: { value: 'xpath' },
8
+ locateValue: { value: '' },
9
+ check: { value: 'selected' }
10
+ },
11
+ inputs: 1,
12
+ outputs: 1,
13
+ icon: 'white-globe.png',
14
+ label: function() {
15
+ return this.name || 'element check'
16
+ }
17
+ })
18
+ </script>
19
+
20
+ <script type="text/x-red" data-template-name="element-check">
21
+ <div class="form-row">
22
+ <label for="node-input-locateUsing"><i class="fa fa-tasks"></i> Locate Method</label>
23
+ <select type="text" id="node-input-locateUsing" style="width:70%;">
24
+ <option value="id">id</option>
25
+ <option value="name">name</option>
26
+ <option value="css selector">CSS selector</option>
27
+ <option value="link text">Link text</option>
28
+ <option value="partial link text">Partial link text</option>
29
+ <option value="tag name">Tag name</option>
30
+ <option value="xpath" selected>XPath</option>
31
+ </select>
32
+ </div>
33
+ <div class="form-row">
34
+ <label for="node-input-locateValue"><i class="fa fa-tasks"></i> Selector</label>
35
+ <input id="node-input-locateValue" type="text">
36
+ </div>
37
+
38
+ <div class="form-row">
39
+ <label for="node-input-check"><i class="fa fa-tasks"></i> Check</label>
40
+ <select type="text" id="node-input-check" style="width:70%;">
41
+ <option value="clickable">Is Clickable</option>
42
+ <option value="displayed">Is Displayed</option>
43
+ <option value="displayedInView">Is Displayed in Viewport</option>
44
+ <option value="enabled">Is Enabled</option>
45
+ <option value="existing">Is Existing</option>
46
+ <option value="focused">Is Focused</option>
47
+ <option value="selected">Is Selected</option>
48
+ </select>
49
+ </div>
50
+ <div class="form-row">
51
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
52
+ <input id="node-input-name" type="text">
53
+ </div>
54
+ </script>
55
+
56
+ <script type="text/x-red" data-help-name="element-check">
57
+ <h3>Selected action of the node performs a target web element inside the browser.</h3>
58
+ <h3>Inputs</h3>
59
+ <dl class="message-properties">
60
+
61
+ <dt><code>mgs.locateUsing</code>: <span class="property-type">string</span></dt>
62
+ <dd>specifies the type of web element identifier:
63
+ <ul>
64
+ <li>id</li>
65
+ <li>name</li>
66
+ <li>CSS selector</li>
67
+ <li>Link text</li>
68
+ <li>Partial link text</li>
69
+ <li>Tag name</li>
70
+ <li>XPath</li>
71
+ </ul>
72
+ <br>
73
+ </dd>
74
+ <dt><code>msg.locateValue</code><span class="property-type">string</span></dt>
75
+ <dd>value passed to the web element identifier (Locate Method)<br></dd>
76
+
77
+ </dl>
78
+
79
+ <h3>Details</h3>
80
+ <dl class="message-properties">
81
+ <p><b>Locate Method</b> specifies the method used to target the web element. This option can be selected manually from the Properties panel OR it can be received from <code>mgs.locateUsing</code><br></p>
82
+ <p><b>Selector</b> value used by the Locate Method to target the web element. This option can be selected manually from the Properties panel OR it can be received from <code>mgs.locateValue</code><br></p>
83
+ <p><b>Check</b> specifies the action to be performed on the target web element. Actions includes:
84
+ <ul>
85
+ <li>Is Element Selected</li>
86
+ <li>Is Element Enabled</li>
87
+ <li>Is Element Displayed</li>
88
+ </ul>
89
+ </p>
90
+ </dl>
91
91
  </script>
@@ -1,62 +1,62 @@
1
- const common = require('./wdio-common')
2
-
3
- module.exports = function (RED) {
4
- function elementCheck(config) {
5
- RED.nodes.createNode(this, config)
6
- const node = this
7
- common.clearStatus(node)
8
-
9
- node.on('input', async (msg) => {
10
- try {
11
- let locateUsing = config.locateUsing || msg.locateUsing
12
- let locateValue = config.locateValue || msg.locateValue
13
-
14
- let browser = await common.getBrowser(node.context())
15
- let locator = await common.getLocator(
16
- browser,
17
- locateUsing,
18
- locateValue
19
- )
20
-
21
- if (config.check === 'clickable') {
22
- node.log = `Check the webelement is clickable, identified using ${locateUsing}: "${locateValue}".`
23
- msg.payload = await browser.$(locator).isClickable()
24
- } else if (config.check === 'displayed') {
25
- node.log = `Check the webelement is displayed, identified using ${locateUsing}: "${locateValue}".`
26
- msg.payload = await browser.$(locator).isDisplayed()
27
- } else if (config.check === 'displayedInView') {
28
- node.log = `Check the webelement is displayed in view port, identified using ${locateUsing}: "${locateValue}".`
29
- msg.payload = await browser.$(locator).isDisplayedInViewport()
30
- } else if (config.check === 'enabled') {
31
- node.log = `Check the webelement is enabled, identified using ${locateUsing}: "${locateValue}".`
32
- msg.payload = await browser.$(locator).isEnabled()
33
- } else if (config.check === 'existing') {
34
- node.log = `Check the webelement is existing, identified using ${locateUsing}: "${locateValue}".`
35
- msg.payload = await browser.$(locator).isExisting()
36
- } else if (config.check === 'focused') {
37
- node.log = `Check the webelement is focused, identified using ${locateUsing}: "${locateValue}".`
38
- msg.payload = await browser.$(locator).isFocused()
39
- } else if (config.check === 'selected') {
40
- node.log = `Check the webelement is selected, identified using ${locateUsing}: "${locateValue}".`
41
- msg.payload = await browser.$(locator).isSelected()
42
- }
43
- await common.log(node)
44
- common.successStatus(node)
45
- node.send(msg)
46
- } catch (e) {
47
- // if(e.message == 'unable to find'){
48
- // msg.payload = false
49
- // node.log = `Webelement is NOT displayed, identified using ${locateUsing}: "${locateValue}".`
50
- // await common.log(node)
51
- // common.successStatus(node)
52
- // node.send(msg)
53
- // }
54
- // else{
55
- await common.log(node)
56
- common.handleError(e, node, msg)
57
- }
58
- //}
59
- })
60
- }
61
- RED.nodes.registerType('element-check', elementCheck)
62
- }
1
+ const common = require('./wdio-common')
2
+
3
+ module.exports = function (RED) {
4
+ function elementCheck(config) {
5
+ RED.nodes.createNode(this, config)
6
+ const node = this
7
+ common.clearStatus(node)
8
+
9
+ node.on('input', async (msg) => {
10
+ try {
11
+ let locateUsing = config.locateUsing || msg.locateUsing
12
+ let locateValue = config.locateValue || msg.locateValue
13
+
14
+ let browser = await common.getBrowser(node.context())
15
+ let locator = await common.getLocator(
16
+ browser,
17
+ locateUsing,
18
+ locateValue
19
+ )
20
+
21
+ if (config.check === 'clickable') {
22
+ node.log = `Check the webelement is clickable, identified using ${locateUsing}: "${locateValue}".`
23
+ msg.payload = await browser.$(locator).isClickable()
24
+ } else if (config.check === 'displayed') {
25
+ node.log = `Check the webelement is displayed, identified using ${locateUsing}: "${locateValue}".`
26
+ msg.payload = await browser.$(locator).isDisplayed()
27
+ } else if (config.check === 'displayedInView') {
28
+ node.log = `Check the webelement is displayed in view port, identified using ${locateUsing}: "${locateValue}".`
29
+ msg.payload = await browser.$(locator).isDisplayedInViewport()
30
+ } else if (config.check === 'enabled') {
31
+ node.log = `Check the webelement is enabled, identified using ${locateUsing}: "${locateValue}".`
32
+ msg.payload = await browser.$(locator).isEnabled()
33
+ } else if (config.check === 'existing') {
34
+ node.log = `Check the webelement is existing, identified using ${locateUsing}: "${locateValue}".`
35
+ msg.payload = await browser.$(locator).isExisting()
36
+ } else if (config.check === 'focused') {
37
+ node.log = `Check the webelement is focused, identified using ${locateUsing}: "${locateValue}".`
38
+ msg.payload = await browser.$(locator).isFocused()
39
+ } else if (config.check === 'selected') {
40
+ node.log = `Check the webelement is selected, identified using ${locateUsing}: "${locateValue}".`
41
+ msg.payload = await browser.$(locator).isSelected()
42
+ }
43
+ await common.log(node)
44
+ common.successStatus(node)
45
+ node.send(msg)
46
+ } catch (e) {
47
+ // if(e.message == 'unable to find'){
48
+ // msg.payload = false
49
+ // node.log = `Webelement is NOT displayed, identified using ${locateUsing}: "${locateValue}".`
50
+ // await common.log(node)
51
+ // common.successStatus(node)
52
+ // node.send(msg)
53
+ // }
54
+ // else{
55
+ await common.log(node)
56
+ common.handleError(e, node, msg)
57
+ }
58
+ //}
59
+ })
60
+ }
61
+ RED.nodes.registerType('element-check', elementCheck)
62
+ }