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

Cannot find element using await driver.$(~${tag}) in Appium 2.0.0 for React Native app (can be replicated on iOS device&simulator, Android is fine) #18920

Closed
richardzhang0301 opened this issue Jul 28, 2023 · 7 comments
Labels
Needs Info typically non-actionable; needs author to respond Question

Comments

@richardzhang0301
Copy link

The goal is to get the element of this:
<TextInput
// accessible={true}
testID={TestIDs.Components.Signup.EmailInput}
accessibilityLabel={TestIDs.Components.Signup.EmailInput}
ref={(rf) => { this.emailTextInput = rf }}
placeholder={translate("EmailPlaceHolder")}
value={this.state.email}
onChangeText={(text) => this.setState({
validationAlert: false,
email: text
})}
//placeholderTextColor={'black'}
placeholderTextColor={'#acacac'}
style={{
color: APP_BLACK_TEXT_COLOR, fontSize: 16,
marginTop: 2, fontWeight: '400',
padding: 5,
flex: 1,
marginLeft: 10
}}
/>

and the EmailInput value is defined here:
Signup: {
EmailInput: 'Signup-EmailInput',
ConfirmEmailInput: 'Signup-ConfirmEmailInput',
FullNameInput: 'Signup-FullNameInput',
ErrorMessage: 'Signup-ErrorMessage',
ContinueButton: 'Signup-ContinueButton',
CloseButton: 'Signup-CloseButton',
LoginButton: 'Signup-LoginButton',
},

This is the App Source extracted from Appium Inspector:

This is the UI preview in the inspector (as you can see, I selected the most nested node, but I cannot expend it further):
image

In Appium 1.0, there seems a way to set snapshotMaxDepth and customSnapshotTimeout, I tried:
capabilities: {
platformName: 'iOS',
'appium:automationName': 'XCUITest',
'appium:deviceName': 'iPhone 13',
'appium:app': '/Users/dongchenzhang/Library/Developer/Xcode/DerivedData/PackageTrackingApp-gfzkdaytisfbfwbrdbqztcicjmbo/Build/Products/Debug-iphonesimulator/TrackMyPack.app',
'appium:fullReset': false, // by default is true
'appium:noReset': true,
// 'appium:settings[snapshotMaxDepth]': 100,
'appium:snapshotMaxDepth': 500,
'appium:customSnapshotTimeout': 60000,
},

