1. 程式人生 > >從零開始搭建Detox自動化測試框架測試React Native (IOS/Andriod)也許是全網最全的教程 持續更新中

從零開始搭建Detox自動化測試框架測試React Native (IOS/Andriod)也許是全網最全的教程 持續更新中

構建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");