wswebcreation / protractor-image-comparison

npm-module to compare images with protractor
86 stars 38 forks source link

Argument should be a buffer #44

Closed sepa-joe closed 6 years ago

sepa-joe commented 6 years ago

Not sure this is entirely something to do with the image comparison, but am raising it here for first consideration.

I have some code which looks to do a screenshot comparison. I use the same code on multiple tests. On a number of these, the test fails with "argument should be a buffer"

I can't see why this is causing an issue, visually the code is executing and navigating with no issues (the navigation code works fine for other tests) - anyone see anything in the stacktrace to help?

  TypeError: argument should be a Buffer
      at Buffer.copy (buffer.js:600:18)
      at Function.PNG.bitblt (C:\Users\Joseph.Adams\Desktop\protractor\node_modules\pngjs-image\node_modules\pngjs\lib\png.js:129:14)
      at exports.PNG.PNG.bitblt (C:\Users\Joseph.Adams\Desktop\protractor\node_modules\pngjs-image\node_modules\pngjs\lib\png.js:140:7)
      at protractorImageComparison._saveFullScreenshot (C:\Users\Joseph.Adams\Desktop\protractor\node_modules\protractor-image-comparison\index.js:176:57)
      at _scrollToVerticalCoordinateAndWait.then.then.then.then.then (C:\Users\Joseph.Adams\Desktop\protractor\node_modules\protractor-image-comparison\index.js:851:33)
      at ManagedPromise.invokeCallback_ (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1376:14)
      at TaskQueue.execute_ (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3084:14)
      at TaskQueue.executeNext_ (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3067:27)
      at asyncRun (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2927:27)
      at C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:668:7
  From: Task: Run it("should save the screen") in control flow
      at UserContext.<anonymous> (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:94:19)
      at C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:64:48
      at ControlFlow.emit (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\events.js:62:21)
      at ControlFlow.shutdown_ (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2674:10)
      at shutdownTask_.MicroTask (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2599:53)
  From asynchronous test:
  Error
      at Suite.<anonymous> (C:\Users\Joseph.Adams\Desktop\protractor\imageTests\question_4-image.js:32:1)
      at Object.<anonymous> (C:\Users\Joseph.Adams\Desktop\protractor\imageTests\question_4-image.js:17:1)
      at Module._compile (module.js:635:30)
      at Object.Module._extensions..js (module.js:646:10)
      at Module.load (module.js:554:32)
      at tryModuleLoad (module.js:497:12)
wswebcreation commented 6 years ago

Hi @sepa-joe

Sorry for my late reaction. When do you experience this problem? Is this random, or in specific cases? Can you also share some code you use and your dependencies including the versions (like nodejs, protractor, jasmine / mocha and so on)?

Tnx in advance

sepa-joe commented 6 years ago

@wswebcreation I can get this to occur on a fairly regular basis (on the application I am testing) - however it makes no sense. The code I am using is:

'use strict';
var path = require('path');

var navFile = path.normalize('../functions/navigation/navigation.js');
var navi    = require(navFile);

const protractorImageComparison = require('protractor-image-comparison');

const screenshotPath = path.resolve(__dirname, `actual\\`); 
const differencePath = path.resolve(__dirname, `diff\\`); 
const helpers        = require('../helpers'); 

const exampleFullPage = 'question_3_baseline';

var startBtn = '/html[1]/body[1]/section[1]/app-root[1]/app-pay-only[1]/div[2]/div[1]/div[1]/div[1]/div[1]/button[1]';
var noRadio  = '/html[1]/body[1]/section[1]/app-root[1]/app-pay-only[1]/div[2]/div[1]/div[1]/div[1]/label[2]/input[1]';
var yesRadio = '/html[1]/body[1]/section[1]/app-root[1]/app-pay-only[1]/div[2]/div[1]/div[1]/div[1]/label[1]/input[1]';                
var nextBtn  = '/html[1]/body[1]/section[1]/app-root[1]/app-pay-only[1]/div[2]/div[1]/div[1]/button[1]';

describe('Question 03 screenshot', function() {

    beforeEach(function() {
        browser.waitForAngularEnabled(false); 
        browser.protractorImageComparison = new protractorImageComparison({ 
        baselineFolder: './data/baseline/imageTests/', 
        screenshotPath: './data/screenshots/imageTests/' 
    }); 

    browser.get(browser.baseUrl)
        .then(() => browser.sleep(0));
    browser.driver.manage().window().maximize();

   });

    it('should save question 3 - selected "no" ', () => { 

        navi.gotoQuestion3();
        var fileName = exampleFullPage + '_selected_no';

        // click no
        element(by.xpath(noRadio)).click();

        expect(browser.protractorImageComparison.checkFullPageScreen(fileName)).toEqual(0);
    });

});

The confusing thing is I use the exact same code for other parts and this works. And when I watch the application I can see pages being loaded as expected. I have made the navigation code into its own function - this is used in several other tests and again this works.

Node version: v8.9.1 protractor: 5.2.0 jasmine should be v2

wswebcreation commented 6 years ago

Hi @sepa-joe

Tnx for the info, is this always on the same testcase or on a random bases? Based om the log it looks like the screenshot array has not been filled. Can you provide a example repo in which I can debug it?

mikedidomizio commented 6 years ago

I ran into the same issue. Here is some information I can provide:

I can't help with a code example at this time. I'll try and help otherwise if I can. Is there something in imageOutput.getImage() I can look into to help?

wswebcreation commented 6 years ago

@mikedidomizio

Hmm, that's useful info. I hope to check it the coming days but I'm pretty busy. I'll post the results here

sepa-joe commented 6 years ago

Sorry I've not been of any help on this - due to a chance in direction I've had to stop using protractor (and so haven't been able to reply.)

I'm going to try and make time to help if I can

JochenDiekenbrock commented 6 years ago

I just created a pull request that fixed this issue for me. #54

wswebcreation commented 6 years ago

I've released version 1.6.1m see https://github.com/wswebcreation/protractor-image-comparison/pull/54 tnx to @JochenDiekenbrock

Will close this for now. If there are still problem please let me know

JochenDiekenbrock commented 6 years ago

Thanks @wswebcreation