保持量角器浏览器会话活动 [英] keep protractor browser session alive

查看:23
本文介绍了保持量角器浏览器会话活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处看了,但似乎只有我一个人在问这个问题.

I have looked everywhere but it looks like I am only person asking this.

如何使量角器中的浏览器会话保持活动状态,而不是每次运行测试时都必须登录.我已将登录逻辑放在 onPrepare 中以避免记录每个测试功能

How to keep browser session in protractor alive, not to have to login everytime I run a test. I have put login logics in onPrepare to avoid logging for every test function

onPrepare: function() {
    var mymodule = require("./e2e/mymodule");
    mymodule.login();
    mymodule.switchToProject("someproject");
}

但是每次我运行我想跳过的量角器时,登录仍然需要 3-4 秒.有什么想法吗?

But still logging in takes 3-4 seconds for every time I run protractor which I would like to skip. Any idea's ?

我更喜欢 chromeOnly: true 设置的解决方案,但单独的 selenium 服务器的解决方案也可以

I prefer a solution for chromeOnly: true setting but a solution for seperate selenium server would be fine as well

推荐答案

Protractor 每次运行时都会创建一个全新的 Chrome 配置文件.在搞砸之前,您需要知道这为您的测试提供了可靠性:它们每次都会以相同的方式运行,因为它们是从一张白纸开始的.如果您决定使用已登录的持久配置文件,那么一旦登录过期、配置文件被删除或您尝试在另一台计算机上运行它们,您的量角器测试就会开始失败.

Protractor creates a brand new Chrome profile every time it runs. Before messing with this, you need to be aware that this provides reliability for your tests: they will run the same way every time because they are starting from a blank slate. If you decide to use a persistent profile that is already logged in, then your Protractor tests will start failing as soon as the login expires, the profile gets deleted, or you try to run them on a different computer.

也就是说,有一种方法可以让 Chrome 在每次运行 Protractor 测试时重复使用相同的配置文件(包括 cookie 和所有设置).在你的 protractor.conf.js 你会做这样的事情:

That said, there is a way to ask Chrome to reuse the same profile (including cookies and all settings) for each run of Protractor tests. In your protractor.conf.js you'll do something like this:

capabilities: {
    'browserName': 'chrome',
    'chromeOptions': {
        'args': ['--user-data-dir=/a/random/path']
    }
}

这里的'args'是操作部分.它允许您在启动时将命令行参数传递给 Protractor 的 Chrome 版本(例如,您可以传入 '--start-maximized' 以在启动时最大化 Chrome).

The 'args' here is the operative part. It lets you pass command-line arguments to Protractor's version of Chrome when it starts up (for example, you could pass in '--start-maximized' to maximize Chrome on startup).

/a/random/path 替换为系统上的任何文件路径(从根目录开始).只需确保您引用的文件夹已创建.您无需使用自己的 Chrome 配置文件路径——这只是不必要的麻烦.在某处创建一个文件夹并使用它.

Replace /a/random/path with any file path (starting from root) on your system. Just make sure the folders you're referencing have been created. You don't need to use your own Chrome profile path--that's just unnecessary hassle. Create a folder somewhere and use it.

当 Protractor 启动 Chrome 时,它​​的配置文件将位于您指定的位置,并且只要您的路径保持不变,它就会继续使用它.

When Protractor starts Chrome, its profile will be in the location you specified, and it will continue to use it as long as your path remains unchanged.

请记住,这是一个浏览器操作,与 Selenium 或 Protractor 的操作完全无关.我不知道 Firefox 或其他浏览器是否有办法做到这一点,因为每个浏览器表面上都有自己的用户配置文件存储方式.

Keep in mind that this is a browser operation, not at all related to what Selenium or Protractor is doing. I don't know if there is a way to do this with Firefox or other browsers, since each one ostensibly has its own way of storing user profiles.

这篇关于保持量角器浏览器会话活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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