7

I have onPrepare in my conf.js file where I log in to the application. My understanding is every time I run 1 or more test suites, it first executes whatever is in onPrepare. This is great, as I use onPrepare to log into the application before running the tests.

Issue is, I don't want to login when I run my login-spec.js suite.

I could first logout before running through login-spec.js, but there must be a more elegant way to do this.

Jason
  • 1,787
  • 4
  • 29
  • 46

1 Answers1

5

As far as I understand, you need a place for suite-specific preparations.

This is what jasmine can help you with.

For jasmine 2.1 and above, there are built-in beforeAll and afterAll notations:

The beforeAll function is called only once before all the specs in describe are run, and the afterAll function is called after all specs finish. These functions can be used to speed up test suites with expensive setup and teardown.

If you are on an older jasmine version, use a separate jasmine-beforeAll package.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Thanks for this. How do I know which version of jasmine I'm using? I followed the installation directions for protractor from http://angular.github.io/protractor/#/tutorial – Jason Jan 08 '15 at 05:46
  • or more importantly, how do I upgrade to 2.1 :) – Jason Jan 08 '15 at 05:47
  • @Jason what is the output of `npm list jasmine-core`? – alecxe Jan 08 '15 at 06:01
  • jasmine-core@2.1.3, but, when I do this 'console.log('jasmine-version:' + jasmine.getEnv().versionString());', it prints 1.3. odd. – Jason Jan 08 '15 at 06:03
  • my package.json file is showing "jasmine-core": "~2.1.2". I guess this means I'm running 2.1 – Jason Jan 08 '15 at 06:03
  • It's telling me beforeAll is not defined, so I'm not on 2.1. Strange that npm list jasmine-core tells me it's 2.1 – Jason Jan 08 '15 at 06:11
  • @Jason I suspect it is not in the core yet, use `jasmine-beforeAll` please. Sorry for the confusion. – alecxe Jan 08 '15 at 06:40
  • https://github.com/angular/protractor/issues/362 Jasmine2 only made it a few days ago. – Jason Jan 08 '15 at 08:31
  • @Jason good to know and thanks for sharing! Have you tried `jasmine-beforeAll`? – alecxe Jan 08 '15 at 13:08
  • Not yet. I got caught up with other tests :) Ill give it a try later today – Jason Jan 08 '15 at 13:25
  • 1
    As explained in the other issue: http://stackoverflow.com/questions/27835554/protractor-jasmine-showing-different-versions-what-am-i-doing-wrong/27847995#27847995, you have to specify which Jasmine version you want to use, as protractor does not force you onto jasmine 2.x – hankduan Jan 08 '15 at 19:29