From 9afc061062f8825f4536f4389278f216f6ffea06 Mon Sep 17 00:00:00 2001 From: Georgy Steshin Date: Wed, 8 May 2024 11:56:35 +0300 Subject: [PATCH 1/5] Fixed the types of whileElement to be aligned with the documantation and the reality --- detox/detox.d.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/detox/detox.d.ts b/detox/detox.d.ts index 6adc73128e..a521dfb67e 100644 --- a/detox/detox.d.ts +++ b/detox/detox.d.ts @@ -1279,12 +1279,28 @@ declare global { * Performs the action repeatedly on the element until an expectation is met * @example await waitFor(element(by.text('Item #5'))).toBeVisible().whileElement(by.id('itemsList')).scroll(50, 'down'); */ - whileElement(by: NativeMatcher): NativeElement & WaitFor; + whileElement(by: NativeMatcher): NativeElementWaitableActions & WaitFor; // TODO: not sure about & WaitFor - check if we can chain whileElement multiple times } - interface NativeElementActions { + interface NativeElementWaitableActions { + /** + * Swipes in the provided direction at the provided speed, started from percentage. + * @param speed default: `fast` + * @param percentage screen percentage to swipe; valid input: `[0.0, 1.0]` + * @param optional normalizedStartingPointX X coordinate of swipe starting point, relative to the view width; valid input: `[0.0, 1.0]` + * @param normalizedStartingPointY Y coordinate of swipe starting point, relative to the view height; valid input: `[0.0, 1.0]` + * @example await element(by.id('scrollView')).swipe('down'); + * @example await element(by.id('scrollView')).swipe('down', 'fast'); + * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5); + * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5, 0.2); + * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5, 0.2, 0.5); + */ + swipe(direction: Direction, speed?: Speed, percentage?: number, normalizedStartingPointX?: number, normalizedStartingPointY?: number): Promise; + } + + interface NativeElementActions extends NativeElementWaitableActions{ /** * Simulate tap on an element * @param point relative coordinates to the matched element (the element size could changes on different devices or even when changing the device font size) From bd8cb74af3a9836c3be4ea5c00714092a3c96d11 Mon Sep 17 00:00:00 2001 From: Georgy Steshin Date: Wed, 8 May 2024 12:00:13 +0300 Subject: [PATCH 2/5] Fixed prev commit --- detox/detox.d.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/detox/detox.d.ts b/detox/detox.d.ts index a521dfb67e..54759f434d 100644 --- a/detox/detox.d.ts +++ b/detox/detox.d.ts @@ -1408,20 +1408,6 @@ declare global { */ adjustSliderToPosition(newPosition: number): Promise; - /** - * Swipes in the provided direction at the provided speed, started from percentage. - * @param speed default: `fast` - * @param percentage screen percentage to swipe; valid input: `[0.0, 1.0]` - * @param optional normalizedStartingPointX X coordinate of swipe starting point, relative to the view width; valid input: `[0.0, 1.0]` - * @param normalizedStartingPointY Y coordinate of swipe starting point, relative to the view height; valid input: `[0.0, 1.0]` - * @example await element(by.id('scrollView')).swipe('down'); - * @example await element(by.id('scrollView')).swipe('down', 'fast'); - * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5); - * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5, 0.2); - * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5, 0.2, 0.5); - */ - swipe(direction: Direction, speed?: Speed, percentage?: number, normalizedStartingPointX?: number, normalizedStartingPointY?: number): Promise; - /** * Sets a picker view’s column to the given value. This function supports both date pickers and general picker views. (iOS Only) * Note: When working with date pickers, you should always set an explicit locale when launching your app in order to prevent flakiness from different date and time styles. From 335125a0430087c3ed0ab3287735bdbf09d987a0 Mon Sep 17 00:00:00 2001 From: Georgy Steshin Date: Wed, 8 May 2024 12:06:54 +0300 Subject: [PATCH 3/5] Fixed prev commit --- detox/detox.d.ts | 51 ++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/detox/detox.d.ts b/detox/detox.d.ts index 54759f434d..1427071e8f 100644 --- a/detox/detox.d.ts +++ b/detox/detox.d.ts @@ -1285,19 +1285,22 @@ declare global { } interface NativeElementWaitableActions { + /** - * Swipes in the provided direction at the provided speed, started from percentage. - * @param speed default: `fast` - * @param percentage screen percentage to swipe; valid input: `[0.0, 1.0]` - * @param optional normalizedStartingPointX X coordinate of swipe starting point, relative to the view width; valid input: `[0.0, 1.0]` - * @param normalizedStartingPointY Y coordinate of swipe starting point, relative to the view height; valid input: `[0.0, 1.0]` - * @example await element(by.id('scrollView')).swipe('down'); - * @example await element(by.id('scrollView')).swipe('down', 'fast'); - * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5); - * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5, 0.2); - * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5, 0.2, 0.5); + * Scrolls a given amount of pixels in the provided direction, starting from the provided start positions. + * @param pixels - independent device pixels + * @param direction - left/right/up/down + * @param startPositionX - the X starting scroll position, in percentage; valid input: `[0.0, 1.0]`, `NaN`; default: `NaN`—choose the best value automatically + * @param startPositionY - the Y starting scroll position, in percentage; valid input: `[0.0, 1.0]`, `NaN`; default: `NaN`—choose the best value automatically + * @example await element(by.id('scrollView')).scroll(100, 'down', NaN, 0.85); + * @example await element(by.id('scrollView')).scroll(100, 'up'); */ - swipe(direction: Direction, speed?: Speed, percentage?: number, normalizedStartingPointX?: number, normalizedStartingPointY?: number): Promise; + scroll( + pixels: number, + direction: Direction, + startPositionX?: number, + startPositionY?: number + ): Promise; } interface NativeElementActions extends NativeElementWaitableActions{ @@ -1369,20 +1372,18 @@ declare global { tapReturnKey(): Promise; /** - * Scrolls a given amount of pixels in the provided direction, starting from the provided start positions. - * @param pixels - independent device pixels - * @param direction - left/right/up/down - * @param startPositionX - the X starting scroll position, in percentage; valid input: `[0.0, 1.0]`, `NaN`; default: `NaN`—choose the best value automatically - * @param startPositionY - the Y starting scroll position, in percentage; valid input: `[0.0, 1.0]`, `NaN`; default: `NaN`—choose the best value automatically - * @example await element(by.id('scrollView')).scroll(100, 'down', NaN, 0.85); - * @example await element(by.id('scrollView')).scroll(100, 'up'); - */ - scroll( - pixels: number, - direction: Direction, - startPositionX?: number, - startPositionY?: number - ): Promise; + * Swipes in the provided direction at the provided speed, started from percentage. + * @param speed default: `fast` + * @param percentage screen percentage to swipe; valid input: `[0.0, 1.0]` + * @param optional normalizedStartingPointX X coordinate of swipe starting point, relative to the view width; valid input: `[0.0, 1.0]` + * @param normalizedStartingPointY Y coordinate of swipe starting point, relative to the view height; valid input: `[0.0, 1.0]` + * @example await element(by.id('scrollView')).swipe('down'); + * @example await element(by.id('scrollView')).swipe('down', 'fast'); + * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5); + * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5, 0.2); + * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5, 0.2, 0.5); + */ + swipe(direction: Direction, speed?: Speed, percentage?: number, normalizedStartingPointX?: number, normalizedStartingPointY?: number): Promise; /** * Scroll to index. From 44684450bce6525f6e2b328928047854bf482b55 Mon Sep 17 00:00:00 2001 From: Georgy Steshin Date: Wed, 8 May 2024 12:16:57 +0300 Subject: [PATCH 4/5] Fixed PR --- detox/detox.d.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/detox/detox.d.ts b/detox/detox.d.ts index 1427071e8f..2ef5483ea2 100644 --- a/detox/detox.d.ts +++ b/detox/detox.d.ts @@ -1371,20 +1371,6 @@ declare global { */ tapReturnKey(): Promise; - /** - * Swipes in the provided direction at the provided speed, started from percentage. - * @param speed default: `fast` - * @param percentage screen percentage to swipe; valid input: `[0.0, 1.0]` - * @param optional normalizedStartingPointX X coordinate of swipe starting point, relative to the view width; valid input: `[0.0, 1.0]` - * @param normalizedStartingPointY Y coordinate of swipe starting point, relative to the view height; valid input: `[0.0, 1.0]` - * @example await element(by.id('scrollView')).swipe('down'); - * @example await element(by.id('scrollView')).swipe('down', 'fast'); - * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5); - * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5, 0.2); - * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5, 0.2, 0.5); - */ - swipe(direction: Direction, speed?: Speed, percentage?: number, normalizedStartingPointX?: number, normalizedStartingPointY?: number): Promise; - /** * Scroll to index. * @example await element(by.id('scrollView')).scrollToIndex(10); @@ -1409,6 +1395,20 @@ declare global { */ adjustSliderToPosition(newPosition: number): Promise; + /** + * Swipes in the provided direction at the provided speed, started from percentage. + * @param speed default: `fast` + * @param percentage screen percentage to swipe; valid input: `[0.0, 1.0]` + * @param optional normalizedStartingPointX X coordinate of swipe starting point, relative to the view width; valid input: `[0.0, 1.0]` + * @param normalizedStartingPointY Y coordinate of swipe starting point, relative to the view height; valid input: `[0.0, 1.0]` + * @example await element(by.id('scrollView')).swipe('down'); + * @example await element(by.id('scrollView')).swipe('down', 'fast'); + * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5); + * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5, 0.2); + * @example await element(by.id('scrollView')).swipe('down', 'fast', 0.5, 0.2, 0.5); + */ + swipe(direction: Direction, speed?: Speed, percentage?: number, normalizedStartingPointX?: number, normalizedStartingPointY?: number): Promise; + /** * Sets a picker view’s column to the given value. This function supports both date pickers and general picker views. (iOS Only) * Note: When working with date pickers, you should always set an explicit locale when launching your app in order to prevent flakiness from different date and time styles. From 60d78796b0d84325a6a6865c576ae13f27d20639 Mon Sep 17 00:00:00 2001 From: Georgy Steshin Date: Thu, 9 May 2024 14:47:36 +0300 Subject: [PATCH 5/5] Added tests --- detox/test/types/detox-global-tests.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/detox/test/types/detox-global-tests.ts b/detox/test/types/detox-global-tests.ts index 293cf930cd..efb86e0cb8 100644 --- a/detox/test/types/detox-global-tests.ts +++ b/detox/test/types/detox-global-tests.ts @@ -92,6 +92,14 @@ describe("Test", () => { .whileElement(by.id("ScrollView630")) .scroll(50, "down"); + await waitFor(element(by.text("Text5"))) + .toBeVisible() + .whileElement(by.id("ScrollView630")) + .scroll(50, "down", 0.5, 0.5); + + // @ts-expect-error + await waitFor(element(by.text("Text5"))).toBeVisible().whileElement(by.id("ScrollView630")).tap(); + await web.element(by.web.id("btnSave")).tap(); await web.element(by.web.id("btnSave")).runScript('(el) => el.click()'); const scriptResult = await web.element(by.web.id("btnSave")).runScript(function (el: any, text: string) {