testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Implement touch gestures actions

Open inikulin opened this issue 10 years ago • 28 comments

  • t.pullUp,
  • t.pullDown,
  • t.swipeRight,
  • t.swipeLeft.

Which will gracefully degrade to scrolling on devices without touch support.

inikulin avatar May 11 '16 10:05 inikulin

Let's clarify new actions api and it's behavior

t.scroll(selector, offsetOptions); // offsetOptions = { offsetX, offsetY }
//----------------
t.mouseDown(selector, clickOptions); // clickOptions = { modifiers, caretPos, offsetX, offsetY }
//or
t.mouseDown(selector, mouseOptions); // mouseOptions = { modifiers, offsetX, offsetY }
//----------------
t.rightMouseDown(selector, clickOptions);
//----------------
t.mouseUp();
t.rightMouseUp();
//or
t.mouseUp(selector, clickOptions);
t.rightMouseUp(selector, clickOptions);

The things to discuss:

  1. t.mouseDown(selector, clickOptions || mouseOptions); Should we have the caretPos option here like in the click command?

I suppose, yes, because mouseDown leads to the element focusing (and set selection for editable elements)

  1. Should t.mouseUp have arguments? If no - it's just raise mouse up event on the position where the cursor is placed right now. Or it's should be t.mouseUp(selector, options). In this case if you call t.mouseDown(element1).mouseUp(element2) - it means
- mouse down on element1
- move to element2
- mouse up on element2

I'm not sure what we should choose here, but I am inclined to choose the first to make action more simple

  1. Should we emulate native behavior when a combination of simple actions is used? For example if you call t.mouseDown(input1, { /* someOffsets */ }).hover(input1, { /* otherOffsets*/ }.mouseUp()) should we change a selection of the input (in other words - execute it like a select action)?

I suppose, yes

  1. Since we have mouseDown and mouseUp action should not we have move or moveTo action (how we have hover)? (/cc @VasilyStrelyaev)

What do you think, @inikulin @helen-dikareva ?

AlexanderMoskovkin avatar May 12 '16 09:05 AlexanderMoskovkin

Let's postpone mouse events discussion for now, since I think they are not quite important and we don't need them in MVP. The more important is t.scroll which is often used e.g. in mobile devices. What kind of scroll actions should we have: t.scrollDocumenToTop,t.scrollDocumenToBottom or should it have selector? Should we have t.scrollToElement version or t.scroll with offset?

inikulin avatar May 12 '16 09:05 inikulin

  1. I vote for t.mouseDown(selector, clickOptions);
  2. t.mouseUp without arguments
  3. I think we should support native behavior for combination of simple actions
  4. move looks more attractive

helen-dikareva avatar May 12 '16 09:05 helen-dikareva

I think t.scrollDocumenToTop,t.scrollDocumenToBottom insufficiently reusable variants. I think we should have command t.scrollToElement because t.scroll looks like we should scroll element itself

helen-dikareva avatar May 12 '16 10:05 helen-dikareva

I think t.scrollDocumenToTop,t.scrollDocumenToBottom insufficiently reusable variants.

I don't agree. The most common scenario people asked for is to scroll down the document e.g. to load additional comments/items in live feed.

inikulin avatar May 12 '16 10:05 inikulin

Let's call it t.scrollDocument and send offsets to it

helen-dikareva avatar May 12 '16 10:05 helen-dikareva

@AlexanderMoskovkin PivotGrid team expressed a high interest in scrolling gestures. I guess we can plan it for Sprint#2. Before figuring out final API it's worth discuss it with other teams and maybe test prototypes during development with them as well.

inikulin avatar Oct 19 '16 09:10 inikulin

ok, I'll do this

AlexanderMoskovkin avatar Oct 19 '16 10:10 AlexanderMoskovkin

Has this been implemented? I'm running into issues where tests fail because of an overlapping element has a parent who has 'position':'fixed', and one way I could work around this would be to use t.pullDown to the bottom of the page manually, instead of relying on testCafe to find it automatically.

