The way to check our canvas in the transporter is as follows:
We set the "well-known" base64 image line, which represents what we want our canvas to be after we draw it. Then we use browser.executeScript to get the dataUrl of the canvas. Then we compare the line with the line and indicate the correctness of the picture.
var base64ImageString = "data:image/png;base64,iVBORw0KGgoAA...snipped for brevity"; describe("The Canvas", function () { browser.get('/#')); it("should contain the right drawings", function(){ browser.executeScript("return document.getElementsByTagName('canvas')[0].toDataURL()").then(function (result) { expect(result).toBe(base64ImageString); }); }); });
Works like a champion for us. We are experimenting with getting a Uint8ClampedArray to see if this is easier, but so far this method is different, except for the thin gotcha.
In our experience, the line of the image that we return from the toDataUrl method represents only the visible area of ββthe canvas β not the entire canvas . This is good enough for us, but your mileage may vary. This is also why we are experimenting with your byte array, because it allows you to specify a specific area X x Y on the canvas.
Scott Davis
source share