testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Mouse down, mouse up behaviour

Open PierreRott opened this issue 8 years ago • 21 comments

Are you requesting a feature or reporting a bug?

Feature request

What is the current behavior?

There is not possible to simulate long click action in testcafe environment, which means it is not possible to measure the time between mouse down and mouse up.

What is the expected behavior?

To simulate long click action as it is in reality, thus it would be possible to measure the total time between mouse down and mouse up.

How would you reproduce the current behavior (if this is a bug)?

Provide the test code and the tested page URL (if applicable)

Tested page URL:

Test code


Specify your

  • operating system: Windows7
  • testcafe version: 0.18.6
  • node.js version: 8.9.3

PierreRott avatar Jan 18 '18 13:01 PierreRott

We would need such functionality as well. It might be good to have either possibility to do mousedown/mouseup in separate or, maybe even better, to add click options with the delay between mousedown/mouseup.

This option would be also useful in D&D functionality. I know use cases, used especially on touch devices, when Drag action is started some time after initial touchstart event to distinguish scroll start vs drag start.

palpatine1991 avatar Jan 18 '18 13:01 palpatine1991

Hi,

Thanks for the proposal. Meanwhile, If you need to increase a delay between mousedown and mouseup try to set the speed option of the click action.

AlexanderMoskovkin avatar Jan 22 '18 06:01 AlexanderMoskovkin

Thank you for your prompt reply. Unfortunately, the solution you recommend is not sufficient. I managed to simulate long press action by drag feature. The smallest value I was able to measure on the button was 0 seconds, the biggest one was 1 second. If I wanted to measure for example 5 seconds I wouldn't be able to do so. Anyway thank you for your answer and I will look forward that this feature will be possibly added to testcafe in the future.

PierreRott avatar Jan 22 '18 12:01 PierreRott

I am looking for similar kind of functionality. Was going to put it as a new issue for extending the DragElement action, but I think having phases of the interaction (see below) split out would be useful.

