0
我有一个iframe这是一种形式的目标改变了:断言高度已使用水豚
<form target="preview">
<textarea name="content"></textarea>
</form>
<iframe name="preview"></iframe>
当在文本区域的用户类型(我省略了为了简洁去抖动码的形式被提交):
$('textarea').keyup(function() {
// debouncer ensures this happens at *most* every two seconds
$('form').submit();
});
而且我这使iframe的高度脚本调整到它的内容:
$('iframe').load(function() {
var height = $('body', $(this).contents()).height();
$(this).height(height);
});
现在我正在编写一个功能规格来声明实际发生的高度调整。我已经确定我需要使用evaluate_script
来获得iframe的高度。所以,从理论上说,我的天赋应该是这个样子:
def preview_iframe_height
page.evaluate_script('$("iframe").height()')
end
scenario 'preview grows to content', js: true do
initial_height = preview_iframe_height
fill_in('Content', with: 'some content')
expect(preview_iframe_height).to be > initial_height
end
但是,此代码不会等待重新填充的iframe请求,总是失败。我知道水豚非常善于利用像have_content
这样的匹配器来等待内容出现,但我不知道如何去等待高度发生变化。有任何想法吗?
我的测试套件:
- RSpec的
- 水豚
- 骚灵
您可能会发现此链接有帮助: http://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara它是关于等待ajax完成,但你可以适应它等待,直到你的jQuery完成调整大小,然后再检查高度, – 2014-09-23 23:55:12
您可能也会发现这也很有帮助:http://animalssittingoncapybaras.tumblr.com/它会让您放心解决问题。 – Jake 2014-09-23 23:57:19