您的位置:软件测试 > 开源软件测试 > 开源功能测试工具 > Selenium
Some selenium tips关于Selenium的小窍门
作者:网络转载 发布时间:[ 2013/4/7 15:55:26 ] 推荐标签:

  Watch out the outdated articles on the internet.

  当心网上那些过时的文章

  Selenium 2.0 is completely different from Selenium 1.x. Selenium 2.0 is also called the selenium webdriver. So always add the keyword webdriver when googling for answers to your selenium related questions.

  Selenium 2.0与Selenium 1.x有非常大的差别。Selenium 2.0 通常也别叫做 selenium webdriver。所以在你google selenium 相关的问题的时候,都请加上 webdriver 这个关键字。

  Implement the web UI in a modular way so it's more selenium testable.

  用模块化的方式来实现Web的UI会提高用Selenium测试的可测性

  Modularize your view logic so that you only update the part of DOM that is needed to change when your models change. If you tend to re-create a bigger part of the DOM than necessary, it's not only a waste but also could introduce risk to your functional tests written in Selenium.

  模块化你的View逻辑,这样做的好处是,当你要更改你的Models时,你只需要更新部分的DOM即可。如果你尝试重新创建一个比需要更大的DOM,这不但是一种浪费,而且会引入使你的Selenium 功能测试脚本出现不能正常工作风险。

  Reduce unnecessary dependency on DOM structure, make element locating logic as simple as possible.

  减少对DOM结构不必要的依赖,元素定位逻辑的越简单越好

  When you need to locate an element, try not rely on the DOM structure too much - for example, using code logic to locate element is the most risky one. The best approach is probably to always use a scoped CSS selector with 1 or 2 levels of IDs, And if you can locate it in one selector, don't do it in two. For example

  请尽量不要使用DOM的结构来定位页面元素,例如,用代码逻辑来定位元素是风险大的。定位元素好的方式是用1 到2级的CSS selector,如果一个selector 能定位,不要用两个, 例如

  label = driver.find_element("#info-panel #name-label")

  is more robust than

  比以下的方法健壮

  panel = driver.find_element("#info-panel")

  label = panel.find_element("#name-label")

  Do wait in selenium the smart way.

  恰当地使用Wait

  Don't use implicit wait blindly. Implicit wait makes sense when you use find_element to find one element. But when you try to locate multiple elements by driver.find_elements, the driver will always wait the whole timeout period if implicit wait is set. That might not be what you always want. I usually write my own safe find_element method. Here is an example in the base class of my page objects:

  不要盲目地使用隐式等待。当你使用find_element的时候去找某一个元素时,使用隐式等待是合适的,但是当你尝试用 driver.find_elements 去定位多个元素时,如果设置了隐式等待,那么drivers 总是会等待整个超时周期。这往往不是你想要的效果。我通常会自己去写一个安全的 find_element 方法。以下例子展示了我页面对象的基类

  def s selector

  wait_until { @driver.find_element css: selector }

  end

  def wait_until(&block)

  wait = Selenium::WebDriver::Wait.new(timeout: 10, interval: INTERVAL)

  wait.until &block

  end

  So that I can write the following code in my page object

上一页12下一页
软件测试工具 | 联系我们 | 投诉建议 | 诚聘英才 | 申请使用列表 | 网站地图
沪ICP备07036474 2003-2017 版权所有 上海泽众软件科技有限公司 Shanghai ZeZhong Software Co.,Ltd