react-native - Detox:如何测试多行 TextInput

标签 react-native keyboard hide detox

我正在尝试使用 detox 来测试我的 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% 可见性标准,因为键盘隐藏了提交按钮。

通常,对于具有 multiline={false} 的 TextInput,您只需将 \n 附加到输入字符串,自动移动到下一个阶段,但对于多行输入 \n 只是添加一个新行。

我该怎么做才能通过排毒测试?

最佳答案

首先,我们需要能够使用 multiline={true} 关闭 TextInput 的键盘。

为此,我们将使用react-native 中的键盘模块。

import {Keyboard} from 'react-native'

现在用 TouchableWithoutFeedback 包裹您的表单并在按下时调用 Keyboard.dismiss() 。

<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
  { /* your form goes here */ }
</TouchableWithoutFeedback>

现在修改您的排毒测试以关闭键盘。

const inputElement = element(by.id('input'));
await expect(inputElement).toBeVisible();
await inputElement.typeText('line1\n');
await inputElement.typeText('line2\n');
await inputElement.typeText('line3\n');
// click somewhere outside the input
await inputElement.tapAtPoint({x: 0, y: 1});

const submitElement = element(by.id('submit'));
await submitElement.toBeVisible();
await submitElement.tap();

detox running the test

关于react-native - Detox:如何测试多行 TextInput,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47555126/

相关文章:

javascript - 类型错误 : undefined is not an object gotten when using navigation. openDrawer()

react-native - 无法从 node_modules\uuidv4\build\lib\uuidv4.js : util could not be found within the project 解析模块 util

ios - TextField SwiftUI 关闭键盘

c++ - SFML 形状无限旋转

jquery 切换以在多个实例中工作

java - React Native 的 BitmapFactory : Unable to decode stream: java. io.FileNotFoundException

Android 键盘在 Web View 中隐藏输入

menu - 在 openerp 中隐藏更多和打印按钮

excel - 如果内容的总和 = 零并跳过空白,我如何隐藏 Excel 行?

javascript - 如何添加 React-Native 原生模块设置依赖?