当我们使用 Internet Explorer Driver 时,我们使用字段 IE_ENSURE_CLEAN_SESSION
IE_ENSURE_CLEAN_SESSION
根据JavaDocs IE_ENSURE_CLEAN_SESSION是定义在IEDriverServer启动Internet Explorer之前是否清理浏览器缓存的能力,配置如下:
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
现在让我们看看WebDriver Spec之后的GeckoDriver。
GeckoDriver / moz:profile / rust_mozprofile
如果您仔细查看 geckodriver 日志,您会发现每次 geckodriver 都被称为新的 moz:profile 被排除在外,rust_mozprofile 的详细信息出现在以下行中:
Marionette CONFIG Matched capabilities: {"browserName":"firefox","browserVersion":"56.0","platformName":"windows_nt","platformVersion":"6.2","pageLoadStrategy":"normal","acceptInsecureCerts":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"rotatable":false,"specificationLevel":0,"moz:processID":5848,"moz:profile":"C:\\Users\\AtechM_03\\AppData\\Local\\Temp\\rust_mozprofile.OfFuR9ogm33d","moz:accessibilityChecks":false,"moz:headless":false}
此日志清楚地表明 Marionette 挖出了一个新的 "moz:profile":"C:\\Users\\AtechM_03\\AppData\\Local\\Temp\\rust_mozprofile.OfFuR9ogm33d",此配置由 WebDriver 实例处理,即 GeckoDriver。
您可以在Is it Firefox or Geckodriver, which creates “rust_mozprofile” directory讨论中找到关于moz:profile的更详细讨论。
ChromeDriver
ChromeDriver 遵循同一个 WebDriver Spec 确实遵守(将遵守)同一个套件。
如果您使用任何存储的 FirefoxProfile 或 ChromeProfile,WebDriver 将选择现有的配置文件,其中 Stored Browser Configurations 被拾取以供重复使用。
driver.manage().deleteAllCookies();
无论新的/现有的 FirefoxProfile 或 ChromeProfile 如果您添加以下行:
driver.manage().deleteAllCookies();
只有 cookie 被删除才能恢复以支持 Active Browser Session