ruby - How does capybara/selenium grab current URL? Issue with single page site -


i using ruby , capybara(which leverages selenium) automate walking through website. after navigating new page verify new page url i'm expecting. issue comes when walk through order funnel single page loads different views.

some code...

i create session instance have additional code opening browser , walking point in website wont include

$session = capybara::session.new(:selenium) 

my line checking browser url without search params ie: after '?'

if url == $session.current_url.to_s.split("?")[0]         urlcorrect = true end 

this code works fine when url

https://www.homepage.com

then click on link takes me order funnel ... https://www.homepage.com/order#/orderpage1?option1=something&option2=somethingelse

my function still matches expected url. issue comes when move second page of order funnel :

https://www.homepage.com/order#/orderpage2?option1=something&option2=somethingelse

my capybara code current url still returns url orderpage1. im guessing because there no postback when moving orderpage1 orderpage2 dont know how force postback or tell capybara re-grab url

any advice appreciated.

thanks

quick edit: forgot mention behavior in ie. chrome , firefox both work correctly exact same code

capybara grabs current_url querying browser - doesn't cache it. issue you're running clicking link move next page doesn't wait page change happen, if call current_url before page load has happened you'll still original url. there 2 solutions - 1. use capybara content doesn't appear until new page loaded ( have_content ), 2. use has_current_path? method wait/retry period of time until current_path/url match

$session.has_current_path?('expected path') 

there options if want match against full url, , can use regex match - http://www.rubydoc.info/gems/capybara/capybara/sessionmatchers#has_current_path%3f-instance_method


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -