Karma Jasmine PhantomeJS test failing ramdomly - angularjs

I have a really strange behavior in my test for a simple angularJS app
Setup:
Karma v0.10.9
PhantomJS 1.9.7
All test passing the first time ( sometimes the second or third too :-) ) But after a while test failing randomly
There are two kinds of errors
TypeError: 'null' is not an object (evaluating 'errorForStack.stack')
at workFn (<my_path>/angular-mocks.js:1811)
and
Error: SECURITY_ERR: DOM Exception 18
//Line $window.openDatabase('myDB', "", 'Offline DB', 5 * 1024 * 1024);
Problem occurs on Windows and Linux
Current fix -> restart Karma --> But i hate this solution since continuous testing is just great
Any suggestions ?

Fixed the first problem ( Bug in angular-mocks.js ).
Second problem fixed by mocking openDatabase.
Thx for the help

Related

How to fix the below test case when i am migrating from angularjs 1.6.9 to 1.7.8

i am trying to migrate my angularjs application from v1.6.9 to v1.7.8. my test case are failing with
angular-mock.js($rootScope)
ERROR: No response Defined! in angularjs/angular-mocks.js(1607)
ERROR:$rootScope:INPROG
since i am new to jasmine karma testing i have tried with $rootscope.flush(). but i am not able to resolve it .
this is my first unit testing with Angularjs and jasmine karma, not able to find the exact reason and i have gone through the release notes of the other releases as well.
with $rootScope i found that they have modified its scope to the function not generic.
Below is my spec.js:
I am getting error with $rootscope,flush(). could some please help me out to resolve this issue as it is required.
$httpBackend.when('GET','/application/api/prefernce-definition')
.respond(successResponsePrefernces);
$httpBackend.when('POST','/application/api/setprefernce-definition')
.respond(201);
$httpBackend.when('POST','/application/api/v1/set-prefernces');
$httpBackend.when('POST','/application/api/v2/balances')
.respond(accountApiResponse);
//assertion for expecting proper get request for preferences-definition
$httpBackend.expectGET(,'/application/api/v1/prefernce-prefernces');
//fetch and set prefernces
$scope.onclickSetting();
$rootScope.flush();
$timeout.flush();
//now save the settings
$scope.saveViewSettings();
// getting error in this line after the flush
$rootScope.flush();
$timeout.flush();
var viewMode = $scope.model.viewSettings.viewMode,
viewModeExpected = successResponsePreferences.preferenceDefinitionList[0];
expect(viewMode.default).toBe(viewModeExpected.defaultPreferenceValue);
expect(viewMode.selected).toBe(viewModeExpected.currentUserPreferenceValue);
expect($scope.$broadcast).toHaveBeenCalledWith("ShowFilter");
//should update the prefernces in cache
expect(viewMode.selected).toBe(cacheService.getPreferences().viewMode);
expect(analyticsService.sendAction).toHaveBeenCalledwith(
Constant.ACCOUNT_BALANCES.MODULE_NAME,
Constant.ACCOUNT_BALANCES,VIEW_SETTINGS,
[]
);
expect(analyticsService.sendAction).toHaveBeenCalledwith(
Constant.ACCOUNT_BALANCES.MODULE_NAME,
Constant.ACCOUNT_BALANCES,VIEW_SETTINGS,
[Constant.EXTD_MODE, Constant.NO_GROUPING]
);
});
Below are the errors:
Error: No response defined! In
../bower_components/angular-mocks/angular-mocks.js(line 1607) $httpBackend#/../bower_components/angular-mocks/angular-mocks.js:1607:63.

"TypeError: Cannot read property 'pseudoType' of undefined" with chrome-devtools

