11

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

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");
}

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

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

5
  • Ha! My e2e suites is thousands of tests and takes ~ 30mins but you complain for 3-4 seconds? Hehe, Only unit testing with Karma can target such a speed, Protractor e2e is meant to start on a new session browser & session cache every time and login again every e2e run at least as a first step. Sep 9, 2014 at 17:05
  • That being said, you need to search for a way to reuse Chrome profile on every run, using the same profile will allow the browser to keep cookies. Sep 9, 2014 at 17:06
  • 1
    Thanks Leo for your tip I will look web for how to reuse a specific chrome profile. Meanwhile I have thought of another good solution, to implement login through an API key which will need just one line browser.get()
    – papoola
    Sep 12, 2014 at 17:21
  • Haha btw of course total of tests would be time consuming and login time is relatively very small like you say. But I will use tests most of time by using ddescribe and iit - so that only one feature which I building needs to be tested after every few lines of code - in that case login of 3-4 seconds following by 3-4 seconds of iit would be kindof annoying
    – papoola
    Sep 12, 2014 at 17:27
  • I also want to do this, and I agree that we need to find a way to keep protractor sessions in between tests (Ideally with also an REPL environment)
    – Dinis Cruz
    Nov 25, 2014 at 10:43

2 Answers 2

11

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.

0
1

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

The best choice is to start the Chrome browser session your self, and then provide the session id to protractor.

There are multiple ways of doing this

  1. Using a script to start the browser - e.g. webdriver-reuse-session that I have created, and I will expand it for better support for this problem.
  2. Use the Selenium Standalone Web interface at

Let me know if this solves your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.