I am currently using Gizmo, a page model testing framework, to dry up my testing assertion.
on_page_with :seo do |page|
page.seo_result_lists.should =~ /#{title}.*/
end
And inside the seo page I have the following code:
def seo_result_lists
@document.css("#navigation_listings").inner_text
end
The code above turns out to not give me the latest html content. The reason is because Gizmo is using Nokogiri to get the HTML content. When the page is initialized it will grab whatever html content it is currently loading. That is why my "@document.css("#navigation_listings").inner_text" returns nill instead of the text that I want.
One solution is to always 'Refresh' the page by assigning @document with the latest html content again "@document = Nokogiri::HTML(body)". However, this is not ideal because you have to refresh every time you want to get the value.
Another solution is to just not use the @document variable but to just use the capybara find method which will automatically wait until it finds the element to appear on the page. I eventually use this Capybara 'find' method over the @document.
After
def seo_result_lists
find(:css,"#navigation_listings").text
end
No comments:
Post a Comment