I'm developing an electron app with React for the front-end. I get the following error in my console when I run my app and hit refresh. My app works as expected, but it's kind of annoying to see this error pop up in my console and not know what it means. Any ideas?
This is the error message I get in my console:
[1] [36084:0511/083524.886880:ERROR:CONSOLE(972)] "TypeError: Cannot read property 'pseudoType' of undefined TypeError: Cannot read property 'pseudoType' of undefined
[1] at SDK.DOMNode._removeChild (chrome-devtools://devtools/bundled/shell.js:4301:28)
[1] at SDK.DOMModel._childNodeRemoved (chrome-devtools://devtools/bundled/shell.js:4420:121)
[1] at SDK.DOMDispatcher.childNodeRemoved (chrome-devtools://devtools/bundled/shell.js:4464:54)
[1] at Protocol.InspectorBackend._DispatcherPrototype.dispatch (chrome-devtools://devtools/bundled/shell.js:3399:26)
[1] at Protocol.SessionRouter._onMessage (chrome-devtools://devtools/bundled/shell.js:3355:41)
[1] at SDK.MainConnection._dispatchMessage (chrome-devtools://devtools/bundled/shell.js:3486:17)
[1] at Common.Object.dispatchEventToListeners (chrome-devtools://devtools/bundled/shell.js:494:23)
[1] at innerDispatch (chrome-devtools://devtools/bundled/shell.js:972:98)
[1] at Host.InspectorFrontendAPIImpl._dispatch (chrome-devtools://devtools/bundled/shell.js:972:1)
[1] at DevToolsAPIImpl._dispatchOnInspectorFrontendAPI (chrome-devtools://devtools/bundled/devtools_compatibility.js:57:36)", source: chrome-devtools://devtools/bundled/shell.js (972)
I've isolated the error to this snippet of code below. If I comment it out, I don't get the error. I couldn't find the cause of the error by reading the BrowserWindow docs.
BrowserWindow.addDevToolsExtension(
path.join(
os.homedir(),
"/Library/Application Support/Google/Chrome/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/3.6.0_0"
)
);
BrowserWindow.addDevToolsExtension(
path.join(
os.homedir(),
"/Library/Application Support/Google/Chrome/Default/Extensions/lmhkpmbekcpmknklioeibfkpmmfibljd/2.17.0_0"
)
);
mainWindow.webContents.openDevTools();
I think that the problems here could be of two different types: the path is incorrect, there is already a path that exists as the one you passed as a parameter or you are calling this function before that the module app is on its ready state.
To solve the first problem i would test the path that os.homedir() gives you back in a different part of the code to see what ends up to be at the time that you join it with the path indicated
in the function join; "/Library/Application/Support/Google/Chrome/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/3.6.0_0".
To solve the second problem i would refactor the code to call the function in the appropriate lifecycle point to be sure that the app module is on the ready state.

Protractor - how to call the WebDriver methods?

I'm trying to use the deleteAllCookies() function from WebDriver from a Protractor test spec.
I've tried:
browser.driver.deleteAllCookies(); // undefined error
browser.driver.options.deleteAllCookies(); // undefined error
browser.manage().deleteAllCookies(); // doesn't seem to be deleting cookies
How do I call/use this function correctly?
This works for me with protractor 1.5.0, selenium-webdriver: "2.44.0"
browser.driver.manage().deleteAllCookies();
In protractor the way to delete all your cookies is:
ptor.manage().deleteAllCookies();

Protractor: timed out after 10000 msec waiting for spec to complete

I have several protractor tests and sometimes I get a error saying:
Message:
timeout: timed out after 10000 msec waiting for spec to complete
Stacktrace:
undefined
It can be randomly happening on some tests.
I usually test on BrowserStack and it shows the error once in 3-5 builds. But recently I tried SauceLabs and almost every (every!) but not all the tests fail with that error. Probably, SauceLabs are just significantly slower so I get the error more often...
So here are the questions:
Is there a way in Protractor/Selenium to change test running timeout? It needs to be changed on BrowserStack/Saucelabs as well.
Why am I getting the error so often? Is there anything wrong with my tests? Most of the doesn't seem complicated or long running. Again, on local machine it's almost always fine.
Here is the example:
it('should check that login gives error on empty or incorrect email', function () {
p.get('/#/login');
p.findElement(protractor.By.css('button[type="submit"]')).click();
expect(p.findElement(protractor.By.css('.alert-danger')).getText()).toEqual('E-mailadres is niet geldig');
p.findElement(protractor.By.model('user.email')).sendKeys('test-1xtc.vc');
p.findElement(protractor.By.css('button[type="submit"]')).click();
expect(p.findElement(protractor.By.css('.alert-danger')).getText()).toEqual('E-mailadres is niet geldig');
p.findElement(protractor.By.model('user.email')).clear();
});
The app is using
AngularJS, selenium 2.20, protractor 0.20.1
Is there a way in Protractor/Selenium to change test running timeout?
Yes :) You can do it via the allScriptsTimeout in your Protractor config (from Protractor FAQ)
You can also set the defaultTimeoutInterval in jasmineNodeOpts option (from Protractor referenceConf.js)
Why am I getting the error so often? Is there anything wrong with my tests? Most of the doesn't seem complicated or long running. Again, on local machine it's almost always fine.
Hard to say without seeing your tests. The example you provided looks good to me.
Is your project an angularjs project? Are you using any $interval or $timeout service somewhere? If so, try to use $interval instead of $timeout and try to adjust the optional 'count' parameter to be 1, for example (https://docs.angularjs.org/api/ng/service/$interval#usage).
I had recently a similar problem and I solved it this way.
I solved it using a different property of config file, which I didn't see mentioned in answers above.
getPageTimeout : 100000 //in millis, i.e., 100 secs
the default time for saucelabs is 90 seconds I believe. it can be changed via your conf.js file using the idleTimeout variable which takes in a value of seconds. example
idleTimeout = 90; // equals 90 seconds
exports.config = {
//Includes test sub-sub-foldersbefore any tests in sub folders
specs: ['tests/*/*/*.js', 'tests/*/*.js', ],
// use jasmine 2
framework: 'jasmine2',
capabilities : {
browserName: "chrome",
// this takes seconds so 120 would be 120 seconds.
idleTimeout = 120;
},
},
Now if you need to change the value of a specific spec file you can use this inside your spec file, of course if your saucelabs idleTimeout is lower than this value than it will time out on saucelabs first. or if your saucelabs value is higher but the DEFAULT_TIMEOUT_INTERVAL is lower then it will time out.
// this takes in miliseconds so 1000 = 1 second
jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;
Jasmine has timeout for each spec i.e. each it in jasmine framework. so if any spec (it) exceeds jasmine spec's default timeout then it fails that spec.
Solution:
To override jasmine spec timeout for one individual spec, pass a third parameter to it:
it(description, testFn, timeout_in_millis)
it('description of test case', function() {
/*your test
steps
here*/
},120000);//120 seconds timeout for this spec
more information on timeouts is here

AngularDart on Firefox fails with "receiver.webkitCreateShadowRoot is undefined"

I have an AngularDart application that is working fine on Chromium and Chrome with Javascript. But in Firefox and IE, I get the following error:
[14:36:14.648] "NullError: receiver.webkitCreateShadowRoot is undefined
STACKTRACE:
.Element.createShadowRoot$0#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:84445
J.createShadowRoot$0$x#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:153659
._ComponentFactory.call$6#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:11337
.BlockFactory__instantiateDirectives__closure2.call$1#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:11097
.Primitives_applyFunction#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:5148
._FactoryProvider.get$2#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:125034
J.get$2$x#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:153716
.DynamicInjector__getInstanceBySymbol_closure.call$0#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:124806
._defaultCreationStrategy#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:125162
.Binding.creationStrategy$3#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:125271
.DynamicInjector._getInstanceBySymbol$2#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:124652
.DynamicInjector.get$1#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:124694
J.get$1$x#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:153713
.BlockFactory__instantiateDirectives_closure3.call$1#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:11183
.IterableMixinWorkaround_forEach#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:22126
.JSArray.forEach$1#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:1995
J.forEach$1$ax#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:153707
.BlockFactory._instantiateDirectives$5#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:10887
.BlockFactory._dom$_link$4#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:10816
.BlockFactory._dom$_link$4#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:10818
.BlockFactory._dom$_link$4#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:10818
.BlockFactory._dom$_link$4#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:10818
.BlockFactory.call$2#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:10776
.ngBootstrap_closure0.call$0#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:7661
._rootRun#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:27183
._ZoneDelegate.run$2#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:34652
.NgZone__onRun_closure.call$0#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:10306
.NgZone._onRunBase$4#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:10162
.NgZone._onRun$4#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:10181
$$.BoundClosure$4<.call$4#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:424
._ZoneDelegate.run$2#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:34652
._CustomizedZone.run$1#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:35046
.ngBootstrap#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:7485
.main#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:130170
._IsolateContext.eval$1#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:3635
.startRootIsolate#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:3301
#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:161315
#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:161295
#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:161309
#http://127.0.0.1:3030/foobarUI/web/foobarui.dart.js:9
"
Here is my foobarUI/pubspec.yaml:
name: foobarUI
description: A sample web application
dependencies:
angular: 0.9.3
browser: any
json_object: any
petitparser: any
unittest: any
foobar:
path: ../foobarLib
I tried to add the js, shadow_dom and web_ui modules but it made no difference.
I tried to add "useShadowDom = true;" (and false) to the main dart file, no difference.
From the error, it seems obvious that the webkit support for DOM shadow root is missing but why is this module not handling this ?
The same error occurs with angular.dart.tutorial chapter_03 sample. This is clearly an issue with Angular.Dart. Bug filed as: https://code.google.com/p/dart/issues/detail?id=15752
The Dart bug for issue is at: https://code.google.com/p/dart/issues/detail?id=15144
It has been fixed in Dart bug has not been pushed to AngularDart yet. That work is blocked by https://github.com/angular/angular.dart/issues/366.

Resources