How to backup browser state after Watir automation

Summary of tools:
 watir-webdriver 1.8.17
 Mac OS X 10.7.3
 Chrome 18.0.1025.151

I'm currently using Watir WebDriver to automate Chrome sessions across a number of websites. I need to backup the state of the web browser (cookies, cache, etc.) at certain points throughout the session. Originally, I figured I could do this with Ruby's file IO library by copying ~/Library/Application Support/Google/Chrome/Default at the necessary points. However, it does not appear that Chrome sessions created with Watir WebDriver store the needed information in this default location. How can I locate this data to back it up? Is this information stored elsewhere? Is there something other than Watir that would make this easier?

Answers


I finally have a solution!

It appears that watir-webdriver stores the browser state/user data in random path. By default this can be found here (where XXXXXX is the random identifier):

/private/var/folders/2v/vkd2v3vs5njf69m59nqzc16m0000gn/T/.com.google.Chrome.XXXXXX/Default/

Instead of relying on this default and randomized path, you can specify a precise location for the user data using the following flag:

Watir::Browser.new :chrome, :switches => %w[--user-data-dir=/path/to/user/data]

Then the cache, cookies, etc. can be backed up, deleted, etc. using Ruby's standard library. Hopefully this helps someone else.

Edit: If you are unable to find where watir-webdriver is storing your user data by default, find Chrome's process id by running watir-webdriver and top. Once you have the pid, type lsof -p <pid> into terminal to find the path to the user data.


Need Your Help

Python Pathlib avoid Permission Errors when using Iterdir()

python pathlib

I was starting to build a "Directory Explorer" GUI for a small program I wrote and was using Pathlib since I hadn't used it before. Unfortunately I got stuck pretty much right off the bat iterating...

jQuery iteration question (confused by example in a book)

jquery iterator toggle

I'm working my way through the O'Reilly jQuery Cookbook. On p. 100 there is an example where I don't get one detail. I'm in my first week of looking at jQuery, so that's no surprise, but I'm hoping