【问题标题】:Is there a way to access test id's using expo web?有没有办法使用 expo web 访问测试 ID?
【发布时间】:2021-02-26 12:38:09
【问题描述】:

我正在尝试使用 Playwright 在 Expo Web 项目上运行端到端测试。我希望当我将 testId 属性添加到 React Native 视图时,它会被转换为 data-testid,这样我就可以为我的测试选择元素。

但是,它并没有这样做,所以我想不出一个选择元素的好方法。到目前为止,我能想到的最好的办法就是为元素添加一个可访问性标签。

有谁知道将测试 ID 添加到将在网络上测试的 react-native expo 项目的更好方法?

【问题讨论】:

    标签: react-native expo e2e-testing playwright expo-web


    【解决方案1】:

    你可以做到!

    我可能犯了大小写错误。你在 react native 组件上添加一个 testID 属性,然后查询div['data-testid="sampleId"']

    这是一个代码示例:https://github.com/expo/expo/blob/b655ff28d924e2274c627294778a02dbec1268db/apps/bare-expo/e2e/TestSuite-test.web.js#L68

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-09
      • 2021-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-20
      相关资源
      最近更新 更多