Implement touch gestures actions
t.pullUp,t.pullDown,t.swipeRight,t.swipeLeft.
Which will gracefully degrade to scrolling on devices without touch support.
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:
t.mouseDown(selector, clickOptions || mouseOptions);Should we have thecaretPosoption here like in theclickcommand?
I suppose, yes, because mouseDown leads to the element focusing (and set selection for editable elements)
- Should
t.mouseUphave arguments? If no - it's just raise mouse up event on the position where the cursor is placed right now. Or it's should bet.mouseUp(selector, options). In this case if you callt.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
- 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
- Since we have
mouseDownandmouseUpaction should not we havemoveormoveToaction (how we havehover)? (/cc @VasilyStrelyaev)
What do you think, @inikulin @helen-dikareva ?
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 t.mouseDown(selector, clickOptions);
- t.mouseUp without arguments
- I think we should support native behavior for combination of simple actions
movelooks more attractive
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
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.
Let's call it t.scrollDocument and send offsets to it
@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.
ok, I'll do this
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.
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');
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
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()
})
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);
}
});
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.scrollwhich is often used e.g. in mobile devices. What kind of scroll actions should we have:t.scrollDocumenToTop,t.scrollDocumenToBottomor should it have selector? Should we havet.scrollToElementversion ort.scrollwith offset?
I vote for having selectors. Need to scroll within an element...
This is a rather old issue -- has there been any thought or progress on touch actions?
@leegee
Hello,
Thank you for your interest in this enhancement. We will update this thread once we have any news on this.
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 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.
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, 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