So my example is trying to test first-draft - an online interactive drawing/annotation app. An example of the interactions I need to be able to test (more at https://gitlab.com/MeldCE/first-draft/issues/59#tool-use) is l-mousedown, mousemove, shiftdown, mousemove, shiftup, mousemove, l-mouseup

While is probably quite an extreme case of needing to test interactions, it could be useful other places, eg testing a map fetches tiles as you pan around the map.

Having the ability to run assertions part way through an interaction would be super useful (eg dragging a file onto a div to ensure the drop target is showing) and I think this would only be possible if the individual phases were available (eg, mousedown, mouseup, mousemove). Doing this (with the addition of an interaction pause action) would also help solve #2803 and #1374.

There is also a case for doing the same (or making sure they are included) for touch and pointer events.

Maybe this would be too complicated and could be a separate module once #1535 is completed

bytesnz avatar Apr 24 '19 15:04 bytesnz

@bytesnz Thank you for an interesting suggestion. While we do not have plans to implement something similar in the near future, we will take your opinion into account when planning our future releases. BTW, I think it's better to create a separate feature request for this.

AlexKamaev avatar Apr 25 '19 08:04 AlexKamaev

Is there a workaround available? I need to migrate the following from puppeteer to testcafe.

export async function drag([fromLeft, fromTop], [toLeft, toTop], page) {
  await page.mouse.move(fromLeft, fromTop, { steps: 10 })
  await page.mouse.down()
  await page.mouse.move(toLeft, toTop, { steps: 10 })
  await page.mouse.up()
}

aaronshaf avatar Apr 30 '20 18:04 aaronshaf

Thank you for creating a separate issue. Let's continue discussing your inquiry in the context of that thread: #5036.

AlexSkorkin avatar May 01 '20 05:05 AlexSkorkin

Any luck @aaronshaf?

I'm evaluating TestCafe and don't think I can use it without this feature.

Is it something you'd like the community to build out for you?

seanpoulter avatar May 20 '20 05:05 seanpoulter

@seanpoulter No luck yet. Would love a solution.

aaronshaf avatar May 20 '20 19:05 aaronshaf

Are you requesting a feature or reporting a bug?

Feature request

What is the current behavior?

There is not possible to simulate long click action in testcafe environment, which means it is not possible to measure the time between mouse down and mouse up.

What is the expected behavior?

To simulate long click action as it is in reality, thus it would be possible to measure the total time between mouse down and mouse up.

How would you reproduce the current behavior (if this is a bug)?

Provide the test code and the tested page URL (if applicable)

Tested page URL:

Test code

Specify your

  • operating system: Windows7
  • testcafe version: 0.18.6
  • node.js version: 8.9.3

Hi Anyone know solution for this issue?

Hi,

Thanks for the proposal. Meanwhile, If you need to increase a delay between mousedown and mouseup try to set the speed option of the click action.

Speed options is not helping..do u have any other option?

LathaSan avatar Jan 19 '21 11:01 LathaSan

Hello @LathaSan,

We don't have another workaround at the moment. If you share details about your case, we can try to adjust the approach with setting the speed option of the click action or suggest something else.

wentwrong avatar Jan 21 '21 08:01 wentwrong

Hello @LathaSan,

We don't have another workaround at the moment. If you share details about your case, we can try to adjust the approach with setting the speed option of the click action or suggest something else.

Hello @wentwrong I have an filter icon in footer, and I want to click that icon for 2 or 5 seconds , then it will clear all the filters in the filter panel and the colour of footer icon also changed. Need to validate the color change. But am not able to long press that icon

LathaSan avatar Feb 23 '21 14:02 LathaSan

@LathaSan It's difficult to determine why the workaround with setting the speed option doesn't work in this case. Can you give us an example of such a page, so we will be able to test it on our side and find another workaround?

wentwrong avatar Feb 26 '21 08:02 wentwrong

@LathaSan It's difficult to determine why the workaround with setting the speed option doesn't work in this case. Can you give us an example of such a page, so we will be able to test it on our side and find another workaround?

Hi @wentwrong, For touch gestures, we use touchswipe library. In that we use long tap event to stimulate long press action. Demo link is 'http://labs.rampinteractive.co.uk/touchSwipe/demos/Tap_vs_swipe.html'

LathaSan avatar Mar 03 '21 14:03 LathaSan

Hi @LathaSan, I can confirm that the workaround with lowering the speed option of the t.click action doesn't apply to your case - in the demo you shared, it leads to raising the tap event (instead of the expected long tap). But the workaround with the t.dragToElement action seems to work:

import { Selector } from 'testcafe';

fixture `Emulating long tap`
    .page `http://labs.rampinteractive.co.uk/touchSwipe/demos/Tap_vs_swipe.html`;

test('Emulate long tap via workaround', async t => {
    const testPanel = Selector('#test');

    await t.dragToElement(testPanel, testPanel, { speed: 0.05 });

    await t
        .expect(Selector('#textText').innerText)
        .eql('You tapped 0, double tapped 0 and long tapped 1 times on test')
});

Please check it and let us know if it meets your needs.

wentwrong avatar Mar 04 '21 08:03 wentwrong

Hi @LathaSan, I can confirm that the workaround with lowering the speed option of the t.click action doesn't apply to your case - in the demo you shared, it leads to raising the tap event (instead of the expected long tap). But the workaround with the t.dragToElement action seems to work:

import { Selector } from 'testcafe';

fixture `Emulating long tap`
    .page `http://labs.rampinteractive.co.uk/touchSwipe/demos/Tap_vs_swipe.html`;

test('Emulate long tap via workaround', async t => {
    const testPanel = Selector('#test');

    await t.dragToElement(testPanel, testPanel, { speed: 0.05 });

    await t
        .expect(Selector('#textText').innerText)
        .eql('You tapped 0, double tapped 0 and long tapped 1 times on test')
});

Please check it and let us know if it meets your needs.

Hi @wentwrong,

Thanks for the workaround. It works, thanks a lot for your support.

LathaSan avatar Mar 04 '21 10:03 LathaSan

Hi @LathaSan, I can confirm that the workaround with lowering the speed option of the t.click action doesn't apply to your case - in the demo you shared, it leads to raising the tap event (instead of the expected long tap). But the workaround with the t.dragToElement action seems to work:

import { Selector } from 'testcafe';

fixture `Emulating long tap`
    .page `http://labs.rampinteractive.co.uk/touchSwipe/demos/Tap_vs_swipe.html`;

test('Emulate long tap via workaround', async t => {
    const testPanel = Selector('#test');

    await t.dragToElement(testPanel, testPanel, { speed: 0.05 });

    await t
        .expect(Selector('#textText').innerText)
        .eql('You tapped 0, double tapped 0 and long tapped 1 times on test')
});

Please check it and let us know if it meets your needs.

Hi @wentwrong,

Thanks for the workaround. It works, thanks a lot for your support.

Hi @wentwrong,

One more issue on the above workaround, I set the speed to 0.01, then only it worked for me. In some cases, when I want to do long press for longer time for eg 5 to 7 secs. Even though, I set the speed to 0.01, it is not clicking for more than 3 to 4 secs. Do you have any workaround for this?

LathaSan avatar Mar 05 '21 04:03 LathaSan

@LathaSan, The minimum value of the speed option is 0.01, so the only way I see is monkey-patching TestCafe's emulation functions in order to wait for a custom delay after the mousedown event is raised. See the following test code with the adapted workaround posted in another issue (https://github.com/DevExpress/testcafe/issues/2803#issuecomment-522637502):

import { Selector, ClientFunction } from 'testcafe';

fixture `Emulating long tap`
    .page `http://labs.rampinteractive.co.uk/touchSwipe/demos/Tap_vs_swipe.html`;

// HACK: Define functions that monkey-patch TestCafe internals
const enableMouseDownDelay = ClientFunction(() => {
    const proto     = window['%testCafeAutomation%'].DragToElement.prototype.constructor.prototype
    const mousedown = proto._mousedown;

    proto._mousedown = function (...args) {
        let result;

        return mousedown
            .apply(this, args)
            .then(r => result = r)
            .then(() => new Promise(r => setTimeout(r, window.mouseDownDelay || 0)))
            .then(() => result);
    }
});

const setMouseDownDelay = ClientFunction(ms => window.mouseDownDelay = ms);
// End of function definitions

test('Emulate long tap via workaround', async t => {
    // HACK: Call patching functions to enable delays during a test

    // Can be called only once per test
    await enableMouseDownDelay();

    // Can be called multiple times per test
    await setMouseDownDelay(5000);

    const testPanel = Selector('#test');

    await t.dragToElement(testPanel, testPanel, { speed: 0.01 });

    await t
        .expect(Selector('#textText').innerText)
        .eql('You tapped 0, double tapped 0 and long tapped 1 times on test')
});

wentwrong avatar Mar 05 '21 08:03 wentwrong

@LathaSan, The minimum value of the speed option is 0.01, so the only way I see is monkey-patching TestCafe's emulation functions in order to wait for a custom delay after the mousedown event is raised. See the following test code with the adapted workaround posted in another issue (#2803 (comment)):

import { Selector, ClientFunction } from 'testcafe';

fixture `Emulating long tap`
    .page `http://labs.rampinteractive.co.uk/touchSwipe/demos/Tap_vs_swipe.html`;

// HACK: Define functions that monkey-patch TestCafe internals
const enableMouseDownDelay = ClientFunction(() => {
    const proto     = window['%testCafeAutomation%'].DragToElement.prototype.constructor.prototype
    const mousedown = proto._mousedown;

    proto._mousedown = function (...args) {
        let result;

        return mousedown
            .apply(this, args)
            .then(r => result = r)
            .then(() => new Promise(r => setTimeout(r, window.mouseDownDelay || 0)))
            .then(() => result);
    }
});

const setMouseDownDelay = ClientFunction(ms => window.mouseDownDelay = ms);
// End of function definitions

test('Emulate long tap via workaround', async t => {
    // HACK: Call patching functions to enable delays during a test

    // Can be called only once per test
    await enableMouseDownDelay();

    // Can be called multiple times per test
    await setMouseDownDelay(5000);

    const testPanel = Selector('#test');

    await t.dragToElement(testPanel, testPanel, { speed: 0.01 });

    await t
        .expect(Selector('#textText').innerText)
        .eql('You tapped 0, double tapped 0 and long tapped 1 times on test')
});

Hi @wentwrong, Many Thanks. The above solution worked for me.

LathaSan avatar Mar 09 '21 16:03 LathaSan

Thank you for your feedback. We are happy that our solution was helpful.

viktoria2506 avatar Mar 10 '21 08:03 viktoria2506