Skip to content

Fix scroll direction and handle OpticsError in scrolling logic#316

Merged
thakur-patel merged 3 commits into
mozarkai:mainfrom
kun-codes:fix/fix-scroll_until_element_appears-action
Jun 25, 2026
Merged

Fix scroll direction and handle OpticsError in scrolling logic#316
thakur-patel merged 3 commits into
mozarkai:mainfrom
kun-codes:fix/fix-scroll_until_element_appears-action

Conversation

@kun-codes

Copy link
Copy Markdown
Contributor
  • Fixed the reverse scroll direction for up/down in optics_framework/engines/drivers/appium.py
  • Caught OpticsError error code E0201 which corresponds to element location issues in optics_framework/api/action_keyword.py

The call chain which leads to OpticsError is:

  1. scroll_until_element_appears calls self.verifier.assert_presence(element, timeout_str="3", rule="any", fail=False)
  2. verifier.assert_presence (verifier.py:89) calls self._process_element_groups(...) at line 107
  3. _process_element_groups (verifier.py:107) calls self.strategy_manager.assert_presence(elem_group, elem_type, timeout, rule) at line 114 — no try/except around it
  4. strategy_manager.assert_presence (strategies.py) raises OpticsError(Code.E0201, ...) when the element is not found

I have tested out my pull request on an Android device

- correct vertical swipe coordinates by swapping up/down branches
retry loop

- The assert_presence call throws OpticsError(Code.E0201) when the
  element is not found, which killed the while loop on the first miss.
  Wrap in try/except to catch only E0201(element not found) so the loop
  continues scrolling until timeout. Re-raise any other OpticsError
  codes
Copilot AI review requested due to automatic review settings June 23, 2026 11:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts mobile scrolling behavior and makes scroll_until_element_appears resilient to element-not-found errors raised by the strategy layer, so scrolling can continue until timeout.

Changes:

  • Fixes the up/down coordinate mapping in the Appium driver’s scroll() gesture.
  • Wraps verifier.assert_presence(...) in scroll_until_element_appears with an OpticsError handler to ignore E0201 (element not found) while continuing to scroll.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
optics_framework/engines/drivers/appium.py Updates swipe start/end Y coordinates to correct up vs down scroll direction behavior.
optics_framework/api/action_keyword.py Catches OpticsError during scroll-until-present loop so E0201 doesn’t abort scrolling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread optics_framework/api/action_keyword.py
Comment thread optics_framework/api/action_keyword.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Chinmay Jha <chinmayajha@gmail.com>
@chinmayajha

Copy link
Copy Markdown
Collaborator

@kun-codes add a unit test pertaining to this.

@kun-codes

Copy link
Copy Markdown
Contributor Author

@chinmayajha added unit tests

elif direction == "down":
start_x = width // 2
start_y = int(height * 0.2)
end_y = int(height * 0.8)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a good part you picked.
it would be great if we unify the standard for this in docs across all drivers
for example

  1. do we follow scroll movement -> if user scrolls down -> page goes down

or
2. do we follow swipe movement -> if you swipes down -> page goes up

or a mix of both

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright I will add this to the TODO

@chinmayajha chinmayajha requested a review from thakur-patel June 25, 2026 13:34
@thakur-patel thakur-patel merged commit e04979e into mozarkai:main Jun 25, 2026
8 checks passed
@sonarqubecloud

Copy link
Copy Markdown

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.

5 participants