Search code examples
ruby-on-rails-3.2integration-testingwatirwatir-webdriverautomated-tests

watir: Fetch params[:id] from URL


I am using watir for testing my rails 3 webapplication which is working fine.

My problem is, my current page url is localhot:3000/sites/535/ecosystem/new. NOw:

  • I want to logout from the page and re-login.
  • Then, I will reach at dashboard page, where I am displaying list of sites.
  • I want to click on the last created site name, so that, I redirects me back to same state, where I left that study i.e. localhost:3000/sites/535/ecosystem/new

But my problem is I am using datatable for displaying sites, and it is sorting site list with sitename.

One solution I got for this problem is, If I can fetch @id = params[:id] from localhost:3000/sites/535/ecosystem/new then I can do:

@browser.goto "localhost:3000/sites/#{@id}"

which is the url for my site link in dashboard page.

HOW TO FETCH params[:id] from current URL in watir or watir-webdriver?

thanks


Solution

  • I have resolved this problem with ruby logic, but still waiting for some good logic.

    Solution

    url = @browser.url
    #> ["localhost:3000/sites/535/ecosystem/new"]
    
    uri = url.split("/sites/")
    #> ["localhost:3000", "535/ecosystem/new"]
    
    uri = uri[1].split("/ecosystem/new")[0]
    #> "535"
    

    I can now access id i.e 535 in current url. But still wating for some good logic for resolving this issue.

    Thanks