but Appium does not recognize:
[Appium] Available drivers:
[Appium] - [email protected] (automationName 'Espresso')
[Appium] - [email protected] (automationName 'UiAutomator2')
[Appium] - [email protected] (automationName 'XCUITest')
[Appium] No plugins have been installed. Use the "appium plugin" command to install the one(s) you want to use.
[HTTP] --> POST /wd/hub/session
[HTTP] {"capabilities":{"alwaysMatch":{"platformName":"iOS","appium:automationName":"XCUITest","appium:deviceName":"iPhone 13","appium:app":"/Users/dongchenzhang/Library/Developer/Xcode/DerivedData/PackageTrackingApp-gfzkdaytisfbfwbrdbqztcicjmbo/Build/Products/Debug-iphonesimulator/TrackMyPack.app","appium:fullReset":false,"appium:noReset":true,"appium:snapshotMaxDepth":500,"appium:customSnapshotTimeout":60000},"firstMatch":[{}]},"desiredCapabilities":{"platformName":"iOS","appium:automationName":"XCUITest","appium:deviceName":"iPhone 13","appium:app":"/Users/dongchenzhang/Library/Developer/Xcode/DerivedData/PackageTrackingApp-gfzkdaytisfbfwbrdbqztcicjmbo/Build/Products/Debug-iphonesimulator/TrackMyPack.app","appium:fullReset":false,"appium:noReset":true,"appium:snapshotMaxDepth":500,"appium:customSnapshotTimeout":60000}}
[debug] [AppiumDriver@e068] Calling AppiumDriver.createSession() with args: [{"platformName":"iOS","appium:automationName":"XCUITest","appium:deviceName":"iPhone 13","appium:app":"/Users/dongchenzhang/Library/Developer/Xcode/DerivedData/PackageTrackingApp-gfzkdaytisfbfwbrdbqztcicjmbo/Build/Products/Debug-iphonesimulator/TrackMyPack.app","appium:fullReset":false,"appium:noReset":true,"appium:snapshotMaxDepth":500,"appium:customSnapshotTimeout":60000},null,{"alwaysMatch":{"platformName":"iOS","appium:automationName":"XCUITest","appium:deviceName":"iPhone 13","appium:app":"/Users/dongchenzhang/Library/Developer/Xcode/DerivedData/PackageTrackingApp-gfzkdaytisfbfwbrdbqztcicjmbo/Build/Products/Debug-iphonesimulator/TrackMyPack.app","appium:fullReset":false,"appium:noReset":true,"appium:snapshotMaxDepth":500,"appium:customSnapshotTimeout":60000},"firstMatch":[{}]}]
[debug] [AppiumDriver@e068] Event 'newSessionRequested' logged at 1690507966239 (18:32:46 GMT-0700 (Pacific Daylight Saving Time))
[Appium] Attempting to find matching driver for automationName 'XCUITest' and platformName 'iOS'
[Appium] The 'xcuitest' driver was installed and matched caps.
[Appium] Will require it at /Users/dongchenzhang/Desktop/work/Linquet/repository/track-my-pack-fork2_appiumQA/node_modules/appium-xcuitest-driver
[debug] [Appium] Requiring driver at /Users/dongchenzhang/Desktop/work/Linquet/repository/track-my-pack-fork2_appiumQA/node_modules/appium-xcuitest-driver
[AppiumDriver@e068] Appium v2.0.0 creating new XCUITestDriver (v4.32.20) session
[AppiumDriver@e068] Checking BaseDriver versions for Appium and XCUITestDriver
[AppiumDriver@e068] Appium's BaseDriver version is 9.3.15
[AppiumDriver@e068] XCUITestDriver's BaseDriver version is 9.3.15
[debug] [XCUITestDriver@0db7] Creating session with W3C capabilities: {
[debug] [XCUITestDriver@0db7] "alwaysMatch": {
[debug] [XCUITestDriver@0db7] "platformName": "iOS",
[debug] [XCUITestDriver@0db7] "appium:automationName": "XCUITest",
[debug] [XCUITestDriver@0db7] "appium:deviceName": "iPhone 13",
[debug] [XCUITestDriver@0db7] "appium:app": "/Users/dongchenzhang/Library/Developer/Xcode/DerivedData/PackageTrackingApp-gfzkdaytisfbfwbrdbqztcicjmbo/Build/Products/Debug-iphonesimulator/TrackMyPack.app",
[debug] [XCUITestDriver@0db7] "appium:fullReset": false,
[debug] [XCUITestDriver@0db7] "appium:noReset": true,
[debug] [XCUITestDriver@0db7] "appium:snapshotMaxDepth": 500,
[debug] [XCUITestDriver@0db7] "appium:customSnapshotTimeout": 60000
[debug] [XCUITestDriver@0db7] },
[debug] [XCUITestDriver@0db7] "firstMatch": [
[debug] [XCUITestDriver@0db7] {}
[debug] [XCUITestDriver@0db7] ]
[debug] [XCUITestDriver@0db7] }
[XCUITestDriver@0db7] The following capabilities were provided, but are not recognized by Appium:
[XCUITestDriver@0db7] snapshotMaxDepth
[XCUITestDriver@0db7] customSnapshotTimeout

How can I set snapshotMaxDepth and customSnapshotTimeout correctly in Appium 2.0.0?
Or is there any other solution from another perspective? Thanks.

@KazuCocoa
Copy link
Member

as same as Appium 1, the below syntax works as part of capabilities.

'appium:settings[snapshotMaxDepth]': 100,

The client method could vary, but https://appium.io/docs/en/2.0/guides/settings/ also works.
e.g. https://www.rubydoc.info/gems/appium_lib_core/Appium/Core/Base/Driver#settings=-instance_method

