排毒 - 在数字键盘上输入 [英] Detox - Enter on Numpad
问题描述
我想知道如何使用本机键盘输入数字,然后像使用\n"在 Detox 上的普通字符串上的 typeText 一样输入它
//await typeText('${screen_id}_screen_question_${question_id}_answer_input_', '\n');
我怎样才能用数字实现这一点?
每当我执行 typeText ('n') 时,它都会给我 GREYKeyboard:在层次结构中找不到已知的 SHIFT 键.
.
在我的假设中,因为小键盘键没有 Enter 键.但仍然不知道它为什么要寻找 Shift 键.
谢谢
使用 react-native 中的键盘模块来隐藏键盘.
这是一个类似的问题:
I wonder how to enter the number using native keyboard and then enter it in just like typeText on a normal string on Detox using "\n"
// await typeText('${screen_id}_screen_question_${question_id}_answer_input_', '\n');
How can I achieve this with number?
Whenever I do the typeText ('n') it will give me GREYKeyboard: No known SHIFT key was found in the hierarchy.
.
In my assumption, because the numpad key doesn't have Enter key. But still not sure why it look for a Shift key.
Thanks
Use Keyboard module from react-native to hide the keyboard.
It's a similar problem to this one: detox-how-to-test-multiline-textinput
Example:
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)
Test:
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();
});
Result:
这篇关于排毒 - 在数字键盘上输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!