Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typings: getAttributes() typings #2598

Closed
noomorph opened this issue Jan 18, 2021 · 7 comments
Closed

Typings: getAttributes() typings #2598

noomorph opened this issue Jan 18, 2021 · 7 comments

Comments

@noomorph
Copy link
Collaborator

The current TypeScript definitions are lacking element(...).getAttributes() signature.

Let's add it soon.

@d4vidi
Copy link
Collaborator

d4vidi commented Jan 18, 2021

Great! Need to note that it is iOS-only for the time being. Related issue: #2083

@LeoNatan
Copy link
Contributor

It also returns different things for different views, and returns array of attributes if there are multiple matches. Good luck 😂

@LeoNatan
Copy link
Contributor

Ah, I see it's possible to specify that a function returns either type A or type B, which will work here. 👍

@Gnarwall19
Copy link

It looks like Definitely Typed added this a few days ago.
DefinitelyTyped/DefinitelyTyped@3696ffa

@LeoNatan
Copy link
Contributor

They have the following definition:

/**
 * Returns an object, representing the attributes of the element.
 * @example
 * const attributes = await element(by.text('Tap Me')).getAttributes();
 * jestExpect(attributes.text).toBe('Tap Me');
 * const multipleMatchedElements = await element(by.text('Multiple')).getAttributes();
 * jestExpect(multipleMatchedElements.elements.length).toBe(5);
 * jestExpect(multipleMatchedElements.elements[0].identifier).toBe('FirstElement');
 */
getAttributes(): Promise<AttributesOfIOS>;

...

interface AttributesOfIOS {
    /**
     * the text value of the element
     */
    text: string;
    /**
     * the label of the element (matches `accessibilityLabel`)
     */
    label: string;
    /**
     * the value of the element (matches `accessibilityValue`)
     */
    value: string;
    /**
     * the placeholder text value of the element
     */
    placeholder: string;
    /**
     * the identifier of the element (matches `accessibilityIdentifier`)
     */
    identifier: string;
    /**
     * whether or not the element is enabled for user interaction
     */
    enabled: boolean;
    /**
     * the activation point of the element, in element coordinate space
     */
    activationPoint: Point;
    /**
     * the activation point of the element, in normalized percentage ([0.0, 1.0])
     */
    normalizedActivationPoint: Point;
    /**
     * whether the element is hittable at the activation point
     */
    hittable: boolean;
    /**
     * whether the element is visible at the activation point
     */
    visible: boolean;
    /**
     * the frame of the element, in screen coordinate space
     */
    frame: AttributeIOSFrame;
    /**
     * the frame of the element, in container coordinate space
     */
    elementFrame: AttributeIOSFrame;
    /**
     * the bounds of the element, in element coordinate space
     */
    elementBounds: AttributeIOSFrame;
    /**
     * the safe area insets of the element, in element coordinate space
     */
    safeAreaInsets: AttributeIOSInsets;
    /**
     * the safe area bounds of the element, in element coordinate space
     */
    elementSafeBounds: AttributeIOSFrame;
    /**
     * the date of the element (in case the element is a date picker)
     */
    date: string;
    /**
     * the normalized slider position (in case the element is a slider)
     */
    normalizedSliderPosition: number;
    /**
     * the content offset (in case the element is a scroll view)
     */
    contentOffset: number;
    /**
     * the content inset (in case the element is a scroll view)
     */
    contentInset: number;
    /**
     * the adjusted content inset (in case the element is a scroll view)
     */
    adjustedContentInset: number;
    layer: string;
}

Which is impressive that they went and documented all that, but inaccurate. If multiple elements are matched, the return type is array of those.

@stale
Copy link

stale bot commented Feb 19, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back.

Thank you for your contributions!

For more information on bots in this reporsitory, read this discussion.

@d4vidi
Copy link
Collaborator

d4vidi commented Oct 19, 2021

Closing in favor of #2971 (dup).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants