预加载浏览器剪贴板,用于使用 watir-webdriver 测试粘贴到字段中 [英] Pre-loading browser clipboard for testing pasting into fields with watir-webdriver

查看:21
本文介绍了预加载浏览器剪贴板,用于使用 watir-webdriver 测试粘贴到字段中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的网络应用程序有一些事件代码来格式化"粘贴到字段中的任何文本,以便任何 HTML 样式都不会破坏我们的数据.

Our web application has some event code to "format" any text with pasted into a field so that any HTML styles do not break our data.

预加载浏览器剪贴板以便我可以测试粘贴到输入字段的好方法是什么?

What would be a good way to pre-load the browser clipboard so that I can test pasting into the input field?

有没有办法以编程方式完成,或者我会让测试脚本访问源页面"并在移动到我们的应用程序之前复制文本?

Is there any way to do it programmatic-ally or would I have the test script visit "a source page" and copy text before moving onto our application?

欢迎提供任何想法或代码片段.

Any ideas or code snippets would be welcome.

推荐答案

我会考虑使用 .value= 方法来设置值.如果它的实现方式与 watir 相同,那么它不会触发任何事件并直接设置值,然后通过发送适当的事件来跟进(取决于是否有任何事件正在发生)监控),例如 onKeypress.我试图从 文本字段的 Watir-webdriver rdoc 中找出答案,如果 .set 和 .value= 之间的区别一直保持,但文档描述它们的方式(至少在那里)使它们看起来可以互换..(Jarib 你能澄清一下吗???)

I would consider using the .value= method to set the value. If it's been implemented the same as in watir, then it causes no events to be fired and sets the value directly, and then follow that up by sending an appropriate event (depending on what if any events are being monitored) such as onKeypress. I tried to figure out from the Watir-webdriver rdoc for textfield, if this distinction between .set and .value= has been maintained, but the way the doc describes them (at least there) makes them seem interchangable.. (Jarib can you clarify???)

根据您使用的控件,您可能需要先启动诸如 onFocus 之类的东西.例如,如本例中所述 设置一个带有 JQuery 掩码的文本字段用于 jquery 掩码,他们最终必须触发取消掩码事件才能设置该字段.

Potentially you might need to first fire something like onFocus depending on the controls you are using. For example, as described in this SO case Setting a text field that has a JQuery mask on it for a jquery mask, they had to end up firing an unmask event to be able to even set the field.

这是利用此处描述的技术的一个很好的例子如何找出触发了哪些 JavaScript 事件? 并在该问题的评论中链接的 SO 项目中,找出当您手动将某些内容粘贴到字段中时触发了哪些事件.(请注意,我会使用鼠标来监视它,但也会使用诸如 tab 之类的东西在字段之间移动并设置焦点,这两种方法共有的事件最有可能由控件实现.

This is a good case for utilizing the techniques described here How to find out which JavaScript events fired? and in the SO item linked in the comments for that question, to figure out just what events are fired when you manually paste something into a field. (note I would slueth it with both using the mouse, but also using something like tab to move between fields and set the focus, events common to those two methods are the ones most likely to be implemented by the controls.

我假设您有某种客户端 javascript 需要检查粘贴到该字段中的内容,以及进行此测试的原因.如果您使用的是标准 HTML 字段,没有 javascript 内容,那么我会认为这个特定的测试用例实际上与测试浏览器"相同,因为支持输入字段中的剪切和粘贴是标准浏览器功能.在那种情况下,您有点不同意",我不会理会这样的测试用例.

I presume you have some kind of client side javascript that needs to check what was pasted into the field, and thus the reason for this test. If you are using standard HTML fields, with no javascript stuff, then I would consider this particular test case to be effectively the same as 'testing the browser' since supporting cut and paste in input fields is a standard browser function. In that case, you are sort of 'off the reservation' and I'd not bother with such a test case.

这篇关于预加载浏览器剪贴板,用于使用 watir-webdriver 测试粘贴到字段中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