我正在尝试使用排毒来测试我的react-native应用程序中的表单。
表单中的一个输入有multiline={true}
。
我正在尝试运行以下测试:
const inputElement = element(by.id('input_multiline'));
await expect(inputElement).toBeVisible();
await inputElement.typeText('line1\n');
await inputElement.typeText('line2\n');
await inputElement.typeText('line3\n');
const submitElement = element(by.id('submit'));
await submitElement.toBeVisible();
await submitElement.tap();
此测试无法通过75%的可见性标准,因为键盘正在隐藏提交按钮。
通常对于使用qazxsw poi的文本输入,您可以将qazxsw poi附加到输入字符串,自动移动到下一个阶段,但对于多行输入,multiline={false}
只需添加一个新行。
为了通过排毒测试,我该怎么办?
首先,我们需要能够使用\n
关闭TextInput的键盘。
为此,我们将使用来自react-native的键盘模块。
\n
现在用TouchableWithoutFeedback包装你的表单并按下调用Keyboard.dismiss()。
multiline={true}
现在修改排毒测试以关闭键盘。
import {Keyboard} from 'react-native'
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
{ /* your form goes here */ }
</TouchableWithoutFeedback>