简体   繁体   English

Watir和Javascript

[英]Watir and Javascript

I am looking into multiple web testing tools. 我正在研究多种Web测试工具。 I am trying watir now. 我现在正在努力。 My main concern is dealing with javascript. 我主要担心的是处理javascript。 I just want to know if anyone can give me an overview on dealing with javascript in watir. 我只是想知道是否有人可以给我一个关于在watir中处理javascript的概述。 What are some of the pitfalls and difficulties with it? 它有哪些陷阱和困难? Is it basically using javascript injections to tell the page what to do? 它基本上是使用javascript注入来告诉页面该做什么?

And if someone wants to suggest other web testing tools like watir I would appreciate it. 如果有人想建议像watir这样的其他网络测试工具,我会很感激。 I tried selenium first and found it to be a tad unreliable. 我先尝试过硒,发现它有点不可靠。

Are there any cheap tools on the market? 市场上有没有便宜的工具?

Thank You! 谢谢!

Watir + Javascript => generally it's possible to inject javascript into your tests eg Watir + Javascript =>通常可以将javascript注入您的测试中,例如

@b.goto("javascript:openWin(2)") @ b.goto( “JavaScript的:openWin(2)”)

When you say 'dealing with javascript' I assume you mean how well does Watir handle client side code in terms of rendering/execution. 当你说'处理javascript'时,我认为你的意思是Watir在渲染/执行方面处理客户端代码的能力。 Since Watir drives real browsers (like Selenium) then JS will execute generally as expected. 由于驱动的Watir真正的浏览器(如硒),那么JS 一般会按预期执行。

Watir has different many different drivers, eg watir, firewatir, safariwatir, chromewatir, operawatir and now watir-webdriver. Watir有许多不同的驱动程序,例如watir,firewatir,safariwatir,chromewatir,operawatir和现在的watir-webdriver。 All of them drive the browser in slightly different implementations depending on the browser and OS. 根据浏览器和操作系统的不同,所有这些驱动器的浏览器略有不同。 Firewatir for example uses JSSH which is in effect controlling the browser via JS. 例如,Firewatir使用JSSH,它实际上是通过JS控制浏览器。 Can you explain what you mean by Selenium being 'unreliable'? 你能解释一下Selenium“不可靠”的含义吗?

I'd recommend looking at the latest implementation of watir-webdriver. 我建议看一下watir-webdriver的最新实现。 That way you get the benefit of a nice watir API on top of a new driver implementation. 这样,您就可以在新的驱动程序实现之上获得良好的watir API。 Webdriver has some strong backing in terms of support (Selenium 2 uses it, Google is coding it!) so I reckon it's a safe bet. Webdriver在支持方面有一些强大的支持(Selenium 2使用它,谷歌正在编码!)所以我认为这是一个安全的赌注。 You can also control most of the major browsers with this implementation. 您还可以使用此实现控制大多数主流浏览器。

Alternative tools => http://wiki.openqa.org/display/WTR/Alternative+Tools+For+Web+Testing 替代工具=> http://wiki.openqa.org/display/WTR/Alternative+Tools+For+Web+Testing

Tim provides a pretty good answer. 蒂姆提供了一个很好的答案。

The only thing I have to add to what he said is that I've found that now and then I have to use the watir methods to fire specific javascript events such as onmouseover in order to accurately simulate the user interacting with the page. 我必须添加到他所说的唯一的事情是我发现,我现在必须使用watir方法来触发特定的javascript事件,如onmouseover,以便准确地模拟用户与页面交互。 Since watir has a method for this, the hard part is not the watir code, but reverse engineering the page (or noticing subtle page interactions based on user actions) to figure out what elements are 'wired' up to what events and the order to fire those events against those specific elements. 由于watir有一个方法,硬件部分不是watir代码,而是对页面进行逆向工程(或根据用户操作注意到细微的页面交互),以确定哪些元素“连线”到什么事件和顺序到针对这些特定元素解雇这些事件。

Usually it's pretty easy to look at the HTML for an element and see what's going on. 通常,查看元素的HTML并查看正在发生的事情非常容易。 But with some custom controls it can take a bit of learning because they manage to do a pretty good job of 'hiding' all the event wiring, and you may have to parse through various aspects of the page (styles and all) using something like fiddler. 但是使用一些自定义控件可能需要一些学习,因为他们能够很好地“隐藏”所有事件布线,并且您可能必须使用类似的东西来解析页面的各个方面(样式和所有)小提琴手。

(after all, the normal user will never 'force' javacript to execute, or 'inject' javascript. They will use the mouse and keyboard to interact with the page, and any javascript is going to be a result of scripts that execute when the page is loaded, or as a result of scripts triggered via events based on specific user actions) (毕竟,普通用户永远不会'强迫'javacript执行,或'注入'javascript。他们将使用鼠标和键盘与页面进行交互,任何javascript都将是脚本执行时的结果页面已加载,或者是基于特定用户操作通过事件触发的脚本的结果)

If your JS does not trigger a HTML refresh then WATiR will get confused. 如果你的JS没有触发HTML刷新,那么WATiR会感到困惑。 When you click an object in WATiR it waits for the page to load before continuing. 当您单击WATiR中的对象时,它会在继续之前等待页面加载。 You can overcome this with custom waiting commands and use of '.click!'. 您可以使用自定义等待命令和“.click!”来解决此问题。

If you are a reasonable ruby coder then WATiR is a solution for most things. 如果你是一个合理的红宝石编码器,那么WATiR是大多数事情的解决方案。 It has the potential to be a rather stable and reliable source of automated web testing. 它有可能成为一个相当稳定和可靠的自动化Web测试源。

You may want to look into Firewatir, sahi, watir-webdriver, just to give you some more leads (would suggest googling for "open source web testing" and the like if you haven't. I looked into these and many more and settled on WATiR for reasons of cost, power, flexibility and prior knowledge (in ruby and WATiR). With the right gems it will speak to most databases and to Excel (or other file) to load test data. 你可能想看一下Firewatir,sahi,watir-webdriver,只是为了给你一些更多的线索(如果你没有,建议使用谷歌搜索“开源网络测试”等等。我调查了这些以及更多,并解决了在WATiR上出于成本,功耗,灵活性和先验知识的原因(在ruby和WATiR中)。使用正确的宝石,它将与大多数数据库和Excel(或其他文件)对话以加载测试数据。

I'm currently using WATiR to test a ZK-generated interface where none of the IDs are ever static and there's a lot of AJAXiness going on. 我目前正在使用WATiR来测试ZK生成的接口,其中没有任何ID是静态的,并且有很多AJAXiness正在进行。 I just built a framework to deal with these, and it works just fine. 我刚刚构建了一个框架来处理这些问题,它的工作正常。

Also, some semi-true and true things that may help . 此外, 一些可能有帮助的半真实和真实的东西

要从watir传递javascript,请使用browser.execute_script()示例:

Watir::Wait.until { $browser.execute_script("return document.readyState") == "complete" }

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

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