简体   繁体   English

是否可以使用webdriver.js观察postMessages?

[英]Is it possible to observe postMessages using webdriver.js?

I would like to make Selenium perform certain actions once an iframe on the webpage sends a particular postMessage to the parent window. 一旦网页上的iframe将特定的postMessage发送到父窗口,我想让Selenium执行某些操作。 In order to do that, I need either to get access to the window object of the web page that the browser is on from the test runner (so that I could observe postMessages on window directly in the test runner), or to somehow connect javascript that is executed in the browser to javascript that is executed in the node test runner (pass a callback from the test runner to the browser that will be called when the window receives the postMessage, or something). 为了做到这一点,我需要从测试运行器访问浏览器所在的网页的window对象(以便我可以直接在测试运行器中观察window postMessages),或以某种方式连接javascript这是在浏览器中执行到在节点测试运行器中执行的javascript(将测试运行器的回调传递给将在窗口接收postMessage时调用的浏览器,或者其他东西)。 Is there any method for doing this? 有没有办法做到这一点? Google was no help with this one :-( 谷歌对此没有帮助:-(

UPDATE: Hmm, executeAsyncScript looks very promising; 更新:嗯,executeAsyncScript看起来很有前途; I wonder whether I could it into listening to postmessages and then notifying the callback provided by the test runner that a particular postmessage was received. 我想知道我是否可以听取postmessages,然后通知测试运行员提供的回调,收到特定的邮件消息。

@azangru did you ever find a solution to this over the last two years? @azangru过去两年你有没有找到解决方案? 🙂 🙂

I tried executeAsyncScript and it theoretically could work, except that it seems to block other actions from completing until it resolves. 我尝试了executeAsyncScript ,理论上它可以工作,除了它似乎阻止其他操作完成直到它结算。

Code mockup in TypeScript: https://gist.github.com/JoshuaKGoldberg/a0c5fe2812a06318e0eb2ffdc9e17021 TypeScript中的代码模型: https//gist.github.com/JoshuaKGoldberg/a0c5fe2812a06318e0eb2ffdc9e17021

Filed Selenium issue: https://github.com/SeleniumHQ/selenium/issues/5972 提起Selenium问题: https//github.com/SeleniumHQ/selenium/issues/5972

In the meantime, you could have the page console.info stringified forms of the data it wants to transmit, then continuously poll for logs in Selenium. 在此期间,您可以将页面console.info字符串化形式的数据传输到其中,然后在Selenium中连续轮询日志。 Not great but better than nothing...? 不是很好但总比没有好......?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM