WebDriver - 无法从 FFDriver 切换到 ChromeDriver 或 IEDriver
我正在尝试在 Firefox 中创建一个大型的 selenium 套件,但我也想知道所有这些测试在 Chrome 或 IE 中工作会有多困难,即使页面只是以不同的方式呈现,并且已经很难链接它们和让其他驱动程序工作。
有什么建议或经验可以分享吗?预先感谢,洛伦佐。
I'm trying to create a big selenium suite in Firefox but I'm also wondering how difficult would be made all these tests working in the Chrome or IE even because the page is simply rendered in a different manner and is already difficult link them and make the other drivers working.
Any suggestion or experience to share about? Thanks in advance, Lorenzo.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,这种场景是模板模式的良好候选者。由于您使用的是 Webdriver,因此将其与页面对象模式结合起来,您应该能够最大限度地减少重复代码。
这个想法是,您将创建某种执行常用步骤的辅助对象。大多数步骤在浏览器中都是相同的。但由于您的 UI 会根据浏览器而变化,因此某些操作将需要自定义步骤。因此,您将拥有继承抽象基础的大部分步骤的具体实现,但实现特定的功能,其中 UI 差异使得无法重用相同的基础代码。
例如,在有两个输入框的页面上,所需操作的 Firefox 实现将需要两次单击,而 Chrome 实现将只有一次。登录和导航步骤(理论上)是相同的,并且可以通过基类共享。
您可以在测试框架的 SetUp 方法中配置辅助对象(页面工厂等)。您的测试调用辅助对象上的适当方法来执行操作,然后验证结果。
参考文献:
模板模式 - http://www.oodesign.com/template-method-pattern.html oodesign.com/template-method-pattern.html
页面对象模式 - http://code.google.com/p/selenium/wiki/PageObjects
In general this kind of scenario is a good candidate for the Template pattern. Combine that with the Page Object pattern since you are using Webdriver and you should be able to minimize your duplicated code.
The idea is that you would create some kind of helper object that performs commonly used steps. Most of the steps are the same across browsers. But since your UI changes depending on the browser, certain actions will require custom steps. So you will have concrete implementations that inherit most of the steps from the abstract base but implement specific functionality where the UI differences make it impossible to reuse the same base code.
For example, on the page where you have your two input boxes, your firefox implementation of the required action would have two clicks while your Chrome implementation will just have one. The login and navigation steps will (theoretically) be the same and can be shared via the base class.
You configure your helper objects (page factory, etc) in your Testing framework's SetUp method. Your tests call the appropriate methods on the helper objects to perform the actions and then you verify the results.
References:
Template Pattern - http://www.oodesign.com/template-method-pattern.html
Page Object Pattern - http://code.google.com/p/selenium/wiki/PageObjects
我发现 Selenium 根本不是跨浏览器友好的。许多小怪癖会导致单个测试无法在所有支持的浏览器上顺利运行。当然,很大程度上取决于被测试页面的复杂程度以及测试代码的复杂程度(我假设这是正在编码而不是记录)。
一个可能的解决方案是在 WebDrivers 之上创建一个抽象层,该抽象层公开常见操作,同时根据浏览器实例规范化行为(想想 jQuery 的工作原理)。
I have found Selenium is not very cross-browser friendly at all. Many little quirks prevent a single test from running smoothly on all supported browsers. A lot of course depends on how complex the pages being tested are and how complex the testing code is (I'm assuming this is being coded and not recorded).
A possible solution is to create a layer of abstraction on top of the WebDrivers that exposes common actions while normalizing the behavior depending on the browser instance (think how jQuery works).