2011-05-24 41 views
0

我正在使用colorbox库在我的应用程序(http://colorpowered.com/colorbox/)中显示lightbox。该代码似乎在浏览器中正常工作,但我无法使自动化测试正常工作。如何让硒/黄瓜与现在在Lightbox/colorbox中的“隐藏”链接交互?

这里是获取生成一些内嵌HTML:

<div class='hidden'> 
    <div id='override'> 
    Are you sure you want to override this action? 
    <br> 
     <a href="" class="close_colorbox">Cancel</a></li> 
     <a href="#" onclick="override(this); return false;">Override once</a> 
    </div> 
</div> 

这是打开的颜色框的JavaScript:

$.fn.colorbox({innerWidth:600, inline:true, href:'#override', scrolling:false}); 

该代码打开收藏和展示我的“#override的内容'div。在我黄瓜测试中,我可以从该分区中查找文本,但如果我试图遵循链接我得到一个错误:

When I follow "link that generates override"  
    Then I should see "Are you sure you want to override this action?" within "#cboxContent" 
    Then I should see "Cancel" within "#cboxContent" 
    # Then show me the page 
    When I follow "Cancel" within "#cboxContent" 

给出了这样的错误:

Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotDisplayedError) 
[remote server] resource://fxdriver/modules/atoms.js:7903:in `' 
[remote server] file:///var/folders/nn/nn5oYAICGPawlH+1W406+k+++TI/-Tmp-/webdriver-profile20110524-2973-1d5qq7w/extensions/[email protected]/components/nsCommandProcessor.js:249:in `' 
[remote server] file:///var/folders/nn/nn5oYAICGPawlH+1W406+k+++TI/-Tmp-/webdriver-profile20110524-2973-1d5qq7w/extensions/[email protected]/components/nsCommandProcessor.js:298:in `' 
[remote server] file:///var/folders/nn/nn5oYAICGPawlH+1W406+k+++TI/-Tmp-/webdriver-profile20110524-2973-1d5qq7w/extensions/[email protected]/components/nsCommandProcessor.js:313:in `' 
[remote server] file:///var/folders/nn/nn5oYAICGPawlH+1W406+k+++TI/-Tmp-/webdriver-profile20110524-2973-1d5qq7w/extensions/[email protected]/components/nsCommandProcessor.js:190:in `' 
./features/step_definitions/web_steps.rb:35 
./features/step_definitions/web_steps.rb:14:in `with_scope' 
./features/step_definitions/web_steps.rb:14:in `with_scope' 
./features/step_definitions/web_steps.rb:34:in `/^(?:|I)follow "([^"]*)"(?: within "([^"]*)")?$/' 
features/prerequisites.feature:38:in `When I follow "Cancel" within "#cboxContent"' 

有没有人见过这个错误你是如何解决它的? (如果我取消注释'显示我的网页'的步骤,那么它也可以)

+0

看起来好像$ .fn.colorbox调用没有完成时,我试图按照取消链接(所以它仍然隐藏在其他股利)。我试图找出使水豚/硒等待div变得可见的最佳方式。 – nimblegorilla 2011-05-24 18:32:11

回答

0

我遇到了类似Jquery-mobile框架的问题。

据我所知,水豚应该等到所有的AJAX调用完成后再进行检查或继续前进。但是,如果您遇到问题,您认为该页面未完成加载,则可尝试向Capybara的股票“我按”步骤添加一个简单的“睡眠1”步骤,以查看是否有帮助。

+0

是的 - 睡眠1也有效。我认为问题在于colorbox的动画步骤需要几毫秒 - 所以ajax调用完成了,但动画不是。我认为正确的答案应该以某种方式使用selenium.wait_for_condition,但我无法弄清楚如何在我的黄瓜步骤中调用它(“selenium.browserbot.getCurrentWindow()。document.getElementById('colorbox').style。显示=='块'“)。我可能会对我的整个测试套件进行很多这些步骤,睡眠1将开始累加起来! – nimblegorilla 2011-05-27 14:28:40