19

I have a test which each time I run it, throws "UnknownError: unknown error: Maximum call stack size exceeded. "

This test is calling a method in one of my services which writes to Google Drive.

The test that is failing is calling my doDrive function with "ui", meaning update a Drive item. If I change a single character "ui" -> "ni", meaning create a new Drive item, the test works. The code under test works fine in normal use.

it('should update a file', function() {
browser.executeAsyncScript(function(callback) {
    // get service
    var service=angular.element(document.getElementById('ngapp')).injector().get('DriveQ')
    // generate a title
    var title = 'title of file';
    // call doDrive to create a new file
    service.doDrive({t:'ui',id:'0B6B-RNrxsCu2Sll7JZTYy2aDA', item:{title:title}})
        .then(function (resp){
                    resp.originalTitle=title;
                    callback(resp)
            });
}).then(function(resp) {
    expect(resp.title).toEqual(resp.originalTitle);
});
});

I'm using the chrome webdriver directly, and I also have browser.ignoreSynchronization = true;

igauravsehrawat
  • 2,959
  • 1
  • 28
  • 44
pinoyyid
  • 19,003
  • 12
  • 50
  • 100
  • What's your service look like? – Abraham P Sep 21 '14 at 09:58
  • it's a big complex piece of code that builds and submits Google Drive REST API transactions. Key points... (1) the service works just fine, it's only the test which is broken, (2) the code path is virtually identical between a working test (REST PUT) and the one that fails (REST POST). Is there some specific aspect of the service that could be pertinent? – pinoyyid Sep 21 '14 at 14:52
  • there's a few things that commonly trigger that particular exception. The obvious thing that comes to mind is a $watch on an object – Abraham P Sep 21 '14 at 19:17
  • I don't use $watch in my app. – pinoyyid Sep 22 '14 at 03:05

1 Answers1

18

I'm having the same issue. I've found that returning big objects from the browser to protractor leads to the "UnknownError: unknown error: Maximum call stack size exceeded" error.

You should check the complexity of the resp object you're sending back with the callback. If it's too big, try to send back less data.

This can happen with executeAsyncScript, executeScript and evaluate (which use executeScript).

Edit by OP...

Fixed by changing callback(resp) to callback({title:resp.title}), ie simplifying the returned object to contain only those items that I am aserting.

pinoyyid
  • 19,003
  • 12
  • 50
  • 100
Offirmo
  • 16,196
  • 8
  • 69
  • 90
  • 1
    I found out that you can't pass too big objects to the browser either. I use the second parameter of `browser.executeScript` to pass in an element, and had to use the `getWebElement` function to avoid this error. – Olov Aug 18 '15 at 10:40