Dtphelan1 avatar Oct 05 '17 17:10 Dtphelan1

Hi @Dtphelan1,

It's not implemented yet.

We've discussed such issue in the #1057 issue. Usually you can use another workaround. Before an action on the target element call the hover action for this element with the offsetY property, for example:

await t
    .hover('#target', { offsetY: 100 })
    .click('#target');

AlexanderMoskovkin avatar Oct 05 '17 17:10 AlexanderMoskovkin

Hello guys,

I'm working with Testcafe API for like a month. I've just encountered the issue that Testcafe cannot click on pagination number at the bottom of our application because the element is in overflow and testcafe shows error that the element is not visible. t.hover doesn't work for me. And t.pressKey('end') also not. I need this scrolling functionality to be implemented.

Also I noticed that the scrolling acts weird. If I scroll down at the bottom, it immediately jumps back up. Basically I need to spam the scrolling wheel down while Testcafe waits for the element to appear and then it usually works. Therefore, I'm not sure how successful would the t.pullDown action would be, but hopefully it would be enough.

Kinds regards, Libor

AlisarDius avatar Nov 27 '18 09:11 AlisarDius

I've been using ClientFunction wrapped in a helper function that I import in my tests. The whole snippet looks like this

export const scroll = ClientFunction((x, y) => window.scrollBy(x, y))

Which i will letter use like so for vertical scrolling:

test('something that needs to scroll', await t => {
....
await scroll(0, divHeight);
expect(....).ok()
})

talentedunicorn avatar Nov 29 '18 07:11 talentedunicorn

To add to @talentedunicorn the following function can do anything that is supported by scrollBy

export const scroll = ClientFunction((selector: string, options: ScrollToOptions) => {
  const elem = document.querySelector(selector);
  if (elem) {
    elem.scrollBy(options);
  }
});

dlangerenken avatar Jan 19 '19 02:01 dlangerenken

Let's postpone mouse events discussion for now, since I think they are not quite important and we don't need them in MVP. The more important is t.scroll which is often used e.g. in mobile devices. What kind of scroll actions should we have: t.scrollDocumenToTop,t.scrollDocumenToBottom or should it have selector? Should we have t.scrollToElement version or t.scroll with offset?

I vote for having selectors. Need to scroll within an element...

caroe233 avatar Jul 24 '19 12:07 caroe233

This is a rather old issue -- has there been any thought or progress on touch actions?

leegee avatar Oct 16 '19 14:10 leegee

@leegee

Hello,

Thank you for your interest in this enhancement. We will update this thread once we have any news on this.

Farfurix avatar Oct 17 '19 07:10 Farfurix

I opened the issue referenced above. Many other automated testing frame works allow for explicit scrolling. On some apps scrolling may cause things to happen on the web page that need to be tested for example.

Also it is sometimes nice to offset the default scrolling behavior of testCafe, so that it scrolls a little more than the minimum required amount. I know that any element that is interacted with is/should be automatically scrolled to, but what is the reservation with giving more power to the user in this regard?

switch201 avatar Oct 18 '19 14:10 switch201

@switch201 Thanks for your opinion. We greatly appreciate it. This issue is still opened, which means that we are going to extend Actions API in the future, however, we cannot give any estimates.

AlexKamaev avatar Oct 21 '19 07:10 AlexKamaev

Still waiting for t.scroll() We have a virtual scroller on an app page. This would come in very handy since a targeted element does not exist until the scroll is activated and therefore can't be reached by the current testcafe targeting scheme

hitautodestruct avatar Nov 27 '19 10:11 hitautodestruct

@hitautodestruct, you can use t.hover for scrolling. TestCafe scrolls your page and containers to a point defined by the offsetX and offsetY options: https://devexpress.github.io/testcafe/documentation/test-api/actions/hover.html

AndreyBelym avatar Dec 02 '19 17:12 AndreyBelym