xebia / VisualReview

VisualReview, a human-friendly tool for testing and reviewing visual regressions.
https://github.com/xebia/VisualReview#see-it-in-action
Apache License 2.0
276 stars 24 forks source link

TypeError: Cannot read property 'getCapabilities' of undefined #51

Open drptbl opened 9 years ago

drptbl commented 9 years ago

Hello. I'm using VisualReview with Protractor and it's plugin. After everything is set-up like in a guide, even if my VisualReview works good, it takes screenshots and everything - after all specs are run I'm getting an error in console. I don't know if it has any impact on my tests (looks like not), but still would love to fix it.

JMs-MacBook-Pro:protractortesting jm$ protractor protractor.conf.js 
created run with ID 3
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
Spec started

  1 Home Page
    ✓ should render properly (11 secs)
    ✓ should contain proper title (2 secs)

  2 Login Page
    ✓ should render properly (12 secs)
    ✓ should contain proper title (3 secs)

    2.1 Cookie Window
      ✓ should contain cookie frame with elements (3 secs)
      ✓ should contain cookie description (3 secs)
      ✓ should contain cookie more.. text (3 secs)
      ✓ should redirect user to cookie page after click on more.. text (4 secs)
      ✓ should contain cookie accept button (3 secs)
      ✓ should close cookie frame after acceptation (3 secs)

Executed 10 of 10 specs SUCCESS in 46 secs.
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 passed

/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1877
      var result = fn();
                   ^
TypeError: Cannot read property 'getCapabilities' of undefined
    at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:430:19
    at promise.ControlFlow.runInFrame_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1877:20)
    at promise.Callback_.goog.defineClass.notify (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:2464:25)
    at promise.Promise.notify_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:563:12)
    at Array.forEach (native)
    at Object.goog.array.forEach (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/array/array.js:203:43)
    at promise.Promise.notifyAll_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:552:16)
    at goog.async.run.processWorkQueue (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/async/run.js:125:21)
    at runMicrotasksCallback (node.js:337:7)
    at process._tickCallback (node.js:355:11)
[launcher] Process exited with error code 1

repository: https://github.com/drptbl/protractortesting/

I've commented the lines with visualreview code and error is gone so it's related to visualreview for sure.

any suggestions? maybe some bad interactions with jasmine2-html-screenshot-reporter which makes screenshots too? would be great to fix this.

Regards, drptbl.

drptbl commented 9 years ago

I've confirmed it's a problem with this code:

    // html reporter (protractor-jasmine2-html-reporter)
    jasmine.getEnv().addReporter(
    new HtmlScreenshotReporter({
    dest: '.tmp/htmltestreports',
    filename: 'report.html',
    ignoreSkippedSpecs: false,
    captureOnlyFailedSpecs: false,
    reportOnlyFailedSpecs: false
    }));

after commenting this, I've got no errors. but still atleast I'm able to use Junit reporter without any problems.

    jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
        consolidateAll: false,
        savePath: '.tmp/junittestreports'
    }));
      // add jasmine spec reporter
      jasmine.getEnv().addReporter(new SpecReporter({
            displayStacktrace: 'summary',    // display stacktrace for each failed assertion, values: (all|specs|summary|none)
            displayFailuresSummary: true, // display summary of all failures after execution
            displayPendingSummary: true,  // display summary of all pending specs after execution
            displaySuccessfulSpec: true,  // display each successful spec
            displayFailedSpec: true,      // display each failed spec
            displayPendingSpec: true,    // display each pending spec
            displaySpecDuration: true,   // display each spec duration
            displaySuiteNumber: true,    // display each suite number (hierarchical)
            colors: {
                   success: 'green',
                   failure: 'red',
                   pending: 'yellow'
            },
            prefixes: {
            success: '✓ ',
            failure: '✗ ',
            pending: '* '
            },
      }));

so it's related to other plugins making screenshots or something like that? any way to fix? or not possible?

skwakman commented 9 years ago

It seems you might have run into this issue of the jasmine2-screenshot-reporter. It relates to protractor not (always) waiting for jasmine reporters to finish what they're doing.

If we remove the vr.cleanup() call in the afterLaunch callback, everything indeed works fine. However, if I replace the vr.cleanup() call with something random that causes protractor/jasmine to wait for a promise to resolve, the error pops up again. Even if the promise resolves after a very short time:

 afterLaunch: function (exitCode) {
       //return vr.cleanup(exitCode);
      // run npm install q before running this code
       var q = require('q');
       var deferred = q.defer();
       setTimeout(deferred.resolve, 1);
       return deferred.promise;
       },

..whereas returning an already resolved promise immediately does not trigger the error:

 afterLaunch: function (exitCode) {
       //return vr.cleanup(exitCode);
      // run npm install q before running this code
       var q = require('q');
       var deferred = q.defer();
       deferred.resolve();
       return deferred.promise;
       },

So I think the error occurs because there is a delayed execution done in afterLaunch (something visualreview-protractor does), which triggers the screenshot-reporter/protractor issue. So while this issue is, in this case, triggered by visualreview-protractor, it's cause is actually somewhere between screenshot-reporter and protractor.

There are some workarounds mentioned in the related protractor discussion, perhaps these might work for you.

kmgilbert100 commented 9 years ago

Was this resolved?

drptbl commented 9 years ago

I'm going to look into it over the weekend and write down the result :+1:

RRMoelker commented 9 years ago

Marking the issue invalid for now. Lets see how the situation develops over at jasmine2-screenshot-reporter issue.