0

I am trying to write a test for a canvas using protractor (Cucumber and chai).

I get a canvas from dom and convert it to base64encoded string and compare with the expected code. This test is working fine on my local (Windows) but not on jenkins (Linux) machine.

Jenkins is generating a bit longer and different base64 code of my canvas.

What can be the issue as I have no clue further to investigate and if its character set issue than how can I fix it?

Edit: Its not a duplicate I am trying find a solution in order to fix the encoding issues of canvas

  await browser.executeScript("return document.querySelector('#testCard canvas').toDataURL(").then(async function (result) {
            await expect(result).to.deep.equal(expectedImageCode);

        });

or is there any alternative of toDataURL function?

Mishi
  • 628
  • 4
  • 16
  • 40

1 Answers1

0

This comes down to different strategies used by toDataURL implementations when generating images from a canvas (such as compression level, metadata, or even the image format itself), as well as subtleties on how browsers implement the HTML5 canvas implementations, whether across versions, operating systems, or otherwise (and these subtleties may arise due to differences in underlying graphics APIs, for example). For these reasons, an HTML5 canvas's toDataURL output is not guaranteed to be bit-for-bit identical even if the same HTML canvas operations are used.

To investigate the differences, you will need to decode the base64 encoding (which comes after "base64," in data URLs) into a binary data file (which will generally be in the form of an image file). If the two binary data files are identical, you can just do an equality check of the binary data files. Otherwise, if the differences (at a pixel level) are small enough, a fuzzy match of the images' pixel data can be done. Fuzzy matching, though, is considerably more involved than a simple equality test of the binary data files, and is too complicated to discuss in this answer.

Peter O.
  • 32,158
  • 14
  • 82
  • 96