Jasmine / Karma test: browser not defined

If this test:

'use strict' describe('application', function() { it('should login', function() { browser().navigateTo('/'); expect('111').toBe('111'); }); }); 

includes the string "browser" , the result:

 Chrome 26.0 (Windows) application should login FAILED ReferenceError: browser is not defined at null.<anonymous> (...../test/js/e2e/tests/test.js:6:9) Chrome 26.0 (Windows): Executed 1 of 1 (1 FAILED) (0.359 secs / 0.004 secs) 

but without this line, the test will succeed.

People suggest including angular-scenario.js , but that breaks the tests.

 expect('111').toBe('222'); 

evaluated as true.

What to do?

+4
source share
2 answers

You need your application server to work with a pencil. So Node.js:

 node app.js 

Also, make sure you change the urlRoot property in your karma configuration so that it does not contradict your application, and yes, you need angular -scenario.js

 files = [ ANGULAR_SCENARIO, ANGULAR_SCENARIO_ADAPTER, 'test/**/*_spec.js' ]; urlRoot = '/__karma/'; proxies = { '/' : 'http://localhost:3000/' }; 
+7
source

I also ran into this problem. I believe that you can only call browser () inside beforeEach (); Try the following:

 'use strict' describe('application', function() { beforeEach(function(){ browser().navigateTo('/'); }); it('should login', function() { expect('111').toBe('111'); }); }); 
0
source

All Articles