From aa11bb97dc7ed9b55c9146f20fda69abb65a32d4 Mon Sep 17 00:00:00 2001 From: pera Date: Tue, 22 Oct 2019 19:19:28 -0300 Subject: [PATCH] Update types to match Detox 14.5.0 (#39210) * Update types to Detox 14.5.0 * Fixes... --- types/detox/index.d.ts | 180 ++++++++++++++++++++++++++++++----------- 1 file changed, 132 insertions(+), 48 deletions(-) diff --git a/types/detox/index.d.ts b/types/detox/index.d.ts index ad9f864102..85c393be11 100644 --- a/types/detox/index.d.ts +++ b/types/detox/index.d.ts @@ -1,13 +1,13 @@ -// Type definitions for detox 12.8 +// Type definitions for detox 14.5 // Project: https://github.com/wix/detox // Definitions by: Tareq El-Masri // Steve Chun // Hammad Jutt +// pera // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - declare global { - const detox: Detox.Detox; const device: Detox.Device; + const detox: Detox.Detox; const element: Detox.Element; const waitFor: Detox.WaitFor; const expect: Detox.Expect>; @@ -135,34 +135,88 @@ declare global { setURLBlacklist(urls: string[]): Promise; /** * Enable EarlGrey's synchronization mechanism (enabled by default). This is being reset on every new instance of the app. - * @example await device.enableSynchronization(); + * @example + * await device.enableSynchronization(); */ enableSynchronization(): Promise; /** * Disable EarlGrey's synchronization mechanism (enabled by default) This is being reset on every new instance of the app. - * @example await device.disableSynchronization(); + * @example + * await device.disableSynchronization(); */ disableSynchronization(): Promise; /** * Resets the Simulator to clean state (like the Simulator > Reset Content and Settings... menu item), especially removing previously set permissions. - * @example await device.resetContentAndSettings(); + * @example + * await device.resetContentAndSettings(); */ resetContentAndSettings(): Promise; /** * Returns the current device, ios or android. - * @example if (device.getPlatform() === 'ios') { + * @example + * if (device.getPlatform() === 'ios') { * await expect(loopSwitch).toHaveValue('1'); * } */ - getPlatform(): "ios" | "android"; + getPlatform(): 'ios' | 'android'; /** - * Simulate press back button (Android Only) + * Takes a screenshot on the device and schedules putting it to the artifacts folder upon completion of the current test. + * @param text + * @example + * await device.takeScreenshot('tap on menu'); + * + * • If the test passes, the screenshot will be put to /✓ Menu items should have Logout/tap on menu.png. + * • If the test fails, the screenshot will be put to /✗ Menu items should have Logout/tap on menu.png. + * + * > NOTE: At the moment, taking screenshots on-demand in --take-screenshots failing mode is not yet implemented. */ - pressBack(): Promise; + takeScreenShot(name: string): Promise; /** * Simulate shake (iOS Only) */ shake(): Promise; + /** + * Toggles device enrollment in biometric auth (TouchID or FaceID) (iOS Only) + * @example + * await device.setBiometricEnrollment(true); + * // or + * await device.setBiometricEnrollment(false); + */ + setBiometricEnrollment(enabled: true): Promise; + /** + * Simulates the success of a face match via FaceID (iOS Only) + */ + matchFace(): Promise; + /** + * Simulates the failure of a face match via FaceID (iOS Only) + */ + unmatchFace(): Promise; + /** + * Simulates the success of a finger match via TouchID (iOS Only) + */ + matchFinger(): Promise; + /** + * Simulates the failure of a finger match via TouchID (iOS Only) + */ + unmatchFinger(): Promise; + /** + * Clears the simulator keychain (iOS Only) + */ + clearKeychain(): Promise; + /** + * Simulate press back button (Android Only) + * @example + * await device.pressBack(); + */ + pressBack(): Promise; + /** + * (Android Only) + * Exposes UiAutomator's UiDevice API (https://developer.android.com/reference/android/support/test/uiautomator/UiDevice). + * This is not a part of the official Detox API, + * it may break and change whenever an update to UiDevice or UiAutomator gradle dependencies ('androidx.test.uiautomator:uiautomator') is introduced. + * UIDevice's autogenerated code reference: https://github.com/wix/Detox/blob/master/detox/src/android/espressoapi/UIDevice.js + */ + getUiDevice(): Promise; } type DetoxAny = Element & Actions & WaitFor; @@ -177,6 +231,7 @@ declare global { */ atIndex(index: number): DetoxAny; } + interface Matchers { (by: Matchers): Matchers; @@ -304,60 +359,71 @@ declare global { interface Actions { /** * Simulate tap on an element - * @example await element(by.id('tappable')).tap(); + * @example + * await element(by.id('tappable')).tap(); */ tap(): Promise>; /** * Simulate long press on an element - * @example await element(by.id('tappable')).longPress(); + * @example + * await element(by.id('tappable')).longPress(); */ longPress(): Promise>; /** * Simulate multiple taps on an element. - * @param times number - * @example await element(by.id('tappable')).multiTap(3); + * @param times number of times to tap + * @example + * await element(by.id('tappable')).multiTap(3); */ multiTap(times: number): Promise>; /** * Simulate tap at a specific point on an element. * Note: The point coordinates are relative to the matched element and the element size could changes on different devices or even when changing the device font size. * @param point - * @example await element(by.id('tappable')).tapAtPoint({ x:5, y:10 }); + * @example + * await element(by.id('tappable')).tapAtPoint({ x:5, y:10 }); */ tapAtPoint(point: { x: number; y: number }): Promise>; /** * Use the builtin keyboard to type text into a text field. * @param text - * @example await element(by.id('textField')).typeText('passcode'); + * @example + * await element(by.id('textField')).typeText('passcode'); */ typeText(text: string): Promise>; /** * Paste text into a text field. * @param text - * @example await element(by.id('textField')).replaceText('passcode again'); + * @example + * await element(by.id('textField')).replaceText('passcode again'); */ replaceText(text: string): Promise>; /** * Clear text from a text field. - * @example await element(by.id('textField')).clearText(); + * @example + * await element(by.id('textField')).clearText(); */ clearText(): Promise>; /** * Taps the backspace key on the built-in keyboard. - * @example await element(by.id('textField')).tapBackspaceKey(); + * @example + * await element(by.id('textField')).tapBackspaceKey(); */ tapBackspaceKey(): Promise>; /** * Taps the return key on the built-in keyboard. - * @example await element(by.id('textField')).tapReturnKey(); + * @example + * await element(by.id('textField')).tapReturnKey(); */ tapReturnKey(): Promise>; /** - * - * @param pixels - * @param direction + * 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 @optional startPositionX - the X starting scroll position, in percentage; valid input: `[0.0, 1.0]`, `NaN`; default: `NaN`—choose the best value automatically + * @param @optional 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'); + * await element(by.id('scrollView')).scroll(100, 'down', NaN, 0.85); * await element(by.id('scrollView')).scroll(100, 'up'); */ scroll( @@ -369,41 +435,59 @@ declare global { /** * Scroll to edge. * @param edge - * @example await element(by.id('scrollView')).scrollTo('bottom'); + * @example + * await element(by.id('scrollView')).scrollTo('bottom'); * await element(by.id('scrollView')).scrollTo('top'); */ scrollTo(edge: Direction): Promise>; /** - * + * Swipes in the provided direction at the provided speed, started from percentage. * @param direction - * @param speed - * @param percentage - * @example await element(by.id('scrollView')).swipe('down'); + * @param speed default: `fast` + * @param @optional percentage screen percentage to swipe; valid input: `[0.0, 1.0]` + * @example + * await element(by.id('scrollView')).swipe('down'); * await element(by.id('scrollView')).swipe('down', 'fast'); * await element(by.id('scrollView')).swipe('down', 'fast', 0.5); */ - swipe( - direction: Direction, - speed?: Speed, - percentage?: number - ): Promise>; + swipe(direction: Direction, speed?: Speed, percentage?: number): Promise>; /** - * (iOS Only) column - number of datepicker column (starts from 0) value - string value in setted column (must be correct) - * @param column - * @param value - * @example await expect(element(by.type('UIPickerView'))).toBeVisible(); + * Sets a picker view’s column to the given value. This function supports both date pickers and general picker views. (iOS Only) + * @param column number of datepicker column (starts from 0) + * @param value string value in setted column (must be correct) + * @example a + * wait expect(element(by.type('UIPickerView'))).toBeVisible(); * await element(by.type('UIPickerView')).setColumnToValue(1,"6"); * await element(by.type('UIPickerView')).setColumnToValue(2,"34"); + * + * > 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. + * See [here](https://github.com/wix/Detox/blob/master/docs/APIRef.DeviceObjectAPI.md#9-launch-with-a-specific-language-ios-only) for more information. */ - setColumnToValue( - column: number, - value: string - ): Promise>; + setColumnToValue(column: number, value: string): Promise>; + /** + * Sets the date of a date picker to a date generated from the provided string and date format. (iOS only) + * @param dateString string representing a date in the supplied `dateFormat` + * @param dateFormat format for the `dateString` supplied + * @example + * await expect(element(by.id('datePicker'))).toBeVisible(); + * await element(by.id('datePicker')).setDatePickerDate('2019-02-06T05:10:00-08:00', "yyyy-MM-dd'T'HH:mm:ssZZZZZ"); + */ + setDatePickerDate(dateString: string, dateFormat: string): Promise>; + /** + * Pinches in the given direction with speed and angle. (iOS only) + * @param direction + * @param speed + * @param angle value in radiant, default is `0` + * @example + * await expect(element(by.id('PinchableScrollView'))).toBeVisible(); + * await element(by.id('PinchableScrollView')).pinchWithAngle('outward', 'slow', 0); + */ + pinchWithAngle(direction: Direction, speed: Speed, angle: number): Promise>; } - type Direction = "left" | "right" | "top" | "bottom" | "up" | "down"; - type Orientation = "portrait" | "landscape"; - type Speed = "fast" | "slow"; + type Direction = 'left' | 'right' | 'top' | 'bottom' | 'up' | 'down'; + type Orientation = 'portrait' | 'landscape'; + type Speed = 'fast' | 'slow'; interface LanguageAndLocale { language?: string; locale?: string; @@ -427,7 +511,7 @@ declare global { /** * Source for string definitions is https://github.com/wix/AppleSimulatorUtils */ - interface DevicePermissions { + interface DevicePermissions { location?: LocationPermission; notifications?: NotificationsPermission; calendar?: CalendarPermission; @@ -444,8 +528,8 @@ declare global { speech?: SpeechPermission; } - type LocationPermission = "always" | "inuse" | "never" | "unset"; - type PermissionState = "YES" | "NO" | "unset"; + type LocationPermission = 'always' | 'inuse' | 'never' | 'unset'; + type PermissionState = 'YES' | 'NO' | 'unset'; type CameraPermission = PermissionState; type ContactsPermission = PermissionState; type CalendarPermission = PermissionState;