question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to draaw a line on canvas

See original GitHub issue

Context:

  1. I want to test a signature canvas field
  2. So i want to draw a signature and then validate that signature is displayed on the canvas.
  3. Right now i cannot even draw a proper line , so wanted to understand how action class works in protractor before i go for the actual implementation.

It would be great if someone could help me

I am trying to draw a line on the canvas : https://vrobbi-nodedrawing.herokuapp.com/ at a particular location say on the right side like:

enter image description here

I tried too many ways nothing is working below is the code that draws atleast something on the screen:

await browser.get("https://vrobbi-nodedrawing.herokuapp.com/");

await browser.sleep(5000);


let canvas = $('canvas#paper')
await canvas.click();

await browser.actions().
mouseMove(canvas, {
        x: 120,
        y: 100
    }).mouseDown().mouseMove(canvas, {
        x: 120,
        y: 200
    })
    .perform();

But i am getting below output and not a vertical line as expected:

enter image description here

Also:

I checked the canvas size using chrome inspect tool and it shows : 1922*939

enter image description here

But when i give move to element .mouseMove( canvas, { x: 50, y: 500 }) i am getting below error:

> Failed: move target out of bounds
>       (Session info: chrome=83.0.4103.61)
>     Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
>     System info: host: 'DESKTOP-U2HJMCV', ip: '192.168.254.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0',
> java.version: '12.0.1'
>     Driver info: driver.version: unknown   Stack:
>     MoveTargetOutOfBoundsError: move target out of bounds
  1. Could someone help me in understanding how to calculate offset , why the exception is thrown
  2. how to find offset inside an element (Here canvas)
  3. How draw a straight line

Bug report

  • Node Version: v10.15.3
  • Protractor Version: Version 5.4.3
  • Browser(s): chrome
  • Operating System and Version Windows 10

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
Fuun347commented, Jun 3, 2020

@praveendvd Actually I even got confused. You are right. It does say if an offset is provided it will be based on the top left corner of the element. But I don’t think that’s correct. The documentation might be outdated. Not too sure.

1reaction
praveendvdcommented, Jun 2, 2020

Thanks for that it works

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML canvas lineTo() Method - W3Schools
The lineTo() method adds a new point and creates a line TO that point FROM the last specified point in the canvas (this...
Read more >
HTML5 Canvas Line - w3resource
To draw a line using HTML5 Canvas is simple, just like draw a line on a paper, define a path, and then fill...
Read more >
CanvasRenderingContext2D.lineTo() - Web APIs | MDN
To draw the path onto a canvas, you can use the fill() or stroke() methods ... This example draws a straight line using...
Read more >
How to Draw a Line in JavaScript
First, create a new line by calling the beginPath() method. · Second, move the drawing cursor to the point (x,y) without drawing a...
Read more >
How to draw lines on canvas using JavaScript - Educative.io
Below are the steps to draw a line on the canvas: Use the beginPath() method to start a new path. Use the moveTo(x,y)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found