从零开始搭建Detox自动化测试框架测试React Native (IOS/Andriod)也许是全网最全的教程 持续更新中

本文详细介绍了如何构建APP并执行测试用例,包括在debug和release模式下进行编译和测试的方法。同时,提供了多种模拟用户行为的操作,如点击、长按、输入文本等,适用于iOS平台。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

构建APP并执行用例
构建APP 编译
debug模式

detox build --configuration ios.sim.debug

release模式

detox build --configuration ios.sim.release

5.2 执行用例
debug模式

detox test --configuration ios.sim.debug

release模式

detox test --configuration ios.sim.release 

常用操作方法
模拟用户行为

Actions 操作

Actions are functions that emulate user behavior. They are being performed on matched elements.
操作用来模拟用户行为的,是在匹配的元素上执行的模拟操作的。

Methods

tap() 点击

Simulate tap on an element.

await element(by.id('tappable')).tap();

longPress(duration) 长按

Simulate long press on an element.

duration - long press time interval. (iOS only)

await element(by.id('tappable')).longPress();

multiTap(times) 多次点击

Simulate multiple taps on an element.

await element(by.id('tappable')).multiTap(3);

tapAtPoint() 点击特定坐标位置

Simulate tap at a specific point on an element.


Note: The point coordinates are relative to the matched element and the element size could changes on different devices or even when changing the device font size.

await element(by.id('tappable')).tapAtPoint({x:5, y:10});

typeText(text) 文本输入

Use the builtin keyboard to type text into a text field.

await element(by.id('textField')).typeText('passcode');

Note: Make sure hardware keyboard is disconnected. Otherwise, Detox may fail when attempting to type text.

To make sure hardware keyboard is disconnected, open the simulator from Xcode and make sure Hardware -> Keyboard -> Connect Hardware Keyboard is deselected (or press ⇧⌘K).
确保硬件键盘断开连接(cmd + shift + K 断开硬件键盘 )

replaceText(text) 粘贴到文本框文本

Paste text into a text field.

await element(by.id('textField')).replaceText('passcode again');

clearText() 讲文本框文本清除

Clear text from a text field.

await element(by.id('textField')).clearText();

scroll(pixels, direction) 桌面滚动

Scroll amount of pixels.
pixels - independent device pixels.
direction - left/right/top/bottom

await element(by.id('scrollView')).scroll(100, 'down'); // 向下滚动100像素
await element(by.id('scrollView')).scroll(100, 'up');   // 向上滚动100像素 

scrollTo(edge) 滚动到边缘

Scroll to edge.

edge - left/right/top/bottom

await element(by.id('scrollView')).scrollTo('bottom');
await element(by.id('scrollView')).scrollTo('top');

swipe(direction, speed, percentage) 滑动

direction - left/right/up/down
方向
speed - fast/slow - default is fast
速度
percentage - (optional) screen percentage to swipe as float
百分比

await element(by.id('scrollView')).swipe('down');
await element(by.id('scrollView')).swipe('down', 'fast');
await element(by.id('scrollView')).swipe('down', 'fast', 0.5);

setColumnToValue(column,value) iOS only

column - date picker column index

value - string value to set in column

await expect(element(by.type('UIPickerView'))).toBeVisible();
await element(by.type('UIPickerView')).setColumnToValue(1,"6");
await element(by.type('UIPickerView')).setColumnToValue(2,"34");
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值