如何测试DatePickerIOS

时间:2018-04-17 13:45:15

标签: detox

我需要使用原生IOS DatePicker输入一天。如何将控制轮旋转到某个可能不在视图中的值,因为这是从当前日期开始的?

enter image description here

2 个答案:

答案 0 :(得分:2)

Detox 7.3.x支持与iOS UIPickerView的互动。按类型匹配UIPickerView,并与之互动。

await expect(element(by.type('UIPickerView'))).toBeVisible();
await element(by.type('UIPickerView')).setColumnToValue(1,"6");
await element(by.type('UIPickerView')).setColumnToValue(2,"34");

文档在这里: https://github.com/wix/detox/blob/master/docs/APIRef.ActionsOnElement.md#setcolumntovaluecolumnvalue--ios-only

答案 1 :(得分:1)

datetimepicker进行了排毒测试,您可以在此处检查代码:

https://github.com/react-native-community/datetimepicker/blob/master/example/e2e/detoxTest.spec.js#L54

if (global.device.getPlatform() === 'ios') {
      const testElement = await element(
        by.type('UIPickerView').withAncestor(by.id('dateTimePicker')),
      );
      await testElement.setColumnToValue(0, 'November');
      await testElement.setColumnToValue(1, '3');
      await testElement.setColumnToValue(2, '1800');

      await expect(dateTimeText).toHaveText('11/03/1800');
    } else {
       // for Android
    }