1

Using Karate testcase scenario (feature) I need to interact with to simulate signature to be written in it.

<canvas width="1292" height="596" style="width: 100%; height: 100%; touch-action: none;"></canvas>

I have tried to use JS to draw some element, but it not identified as signature. I have used this:

* script('document.getElementsByTagName("canvas")[0].getContext("2d").fillStyle = "green"')
* script('document.getElementsByTagName("canvas")[0].getContext("2d").fillRect(10, 10, 150, 100)')

It worked, but the paint was not identified as signature. I have different idea - to use path/move to/fill in javascript:

* script('document.getElementsByTagName("canvas")[0].getContext("2d").fillStyle = "green"')
* script('document.getElementsByTagName("canvas")[0].getContext("2d").beginPath()')
* script('document.getElementsByTagName("canvas")[0].getContext("2d").moveTo(200, 200)')
* script('document.getElementsByTagName("canvas")[0].getContext("2d").fill()')

Using this, the test has passed (these lines passed) but in reality the line has not been written into the canvas...

Do you have any idea how to simulate this? Or is there another way how to do it differently? My aim is to simulate hand-written signature in .

Thank you!

Radim Bukovský
  • 337
  • 2
  • 11

1 Answers1

1

My sincere opinion is to drop this test and focus on the other parts of the application that you can test. It may not be worth it. Also consider asking the developer team to disable this part of the UI flow in test-mode, this is a perfectly legitimate test-strategy, many teams do this for CAPTCHA-s for example.

It may be possible if you use the mouse() API which supports click and drag to some extent: https://github.com/intuit/karate/tree/master/karate-core#mouse

But not an area you will get much help on the internet.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Thank you for the answer! I used " * mouse(250,250).down().up() " and it worked well (it created dot on canvas and it was good simulation of hand-writing - that was sufficient). I have also tried to do some line using: * mouse(250,250).go().down().move(300, 300).up() , but the line is not created (again only dot). Have I used wrong syntax? But the main problem is solved. – Radim Bukovský Mar 17 '21 at 23:08