WebDriverIO:通过浏览器会话和浏览器启动Chrome;饼干 [英] WebDriverIO: Starting Chrome with browser sessions & cookies

查看:270
本文介绍了WebDriverIO:通过浏览器会话和浏览器启动Chrome;饼干的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在没有创建私有Chrome窗口" (没有缓存或cookie )的情况下,使用Google Chrome运行WebdriverIO测试用例.

Is it possible to run a WebdriverIO test case with Google Chrome, without creating a "private Chrome window" (no cache or cookies).

我要启动Chrome浏览器,但要使用Chrome的cookie和缓存,而不是完全默认的状态

I want to start the Chrome browser I want to use the cookies and cache from Chrome, not a completely default state

方案::我正在Chrome上登录后端,该后端设置了我在本地主机上使用的令牌.当我通过Webdriverio运行测试时,它没有令牌,必须再次进行登录过程.

Scenario: I am logging into our back-end on Chrome, which sets a token that I use on my localhost. When I run a test through Webdriverio, it doesn't have the token and I have to go through the login process once more.

因此,在终端中,如果我运行open http://localhost:3001,Chrome将打开应用程序而无需再次登录.

So, in the terminal, if I run open http://localhost:3001, Chrome will open the application without needing to log in again.

!注意::我不想在测试中经历登录过程...我只想在手动登录后使用Chrome中存储的会话令牌.

!Note: I don't want to go through a login process on my tests... I just want to use the session token stored in Chrome after I login manually.

推荐答案

首先,不要惊吓测试工具从空白状态浏览器启动.谁希望测试上下文被以前的浏览,设置,Cookie等污染?其次,我觉得您想自动化一个任务有点可笑,但是却不介意再执行3-5个步骤来执行成功的登录.

First of all, it shouldn't shock you that a test tool starts from a blank state browser. Who would want the testing context to be polluted by previous browsing, settings, cookies, etc? Secondly, I find it a bit funny that you want to automate a task, but don't care to automate 3-5 more steps to execute a successful login.

如果您需要在Chrome实例中添加一些广泛的配置(Cookie,本地存储,扩展程序,用户和密码),则可以自定义

If you have some extensive level of configurations that need to be added to your Chrome instance (cookies, local storage, extensions, users & passwords), then custom Chrome Profiles is what you're looking for.

  1. 确定Chrome存储默认文件夹的位置
  1. Identify where Chrome is storing the Default folder

您基本上是在尝试使用一组特定的配置生成Chrome.这些通常保存在默认文件夹中(路径:/Users/YourUserHere/Library/Application Support/Google/Chrome/Default ).

You are basically trying to spawn Chrome with a specific set of configs. These are usually kept into the Default folder (path: /Users/YourUserHere/Library/Application Support/Google/Chrome/Default).

!注意:该路径可能因操作系统而异,因此建议的方法是打开新的Chrome标签并找到Chrome在设备上存储这些配置的位置.键入chrome://version.我们在此处寻找的设置是个人资料路径.

!Note: This path might differ from OS to OS, so the recommended way to find out where Chrome is storing these configs on your device is by opening a new Chrome tab & typing chrome://version. The setting we are looking for here is Profile Path.

  1. 默认文件夹的内容存储在指定的资产文件夹中

  1. Store the contents of your Default folder in your designated assets folder

通过--user-data-dir 铬CLI开关:


'goog:chromeOptions': {
// 'moz:firefoxOptions': {
  args: [ '--no-sandbox',
          '--disable-gpu',
          '--start-fullscreen',
          '--disable-notifications',
          '--user-data-dir=/Path/To/Your/CustomConfigsFolder',
        ],
   }
}

  1. 使用browser.debug()&检查配置是否已成功导入.
  1. Run your test with browser.debug() & check the configs have been successfully imported.

注意:我想我在

Note: I think I tackled this in a more generic sense on this answer. Check it out, maybe it further helps in setting this up.

这篇关于WebDriverIO:通过浏览器会话和浏览器启动Chrome;饼干的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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