Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions detox/ios/Detox/Invocation/Element.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,19 @@ class Element : NSObject {
@objc
var attributes: [String : Any] {
let views = self.views

if views.count == 1 {

if let index = index {
guard index < views.count else {
dtx_fatalError("Index \(index) beyond bounds \(views.count > 0 ? "[0 .. \(views.count - 1)] " : " ")for "\(self.description)"", viewDescription: failDebugAttributes)
}
return views[index].dtx_attributes
} else if views.count == 1 {
return views.first!.dtx_attributes
} else {
let elements = views.map {
return $0.dtx_attributes
}

return ["elements": elements]
}
}
Expand Down
22 changes: 22 additions & 0 deletions detox/test/e2e/33.attributes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,28 @@ describe('Attributes', () => {
});
});

describe('of multiple views with atIndex', () => {
it(':ios: @legacy should return attributes of a single element when using atIndex', async () => {
const result = await element(by.type('RCTView').withAncestor(by.id('attrScrollView'))).atIndex(0).getAttributes();

expect(result).not.toHaveProperty('elements');
expect(result).toMatchObject({
enabled: true,
visible: true,
});
});

it(':ios: @new-arch should return attributes of a single element when using atIndex', async () => {
const result = await element(by.type('RCTViewComponentView')).atIndex(0).getAttributes();

expect(result).not.toHaveProperty('elements');
expect(result).toMatchObject({
enabled: true,
visible: true,
});
});
});

describe('of multiple views', () => {
it(':ios: @legacy should return an object with .elements array', async () => {
await useMatcher(by.type('RCTView').withAncestor(by.id('attrScrollView')));
Expand Down
Loading