@mykola-mokhnach mykola-mokhnach added the Needs Info typically non-actionable; needs author to respond label Jul 28, 2023
@richardzhang0301
Copy link
Author

richardzhang0301 commented Jul 28, 2023

as same as Appium 1, the below syntax works as part of capabilities.

'appium:settings[snapshotMaxDepth]': 100,

The client method could vary, but https://appium.io/docs/en/2.0/guides/settings/ also works. e.g. https://www.rubydoc.info/gems/appium_lib_core/Appium/Core/Base/Driver#settings=-instance_method

Thanks for your info.
I tried this in capabilities:

capabilities: {
platformName: 'iOS',
'appium:automationName': 'XCUITest',
'appium:deviceName': 'iPhone 13',
'appium:platformVersion': '16.4',
'appium:app': '/Users/xxx/Library/Developer/Xcode/DerivedData/PackageTrackingApp-gfzkdaytisfbfwbrdbqztcicjmbo/Build/Products/Debug-iphonesimulator/TrackMyPack.app',
'appium:fullReset': false, // by default is true
'appium:noReset': true,
'appium:settings[snapshotMaxDepth]': 500,
'appium:settings[customSnapshotTimeout]': 60000,
// 'appium:snapshotMaxDepth': 500,
// 'appium:customSnapshotTimeout': 60000,
},

And there seems no errors in the Appium log:
[HTTP] --> POST /wd/hub/session
[HTTP] {"capabilities":{"alwaysMatch":{"platformName":"iOS","appium:automationName":"XCUITest","appium:deviceName":"iPhone 13","appium:platformVersion":"16.4","appium:app":"/Users/xxx/Library/Developer/Xcode/DerivedData/PackageTrackingApp-gfzkdaytisfbfwbrdbqztcicjmbo/Build/Products/Debug-iphonesimulator/TrackMyPack.app","appium:fullReset":false,"appium:noReset":true,"appium:settings[snapshotMaxDepth]":500},"firstMatch":[{}]},"desiredCapabilities":{"platformName":"iOS","appium:automationName":"XCUITest","appium:deviceName":"iPhone 13","appium:platformVersion":"16.4","appium:app":"/Users/xxx/Library/Developer/Xcode/DerivedData/PackageTrackingApp-gfzkdaytisfbfwbrdbqztcicjmbo/Build/Products/Debug-iphonesimulator/TrackMyPack.app","appium:fullReset":false,"appium:noReset":true,"appium:settings[snapshotMaxDepth]":500}}
[debug] [AppiumDriver@85cc] Calling AppiumDriver.createSession() with args: [{"platformName":"iOS","appium:automationName":"XCUITest","appium:deviceName":"iPhone 13","appium:platformVersion":"16.4","appium:app":"/Users/xxx/Library/Developer/Xcode/DerivedData/PackageTrackingApp-gfzkdaytisfbfwbrdbqztcicjmbo/Build/Products/Debug-iphonesimulator/TrackMyPack.app","appium:fullReset":false,"appium:noReset":true,"appium:settings[snapshotMaxDepth]":500},null,{"alwaysMatch":{"platformName":"iOS","appium:automationName":"XCUITest","appium:deviceName":"iPhone 13","appium:platformVersion":"16.4","appium:app":"/Users/xxx/Library/Developer/Xcode/DerivedData/PackageTrackingApp-gfzkdaytisfbfwbrdbqztcicjmbo/Build/Products/Debug-iphonesimulator/TrackMyPack.app","appium:fullReset":false,"appium:noReset":true,"appium:settings[snapshotMaxDepth]":500},"firstMatch":[{}]}]
[debug] [AppiumDriver@85cc] Event 'newSessionRequested' logged at 1690562739806 (09:45:39 GMT-0700 (Pacific Daylight Saving Time))
[Appium] Attempting to find matching driver for automationName 'XCUITest' and platformName 'iOS'
[Appium] The 'xcuitest' driver was installed and matched caps.
[Appium] Will require it at /Users/xxx/Desktop/work/Linquet/repository/track-my-pack-fork2_appiumQA/node_modules/appium-xcuitest-driver
[debug] [Appium] Requiring driver at /Users/xxx/Desktop/work/Linquet/repository/track-my-pack-fork2_appiumQA/node_modules/appium-xcuitest-driver
[AppiumDriver@85cc] Appium v2.0.0 creating new XCUITestDriver (v4.32.20) session
[AppiumDriver@85cc] Checking BaseDriver versions for Appium and XCUITestDriver
[AppiumDriver@85cc] Appium's BaseDriver version is 9.3.15
[AppiumDriver@85cc] XCUITestDriver's BaseDriver version is 9.3.15
[debug] [XCUITestDriver@a6ea] Creating session with W3C capabilities: {
[debug] [XCUITestDriver@a6ea] "alwaysMatch": {
[debug] [XCUITestDriver@a6ea] "platformName": "iOS",
[debug] [XCUITestDriver@a6ea] "appium:automationName": "XCUITest",
[debug] [XCUITestDriver@a6ea] "appium:deviceName": "iPhone 13",
[debug] [XCUITestDriver@a6ea] "appium:platformVersion": "16.4",
[debug] [XCUITestDriver@a6ea] "appium:app": "/Users/xxx/Library/Developer/Xcode/DerivedData/PackageTrackingApp-gfzkdaytisfbfwbrdbqztcicjmbo/Build/Products/Debug-iphonesimulator/TrackMyPack.app",
[debug] [XCUITestDriver@a6ea] "appium:fullReset": false,
[debug] [XCUITestDriver@a6ea] "appium:noReset": true
[debug] [XCUITestDriver@a6ea] },
[debug] [XCUITestDriver@a6ea] "firstMatch": [
[debug] [XCUITestDriver@a6ea] {}
[debug] [XCUITestDriver@a6ea] ]
[debug] [XCUITestDriver@a6ea] }
[XCUITestDriver@a6ea (8c65a3d9)] Session created with session id: 8c65a3d9-8933-436e-adb4-363f14e17a00
[debug] [XCUITest] Current user: 'xxx'
[XCUITestDriver@a6ea (8c65a3d9)] iOS SDK Version set to '16.4'
[debug] [XCUITest] Looking for an existing Simulator with platformName: iOS, platformVersion: 16.4, deviceName: iPhone 13
[iOSSim] Constructing iOS simulator for Xcode version 14.3.1 with udid '0D68DA49-DD97-49C0-AC6E-508B8713ECC6'
[XCUITestDriver@a6ea (8c65a3d9)] Determining device to run tests on: udid: '0D68DA49-DD97-49C0-AC6E-508B8713ECC6', real device: false
[debug] [XCUITestDriver@a6ea (8c65a3d9)] Event 'xcodeDetailsRetrieved' logged at 1690562740080 (09:45:40 GMT-0700 (Pacific Daylight Saving Time))
[BaseDriver] Using local app '/Users/xxx/Library/Developer/Xcode/DerivedData/PackageTrackingApp-gfzkdaytisfbfwbrdbqztcicjmbo/Build/Products/Debug-iphonesimulator/TrackMyPack.app'
[debug] [XCUITestDriver@a6ea (8c65a3d9)] Event 'appConfigured' logged at 1690562740081 (09:45:40 GMT-0700 (Pacific Daylight Saving Time))
[debug] [XCUITest] Checking whether app '/Users/xxx/Library/Developer/Xcode/DerivedData/PackageTrackingApp-gfzkdaytisfbfwbrdbqztcicjmbo/Build/Products/Debug-iphonesimulator/TrackMyPack.app' is actually present on file system
[debug] [XCUITest] App is present
[debug] [XCUITest] Getting bundle ID from app '/Users/xxx/Library/Developer/Xcode/DerivedData/PackageTrackingApp-gfzkdaytisfbfwbrdbqztcicjmbo/Build/Products/Debug-iphonesimulator/TrackMyPack.app': 'com.trackmypack.trackmypack'
[debug] [XCUITestDriver@a6ea (8c65a3d9)] Event 'resetStarted' logged at 1690562740085 (09:45:40 GMT-0700 (Pacific Daylight Saving Time))
[debug] [XCUITest] Reset: noReset is on. Leaving simulator as is
[debug] [XCUITestDriver@a6ea (8c65a3d9)] Event 'resetComplete' logged at 1690562740085 (09:45:40 GMT-0700 (Pacific Daylight Saving Time))

However, from Appium Inspector, I stil get the same App source (Signup-EmailInput is not in its independent node)

Not sure if snapshotMaxDepth and customSnapshotTimeout are readlly taking effects.
Or is there any other way to get the element for the TextInput with accessibility label and testId of 'Signup-EmailInput' in my case? Thanks.

@KazuCocoa
Copy link
Member

KazuCocoa commented Jul 28, 2023

If your question was how to split the big one name element thing (kind of), it depends on RN implementation.

e.g.
#14825 (comment)

Some nested element cases, you may need to set accessible={false} in the outer element and set accessible={true} in the inner element to interact with the inner element

@richardzhang0301
Copy link
Author

richardzhang0301 commented Jul 28, 2023

If your question was how to split the big one name element thing (kind of), it depends on RN implementation.

e.g. #14825 (comment)

Some nested element cases, you may need to set accessible={false} in the outer element and set accessible={true} in the inner element to interact with the inner element

Thanks. I have tried both 50 and 62 (max supported) for 'snapshotMaxDepth' settings, and the App source stayed the same as when it is set to 500 or not set. (Signup-EmailInput is not in its independent node)

However, when I set 'snapshotMaxDepth' to be 10, I did get less depth of the App source, so 'snapshotMaxDepth' setting did take effects somehow. Just wondering why Appium is not trying to get elements in more depth, even when 'snapshotMaxDepth' is specified to be 50, 62 and 500 in my case. (especially my app has a very simple UI, as the screenshot I shared in the first message) Also, I commented out the outer the accessible, accessibilityLabel and testId properties in the outer elements, but not luck either.

Is there any other workarounds? Or otherwise, iOS auto testing using Appium is not usable.

@KazuCocoa
Copy link
Member

WDA gives it as a parameter of https://github.com/appium/WebDriverAgent/blob/c204c73081ed210399427917ab43056c07f6f491/PrivateHeaders/XCTest/XCAXClient_iOS.h#L51 (by XCTest), so it might indicate XCTest framework returns only these.

What the result of https://appium.github.io/appium-xcuitest-driver/4.32/execute-methods/#mobile-source with format: description, btw?

@richardzhang0301
Copy link
Author

Executed this in SignUp screen:
let source = await driver.execute('mobile: source', { format: 'description' });
console.log('SignUp source: ' + source);

With 'appium:settings[snapshotMaxDepth]': 50

