[英]Detox textInput not writing text
我在我的react-native項目上使用Detox,並想在登錄屏幕上輸入名稱,但是detox無法識別textInput。 這是我的文字代碼
describe('SCA', () => {
beforeEach(async () => {
await device.reloadReactNative();
});
it('should have splash screen', async () => {
await expect(element(by.id('splash'))).toBeVisible();
});
it('should show login screen', async () => {
await waitFor(element(by.id('login'))).toBeVisible();
});
it('test login screen name input', async () => {
await element(by.id('name')).typeText('Liam')
});
});
textInput代碼:
<TextInput
testID="name"
style={styles.input}
onChangeText={value => this.setState({ name: value }) }
placeholder={'Name ... '}
placeholderTextColor='white'
value={name} />
這是我得到的錯誤:
● SCA › test login screen name input
Failed: [Error: Error: Cannot find UI element.
Exception with Action: {
"Action Name": "Type 'Liam'",
"Element Matcher": "((!(kindOfClass('RCTScrollView')) && (respondsToSelector(accessibilityIdentifier) && accessibilityID('name'))) || (((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && parentThatMatches(kindOfClass('RCTScrollView'))) && ((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && parentThatMatches((respondsToSelector(accessibilityIdentifier) && accessibilityID('name'))))))",
"Recovery Suggestion": "Check if the element exists in the UI hierarchy printed below. If it exists, adjust the matcher so that it accurately matches element."
}
Error Trace: [
{
"Description": "Interaction cannot continue because the desired element was not found.",
"Error Domain": "com.google.earlgrey.ElementInteractionErrorDomain",
"Error Code": "0",
"File Name": "GREYElementInteraction.m",
"Function Name": "-[GREYElementInteraction matchedElementsWithTimeout:error:]",
"Line": "124"
}
]
您當前正在每次測試之間重新加載設備。
beforeEach(async () => {
await device.reloadReactNative();
});
我認為這不是您要執行的操作,因為它會重置所有內容,這意味着您必須等待所有內容重新加載並在屏幕上移動,並且您將面臨與上一篇文章相同的問題(注意, waitFor
的用法是不正確的,請參閱我以前的帖子中的答案或重新閱讀文檔 )
您可以在文檔中閱讀有關.typeText
更多信息。
使用.typeText
時的常見錯誤是未斷開硬件鍵盤的連接
注意:確保已斷開硬件鍵盤的連接。 否則,嘗試鍵入文本時排毒可能會失敗。
要確保已斷開硬件鍵盤的連接,請從Xcode打開模擬器,並確保未選中“硬件->鍵盤->連接硬件鍵盤”(或按⇧⌘K)。
使用.typeText
時,我總是做的一件事是確保元素存在
因此,在使用.typeText
以確保它可見之前,我將添加以下內容。
await expect(element(by.id('name'))).toBeVisible();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.