simonradier / node-red-contrib-selenium-wd2

Selenium nodes for Node-Red
Apache License 2.0
9 stars 7 forks source link

TypeError: Cannot read property 'send' of undefined -- Can't close the browser, when more actions in the flow are performed #3

Closed sudoritz closed 3 years ago

sudoritz commented 3 years ago

"Can't close the browser, check msg.error for more information"

Screen Shot 2020-10-23 at 6 14 15 PM
error: object
message: "TypeError: Cannot read property 'send' of undefined"
source: object
id: "c87a37a5.72dac8"
type: "close-web"

name: undefined
count: 1
stack: string
TypeError: Cannot read property 'send' of undefined
    at Executor.execute (/data/node_modules/selenium-webdriver/lib/http.js:487:33)
    at thenableWebDriverProxy.execute (/data/node_modules/selenium-webdriver/lib/webdriver.js:700:38)

NOTE: i did see this same issue before close node it happened Intermittently at times too

FYI if it doesn't close i do go in wdhub and delete sessions so they arent hung.

http://10.0.1.10:4444/wd/hub/static/resource/hub.html

(though weirdly within wdhub you cant take screenshot like original selenium-node-red from within wd-hub it errors out in null/ I could throw that issue on another Issue ID. i only mention if it could be related.)

thanks

simonradier commented 3 years ago

Hi again,

Could you share with me the flow you are building? Can you try the example flow and check if you have the error as well.

Thanks

sudoritz commented 3 years ago

i tried example and it seems to close so im not sure where in line it is dropping

