Skip to content

Conversation

@ceceppa
Copy link
Member

@ceceppa ceceppa commented Mar 28, 2022

This PR proposes an alternative solution to using Detox.

Proposed solution

When launching the app for OWL testing, we can patch the createElement function of React; this PR is done by calling the initClient method.
This allows us to spy on elements with testIDs and store a reference to their methods, like onPress and onChanged; we can also store a ref to the element that allows us to call methods like: focus, scrollToEnd, etc.

Ideally, the user won't need to add this manually, but we could do it automatically using, for example, a file called index.owl.js where the app will be compiled using this as the entry-point.
In my tests, when calling initClient in the same file of index.js, I couldn't "detect" elements; the createElement was never called for those.

The communication between App and Test happens via the server started on launch. I've added a working example of calling the onPress method for a Pressable component.
This method also allows us to trigger other actions, like: onChangeText, focus and scrollToEnd. It can also be used to get the layout size of a ScrollView, which can be used to get a fullscreen screenshot.

I've also included an example of how we could wait for certain elements to be visible before taking a screenshot.

Some differences with Detox:

  • Tap calls the onPress method, even though the element is not in view or is disabled.
  • Some manual await might be needed by the users to ensure that the screen has been fully rendered.
  • We don't have a way (yet?) to detect if there is some animation going on on the native side

TODO:

  • Find a way to launch an index.owl.js without the user needing to call initClient
  • Organise code
  • Add more interaction methods
  • Discuss on improvements
  • Setup global teardown for jest to close the client connection

ceceppa and others added 30 commits March 16, 2022 16:27
This prevents an issue where some screenshot tests fail, leaving the dif images and report in a half updated state.
@github-actions github-actions bot temporarily deployed to staging-85 May 16, 2022 14:33 Inactive
@github-actions github-actions bot temporarily deployed to staging-85 May 17, 2022 10:08 Inactive
@github-actions github-actions bot temporarily deployed to staging-85 May 18, 2022 13:58 Inactive
@github-actions github-actions bot temporarily deployed to staging-85 May 19, 2022 11:39 Inactive
@github-actions github-actions bot temporarily deployed to staging-85 May 19, 2022 11:47 Inactive
manosim and others added 2 commits May 19, 2022 12:59
* docs: add new methods api docs

* docs: update docs

* docs: document the `call` method

* docs: add docs for owlTestCallbacks

* fix: correct example of wrapping a component to add `OwlTestProps` types

* docs: update docs

* chore: Cleanup ConfigEnv

Co-authored-by: Manos Konstantinidis <hello@manos.im>
@github-actions github-actions bot temporarily deployed to staging-85 May 19, 2022 12:02 Inactive
@github-actions github-actions bot temporarily deployed to staging-85 May 19, 2022 15:58 Inactive
@github-actions github-actions bot temporarily deployed to staging-85 May 19, 2022 16:09 Inactive
@github-actions github-actions bot temporarily deployed to staging-85 May 19, 2022 16:26 Inactive
@github-actions github-actions bot temporarily deployed to staging-85 May 20, 2022 13:43 Inactive
@github-actions github-actions bot temporarily deployed to staging-85 May 20, 2022 13:49 Inactive
@manosim manosim merged commit cea94c6 into main May 20, 2022
@manosim manosim deleted the js-interactions branch May 20, 2022 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants