如何测试DatePickerIOS

How to test DatePickerIOS

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

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

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
    }