[{"id":"31b26265.815fce","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"4ed979e0.4062d8","type":"open-web","z":"31b26265.815fce","name":"","browser":"chrome","webURL":"http://172.16.190.11","width":1280,"height":1024,"timeout":3000,"maximized":false,"headless":true,"serverURL":"http://10.0.7.27:4444/wd/hub","x":310,"y":40,"wires":[["3fd1c25f.31d6be"]]},{"id":"ff6bbc5b.7b0e6","type":"screenshot","z":"31b26265.815fce","name":"","filePath":"./snap.png","waitFor":"2000","x":310,"y":260,"wires":[["a07acd81.ccfe4","c87a37a5.72dac8"],[]]},{"id":"eee51b2f.b62cb8","type":"inject","z":"31b26265.815fce","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":100,"wires":[["4ed979e0.4062d8"]]},{"id":"a07acd81.ccfe4","type":"debug","z":"31b26265.815fce","name":"afterSCREENSHOT","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":640,"y":340,"wires":[]},{"id":"3fd1c25f.31d6be","type":"click-on","z":"31b26265.815fce","name":"userName","selector":"name","target":"idUsername","timeout":1000,"waitFor":500,"clickOn":false,"x":310,"y":120,"wires":[["270f5e7a.1c3e02"],[]]},{"id":"270f5e7a.1c3e02","type":"send-keys","z":"31b26265.815fce","name":"admin","keys":"admin","selector":"id","target":"idUsername","timeout":1000,"waitFor":500,"clearval":false,"x":470,"y":120,"wires":[["4de9267a.7e94a8"],[]]},{"id":"4de9267a.7e94a8","type":"click-on","z":"31b26265.815fce","name":"ClickPass","selector":"name","target":"idPassword","timeout":1000,"waitFor":500,"clickOn":false,"x":620,"y":120,"wires":[["5a009167.9b2e4"],[]]},{"id":"5a009167.9b2e4","type":"send-keys","z":"31b26265.815fce","name":"pass","keys":"Password1","selector":"id","target":"idPassword","timeout":1000,"waitFor":500,"clearval":false,"x":770,"y":120,"wires":[["e0ae56b1.c436f8"],[]]},{"id":"e0ae56b1.c436f8","type":"click-on","z":"31b26265.815fce","name":"clickSubmit","selector":"name","target":"idLoginSubmit","timeout":"1500","waitFor":"500","clickOn":false,"x":930,"y":120,"wires":[["8c4e28f4.d9e3e8"],[]]},{"id":"d192320f.571c","type":"http in","z":"31b26265.815fce","name":"","url":"/jma","method":"get","upload":false,"swaggerDoc":"","x":80,"y":40,"wires":[["4ed979e0.4062d8"]]},{"id":"f828516a.08dc","type":"catch","z":"31b26265.815fce","name":"","scope":null,"uncaught":false,"x":1140,"y":60,"wires":[["80121cc1.2f813"]]},{"id":"80121cc1.2f813","type":"debug","z":"31b26265.815fce","name":"ERR","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1150,"y":100,"wires":[]},{"id":"e9e3b569.d64218","type":"debug","z":"31b26265.815fce","name":"CLOSE","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":740,"y":260,"wires":[]},{"id":"c87a37a5.72dac8","type":"close-web","z":"31b26265.815fce","name":"","waitFor":"5000","x":550,"y":260,"wires":[["e9e3b569.d64218"]]},{"id":"fceb0e0b.f1bf7","type":"debug","z":"31b26265.815fce","name":"afterDELAY","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":740,"y":200,"wires":[]},{"id":"8c4e28f4.d9e3e8","type":"delay","z":"31b26265.815fce","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":300,"y":200,"wires":[["ff6bbc5b.7b0e6","fceb0e0b.f1bf7"]]}]

sudoritz commented 3 years ago

all i have is user/pass click submit / screenshot and then close

sudoritz commented 3 years ago
Screen Shot 2020-10-24 at 6 50 50 PM

at times it doesnt only fail at close (as if its failing on the same TypeError: Cannot read property 'send' of undefined

i can even rechange the flow and what worked now doesnt so not sure if theres a timer / something

simonradier commented 3 years ago

This is weird. It seems to be a race condition... Could you try to reproduce it with this docker image : => Tag : 1.2.2-12-amd64 It's to ensure it is not node v10 related.

sudoritz commented 3 years ago

hmm same thing

25 Oct 16:12:05 - [info] Welcome to Node-RED 25 Oct 16:12:06 - [info] Node-RED version: v1.2.2 25 Oct 16:12:06 - [info] Node.js version: v12.19.0 25 Oct 16:12:06 - [info] Linux 3.10.0-957.10.1.el7.x86_64 x64 LE

element: WebElement {
    driver_: thenableWebDriverProxy {
      session_: Promise {
        Session {
          id_: 'd5a175ee766f8c0862caf344edb4afc9',
          caps_: Capabilities {
            map_: Map {
              'acceptInsecureCerts' => false,
              'browserName' => 'chrome',
              'browserVersion' => '81.0.4044.92',
              'chrome' => {
                chromedriverVersion: '81.0.4044.69 (6813546031a4bc83f717a2ef7cd4ac6ec1199132-refs/branch-heads/4044@{#776})',
                userDataDir: '/tmp/.com.google.Chrome.VoQIyC'
              },
              'goog:chromeOptions' => { debuggerAddress: 'localhost:34736' },
              'networkConnectionEnabled' => false,
              'pageLoadStrategy' => 'normal',
              'platformName' => 'linux',
              'proxy' => {},
              'setWindowRect' => true,
              'strictFileInteractability' => false,
              'timeouts' => { implicit: 0, pageLoad: 300000, script: 30000 },
              'unhandledPromptBehavior' => 'dismiss and notify',
              'webauthn:virtualAuthenticators' => true,
              'webdriver.remote.sessionid' => 'd5a175ee766f8c0862caf344edb4afc9'
 },
 error: {
    message: "TypeError: Cannot read property 'send' of undefined",
    source: {
      id: '32711e02.c5bb72',
      type: 'click-on',
      name: undefined,
      count: 1
    },
    stack: "TypeError: Cannot read property 'send' of undefined\n" +
      '    at Executor.execute (/data/node_modules/selenium-webdriver/lib/http.js:487:33)\n' +
      '    at thenableWebDriverProxy.execute (/data/node_modules/selenium-webdriver/lib/webdriver.js:700:38)\n' +
      '    at async thenableWebDriverProxy.findElements (/data/node_modules/selenium-webdriver/lib/webdriver.js:952:19)'
  }
}
simonradier commented 3 years ago

Ok, it seems I found a way to generate it each time.

Can you try this flow :

[{"id":"bb7829f8.2195f8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"b229db0e.e79a18","type":"open-web","z":"bb7829f8.2195f8","name":"","browser":"firefox","webURL":"https://www.google.com/","width":1280,"height":1024,"timeout":3000,"maximized":true,"headless":false,"serverURL":"http://10.0.1.21:4444/wd/hub","x":510,"y":380,"wires":[["a8078112.206b8","40dbde54.20f54"]]},{"id":"1edb0646.c0baca","type":"inject","z":"bb7829f8.2195f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":310,"y":380,"wires":[["b229db0e.e79a18"]]},{"id":"7b8450cd.4fe4f","type":"close-web","z":"bb7829f8.2195f8","name":"","waitFor":500,"x":1010,"y":300,"wires":[[]]},{"id":"a8078112.206b8","type":"function","z":"bb7829f8.2195f8","name":"","func":"node.send (msg);","outputs":1,"noerr":0,"initialize":"","finalize":"","x":720,"y":220,"wires":[["7b8450cd.4fe4f","40dbde54.20f54"]]},{"id":"40dbde54.20f54","type":"debug","z":"bb7829f8.2195f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1000,"y":460,"wires":[]}]

Of course by changing the url of the WD server 😉.

sudoritz commented 3 years ago

okay so this is weird..... i just manually recreated instead of copy/paste and now it works as if its like not liking a copy node im not sure i trie d it on both versions but now i got it to work (note i did put less debug nodes (msg.complete) not sure if that is causing something .

sudoritz commented 3 years ago

Oh so i see the recreated node.send

"Can't close the browser, check msg.error for more information"
10/25/2020, 10:51:25 AMnode: 7b8450cd.4fe4f
msg : error
"TypeError: Cannot read property 'send' of undefined"
simonradier commented 3 years ago

I think it is related to a stability of the WebDriver object of selenium-webdriver (and a lot of promise use in my side). Not sure it is thread safe or parallel access safe. I'll try some things in my side and let you know if I can stabilize it.

FYI : the "send" is not related at all to node.send. It is linked to "client.send" in this file :

sudoritz commented 3 years ago

Ohhhhhh i see I was able to sort of resolve this and now i cant replicate it anymore .

when im troubleshooting i post debug msg.complete object and tag that to some of the flows so i can see msg.object (and what webdriver comes back or whats going on.)

Whats weird as above i was able to manually rebuild the same exact flow and now it closes and doesnt fail.

but What i did to get my flow to work is remove the debug nodes msg.complete on each of them and now it passes through.

I tried to add them back and now i cant even reproduce it.

simonradier commented 3 years ago

Good news. I made a patch which should correct the issue. Bad news, it is very dirty, because the issue comes from selenium-webdriver itself 😢. It applies a patch the selenium-webdriver during the npm install. Could you try it and check if it is better now? I'll really consider to "rebuild" a simpler version of WD server client which does not rely on selenium-webdriver as the maintenance is quite low at the moment. Can you let me know if it works now?

sudoritz commented 3 years ago

i did apply the patch but it looks like it did fail on unknown-node-types

This node is a type unknown to your installation of Node-RED.
If you deploy with the node in this state, it's configuration will be preserved, but the flow will not start until the missing type is installed.
Screen Shot 2020-10-29 at 2 48 44 PM
sudoritz commented 3 years ago

Looks to be this again

[node-red-contrib-selenium-wd2/selenium-wd2] Error: Cannot find module 'fs/promises'

29 Oct 20:45:18 - [info] Node-RED version: v1.2.2
29 Oct 20:45:18 - [info] Node.js  version: v10.22.1
29 Oct 20:45:18 - [info] Linux 3.10.0-957.10.1.el7.x86_64 x64 LE
29 Oct 20:45:18 - [info] Loading palette nodes
29 Oct 20:45:20 - [warn] ------------------------------------------------------
29 Oct 20:45:20 - [warn] [node-red-contrib-selenium-wd2/selenium-wd2] Error: Cannot find module 'fs/promises'
29 Oct 20:45:20 - [warn] ------------------------------------------------------
simonradier commented 3 years ago

My bad. It seems I forget to commit the fs/promise issue. This is why it reappeared. Try it with version 0.1.4-4.

sudoritz commented 3 years ago

K that worked And retested with my original flow i posted and that didnt fail (adding more dbg. msgcomplete didnt break it it looks to be working :)