Search code examples
rubyurlsavewatir-webdriver

Saving a browser url with Ruby and watir-webdriver


I'm using watir-webdriver to do my GUI smoke tests, and one area I'd like to test out is redirecting from a dynamic url

Is it possible to save the url to a file, then load it for use?

What I'm thinking of in pseudo code:

@browser.goto 'google.com'
@browser.url.save

in another test

@browser.load url
continue testing....

Is there a way to do this?


Solution

  • To write a string to a file you can just do that:

     File.open('path/to/yourfile', 'w') { |file| file.write(@browser.url) }
    

    You can use it in the other test like this:

    File.open('path/to/yourfile', "rb") { |file| @browser.goto(file.read) }