Here is the execution result:
SignUp source: Attributes: Window (Main), 0x159f418a0, {{0.0, 0.0}, {390.0, 844.0}}
Element subtree:
→Window (Main), 0x159f418a0, {{0.0, 0.0}, {390.0, 844.0}}
Other, 0x159f41c60, {{0.0, 0.0}, {390.0, 844.0}}
Other, 0x159f41d80, {{0.0, 0.0}, {390.0, 844.0}}
Other, 0x159f419c0, {{0.0, 0.0}, {390.0, 844.0}}
Other, 0x159f41ae0, {{0.0, 0.0}, {390.0, 844.0}}, label: 'SignupScreen'
Other, 0x159f41ea0, {{0.0, 0.0}, {390.0, 844.0}}, label: 'SignupScreen'
Other, 0x159f41fc0, {{0.0, 0.0}, {390.0, 844.0}}, label: 'SignupScreen'
Other, 0x159f420e0, {{0.0, 0.0}, {390.0, 844.0}}, label: 'SignupScreen'
Other, 0x159f42200, {{0.0, 0.0}, {390.0, 844.0}}, label: 'SignupScreen'
Other, 0x159f42320, {{0.0, 0.0}, {390.0, 844.0}}, label: 'SignupScreen'
Other, 0x159f42440, {{0.0, 0.0}, {390.0, 844.0}}, label: 'SignupScreen'
Other, 0x159f42560, {{0.0, 0.0}, {390.0, 844.0}}, label: 'SignupScreen'
Other, 0x159f42680, {{0.0, 0.0}, {390.0, 844.0}}, label: 'SignupScreen'
Other, 0x159f427a0, {{0.0, 0.0}, {390.0, 844.0}}, label: 'SignupScreen'
Other, 0x159f428c0, {{0.0, 0.0}, {3.0, 844.0}}
Other, 0x159f429e0, {{0.0, 0.0}, {390.0, 844.0}}, label: 'SignupScreen'
Other, 0x159f42b00, {{0.0, 0.0}, {390.0, 844.0}}, label: 'SignupScreen'
Other, 0x159f42c20, {{0.0, 0.0}, {390.0, 844.0}}, label: 'SignupScreen'
Other, 0x159f42d40, {{0.0, 0.0}, {390.0, 844.0}}, identifier: 'SignupScreen', label: 'SignupScreen'
Other, 0x159f42e60, {{0.0, 0.0}, {390.0, 47.0}}
Other, 0x159f42f80, {{0.0, 0.0}, {390.0, 47.0}}
Other, 0x159f430a0, {{0.0, 47.0}, {390.0, 797.0}}, label: 'Skip Sign up with one tap Continue with Google Continue with Apple OR Sign up with email Signup-EmailInput Signup-ConfirmEmailInput Signup-FullNameInput Signup-ContinueButton By continuing, you agree to our Terms and Privacy Policy Signup-LoginButton Vertical scroll bar, 1 page Horizontal scroll bar, 1 page'
ScrollView, 0x159f43310, {{0.0, 47.0}, {390.0, 797.0}}
Other, 0x159f43430, {{0.0, 47.0}, {390.0, 777.0}}, label: 'Skip Sign up with one tap Continue with Google Continue with Apple OR Sign up with email Signup-EmailInput Signup-ConfirmEmailInput Signup-FullNameInput Signup-ContinueButton By continuing, you agree to our Terms and Privacy Policy Signup-LoginButton'
Other, 0x159f43550, {{0.0, 47.0}, {390.0, 717.0}}, label: 'Skip Sign up with one tap Continue with Google Continue with Apple OR Sign up with email Signup-EmailInput Signup-ConfirmEmailInput Signup-FullNameInput Signup-ContinueButton By continuing, you agree to our Terms and Privacy Policy Signup-LoginButton'
Other, 0x159f43780, {{0.0, 701.7}, {390.0, 27.3}}, identifier: 'Signup-LoginButton', label: 'Signup-LoginButton'
Other, 0x159f438a0, {{0.0, 764.0}, {390.0, 60.0}}
Other, 0x159f439c0, {{357.0, 47.0}, {30.0, 763.0}}, label: 'Vertical scroll bar, 1 page', value: 0%
Other, 0x159f43ae0, {{0.0, 777.0}, {390.0, 30.0}}, label: 'Horizontal scroll bar, 1 page', value: 0%
Path to element:
→Application, 0x159f40800, pid: 27904, label: 'Wonderpack'
↳Window (Main), 0x159f418a0, {{0.0, 0.0}, {390.0, 844.0}}
Query chain:
→Find: Application 'com.trackmypack.trackmypack'
Output: {
Application, 0x159a1d840, pid: 27904, label: 'Wonderpack'
}
↪︎Find: Children matching type Any
Output: {
Window (Main), 0x159a1aa70, {{0.0, 0.0}, {390.0, 844.0}}
}
↪︎Find: Element at index 0
Output: {
Window (Main), 0x159b82140, {{0.0, 0.0}, {390.0, 844.0}}
}

@KazuCocoa
Copy link
Member

So, the result was the same, correct?

It is vanilla debugDescription by XCTest framework. Some comments in #14825 may help to improve the structure of RN application side so that XCTest framework can treat them further, but am afraid no much can do as Appium/WDA side.

Closing this ticket as not much can do as Appium/WDA. Moving to the #14825

https://discuss.appium.io/ may also help to find something past record about RN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Info typically non-actionable; needs author to respond Question
Projects
None yet
Development

No branches or pull requests

3 participants