路宁(luning)的博客

    <<  Code Snippet to Log All Events as They Are Triggered | Home | Selenium Test Powered by jQuery.parcel  >>
  • Remove the Noisy Thread.Sleep and WaitForCondition from Selenium Tests - [Test]

    2009-05-14

    Mark Needham just posted a blog here described the 'waiting for jQuery ajax call' problem in selenium tests and the way we solved it.

    The basic idea is recording the count of active ajax requests in client side js code, and generically decorating the calls(click, type, select etc.) in selenium tests with the logic of waiting for the count to be zero.

    Ajax request may not be the only async point we want to wait for its completion in selenium tests, animation is another one we care about, but just turn off it in tests so that we don't need to worry about it any more. "jQuery.fx.off = true" will turn off jQuery animation.

    Is there any more async points? probably YES. Acturally, what we really want to wait is the completion of any action which is delayed to be executed by window.setTimeout() or window.setInterval(). Ajax and animation rely on window.setTimeout() or window.setInterval() to simulate the async behaviours eventually.

    Please check out the code at mark's post or here(with comments) for details. It works for the cases you fire multiple ajax requests at once or fire further ajax request in previous ajax request's callback.

    Given this, we removed almost all noisy thread.sleep() and waitForCondition() codes in selenium tests! The build is speeded up and the tests become more concise, readable and stable.

    This approach is simple, stable, side-effect free and able to be ported to other ajax framework easily.(jQuery Ajax provides proper events we can rely on, for other ajax framework without build-in events, we can try method delegation instead)

    Waiting for ajax call is a common issue in selenium tests, try this approach and make your selenium tests cleaner.


    随机文章:

    Share DOM Fixtures between JavaScript Unit Tests 2009-12-21
    Selenium Test Powered by jQuery.parcel 2009-07-25
    利用客户端Javascript代码简化Selenium测试 2008-12-23
    Manage Mock Dependencies of Controllers with IoC Container 2009-09-09
    将客户端逻辑封装进Javascript对象,并用Jsunit做单元测试 2008-11-04

    收藏到:Del.icio.us
    Tag:selenium ajax jquery
    Cite url:
    luning published this at 19:42:38 | Edit | Continue This Topic | Forward | 分享 0
  • RSS EMail Me

Search

Latest logs

  • Share DOM Fixtures between JavaScript Unit Tests
  • Manage Mock Dependencies of Controllers with IoC Container
  • The Waste from Very Fat to Very Lean's Perspective
  • A Misleading Analogy between Software Development and Manufacturing
  • Selenium Test Powered by jQuery.parcel
  • Remove the Noisy Thread.Sleep and WaitForCondition from Selenium Tests
  • Code Snippet to Log All Events as They Are Triggered
  • A Quick Check of Javascript Code Quality
  • Implement Object Builder for Testing in a .NET Object Initializer Style
  • 看过《丰田现场管理方式》,30年前出版的书
全部日志>>

Comments

  • taowen:http://taowen.github.com/bay...
  • dewwind88:呵呵,我信!我也是自己深有同感~-网络上的陌生人,搜索到...
  • sean xu:项目忙完了吗?好像很久没写精益方面的文章了:)...
  • 菜头:good summary ^.^
  • luning:你是说如何确定适合自己team的switch频率吧,多尝...
  • jackie chen:LN,想问问:怎样计算switch pair rate ...
  • sabrina:路子分析的很有道理哦!...
  • sabrina:虽然我不是很懂技术,但是能看出你的用心,加油哦!...
  • ncholas ren:where is the 'continue...'
  • laura:不错,好好学习!

Categories

  • Lean[21]
  • Software Development[2]
  • Agile[15]
  • Life[1]
  • Economics[3]
  • Misc[0]
  • Test[7]
  • Javascript[3]

Tag

  • 敏捷[32]
  • 精益[29]
  • Agile[22]
  • 软件开发[19]
  • Lean[15]
More..