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.
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']
}
}
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).
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.
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.
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…