Watir自动化后如何备份浏览器状态 [英] How to backup browser state after Watir automation

查看:110
本文介绍了Watir自动化后如何备份浏览器状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我目前正在使用Watir WebDriver来自动化许多网站上的Chrome会话。我需要在整个会话的某些时间备份Web浏览器的状态(cookie,缓存等)。最初,我认为可以使用Ruby的文件IO库做到这一点,方法是在必要时复制〜/ Library / Application Support / Google / Chrome / Default 。但是,用Watir WebDriver创建的Chrome会话似乎没有在此默认位置存储所需的信息。如何找到该数据进行备份?此信息是否存储在其他位置?除了Watir之外,还有其他方法可以使此操作更容易吗?

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?

推荐答案

我终于有了解决方案!

似乎watir-webdriver将浏览器状态/用户数据存储在随机路径中。默认情况下,可以在此处找到(XXXXXX是随机标识符):

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]

然后是缓存,Cookie等。可以使用Ruby的标准库进行备份,删除等。希望这会对其他人有所帮助。

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

编辑:如果默认情况下您找不到watir-webdriver将用户数据存储到的位置,请找到Chrome的通过运行watir-webdriver和 top 来获取进程ID。有了pid后,在终端中输入 lsof -p< pid> 来查找用户数据的路径。

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.

这篇关于Watir自动化后如何备份浏览器状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