follow me icons

Tuesday, February 8, 2011

Refresh Issue in Gizmo

I have been forced to use the 'sleep' method to wait for my page to load before I can check elements on the page as a temporary solution to my problem. The tests that I have been running somehow cannot get the element that I wanted. If I use the sleep method and wait for 1 - 2 seconds, then the test will be able to find that element. This is not an ideal solution. The automation test should be able to wait automatically until it can find the element on the page and we should not specify the time to wait.

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