我想知道如何使用原生键盘输入数字,然后使用" \ n"
在Detox上的普通字符串上输入类似文本 // await typeText('${screen_id}_screen_question_${question_id}_answer_input_', '\n');
我如何用数字来实现这个目标?
每当我执行typeText(' n')时,它都会给我GREYKeyboard: No known SHIFT key was found in the hierarchy.
。
在我的假设中,因为小键盘键没有Enter键。但仍然不确定为什么它会寻找Shift键。
由于
答案 0 :(得分:1)
使用react-native键盘模块隐藏键盘。
这与此问题类似:detox-how-to-test-multiline-textinput
示例:
import {Keyboard} from 'react-native'
import React, { Component } from 'react'
import {
AppRegistry,
StyleSheet,
Alert,
TouchableWithoutFeedback,
TouchableOpacity,
View,
Text,
TextInput
} from 'react-native'
class example extends Component {
constructor(props) {
super(props)
}
render() {
return (
<TouchableWithoutFeedback
onPress={Keyboard.dismiss}
style={styles.container}
>
<View style={styles.form}>
<View style={styles.input}>
<TextInput
testID='input'
style={styles.inputText}
keyboardType="numeric"
/>
</View>
<TouchableOpacity
testID='next'
style={styles.button}
onPress={() => Alert.alert("Button pressed")}
>
<Text>Next</Text>
</TouchableOpacity>
</View>
</TouchableWithoutFeedback>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1
},
form: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
input: {
height: 20,
width: 200,
borderColor: 'gray',
borderWidth: 1
},
inputText: {
flex: 1
},
button: {
margin: 20,
padding: 5,
borderColor: 'gray',
borderWidth: 1
}
})
AppRegistry.registerComponent('example', () => example)
测试:
it('Hide num keyboard', async () => {
const inputElement = element(by.id('input'));
await expect(inputElement).toBeVisible();
await inputElement.typeText('1234567890');
// click somewhere outside the input
await inputElement.tapAtPoint({x: 0, y: -1});
const buttonElement = element(by.id('next'));
await expect(buttonElement).toBeVisible();
await buttonElement.tap();
});
结果: