Skip to content

feat: enhance scrollIntoView to support native mobile#13870

Merged
christian-bromann merged 15 commits intomainfrom
ws/update-scrollintoview-mobile
Nov 13, 2024
Merged

feat: enhance scrollIntoView to support native mobile#13870
christian-bromann merged 15 commits intomainfrom
ws/update-scrollintoview-mobile

Conversation

@wswebcreation
Copy link
Member

@wswebcreation wswebcreation commented Nov 9, 2024

Initial setup to support Native apps

Proposed changes

This PR enhances the scrollIntoView to support native mobile apps by using the native mobile:execute methods of the drivers

Types of changes

  • Polish (an improvement for an existing feature)
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (improvements to the project's docs)
  • Specification changes (updates to WebDriver command specifications)
  • Internal updates (everything related to internal scripts, governance documentation and CI files)

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Backport Request

//: # (The current main branch is the development branch for WebdriverIO v9. If your change should be released to the current major version of WebdriverIO (v8), please raise another PR with the same changes against the v8 branch.)

  • This change is solely for v9 and doesn't need to be back-ported
  • Back-ported PR at #XXXXX

Further comments

Reviewers: @webdriverio/project-committers

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 10, 2024

Open in Stackblitz

eslint-plugin-wdio

pnpm add https://pkg.pr.new/webdriverio/webdriverio/eslint-plugin-wdio@13870

@wdio/allure-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/allure-reporter@13870

@wdio/browser-runner

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/browser-runner@13870

@wdio/appium-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/appium-service@13870

@wdio/browserstack-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/browserstack-service@13870

@wdio/cli

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/cli@13870

@wdio/concise-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/concise-reporter@13870

@wdio/config

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/config@13870

@wdio/cucumber-framework

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/cucumber-framework@13870

@wdio/dot-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/dot-reporter@13870

@wdio/firefox-profile-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/firefox-profile-service@13870

@wdio/globals

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/globals@13870

@wdio/jasmine-framework

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/jasmine-framework@13870

@wdio/json-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/json-reporter@13870

@wdio/junit-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/junit-reporter@13870

@wdio/lighthouse-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/lighthouse-service@13870

@wdio/local-runner

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/local-runner@13870

@wdio/logger

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/logger@13870

@wdio/mocha-framework

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/mocha-framework@13870

@wdio/protocols

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/protocols@13870

@wdio/repl

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/repl@13870

@wdio/reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/reporter@13870

@wdio/runner

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/runner@13870

@wdio/sauce-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/sauce-service@13870

@wdio/shared-store-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/shared-store-service@13870

@wdio/smoke-test-cjs-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-cjs-service@13870

@wdio/smoke-test-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-reporter@13870

@wdio/smoke-test-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-service@13870

@wdio/spec-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/spec-reporter@13870

@wdio/static-server-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/static-server-service@13870

@wdio/sumologic-reporter

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/sumologic-reporter@13870

@wdio/testingbot-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/testingbot-service@13870

@wdio/types

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/types@13870

@wdio/utils

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/utils@13870

@wdio/webdriver-mock-service

pnpm add https://pkg.pr.new/webdriverio/webdriverio/@wdio/webdriver-mock-service@13870

webdriver

pnpm add https://pkg.pr.new/webdriverio/webdriverio/webdriver@13870

webdriverio

pnpm add https://pkg.pr.new/webdriverio/webdriverio@13870

commit: 3cf3653

@wswebcreation wswebcreation marked this pull request as ready for review November 10, 2024 13:23
@wswebcreation
Copy link
Member Author

Hmm, getting the following error when I try to test the command

Can't call scrollIntoView on element with selector "//android.widget.TextView[@resource-id="android:id/title" and @text="System"]" because element wasn't found

For native the elements are not always available as with web. I might have found a hack I'm not proud of. The implicitWait excludes checking for the *waitUntil* methods. If I just "hack" the scrollIntoView into it, it works, it will not find the element, it will scroll and check if it exists, if not, it will scroll, and so on.
This is a "hacky" solution, so I would love to get some input/look into a specific direction to make this more stable. I'm open to suggestions 😅

@christian-bromann
Copy link
Member

If I just "hack" the scrollIntoView into it, it works, it will not find the element, it will scroll and check if it exists, if not, it will scroll, and so on.

It seem fine to me if we extend the if statement with scrollIntoView if we are in a mobile and native context, e.g.

const browser = getBrowserObject(currentElement)
const shallSkipForMobileScrollIntoView = browser.isMobile && (await browser.getContext === 'NATIVE')

Co-authored-by: Christian Bromann <git@bromann.dev>
@wswebcreation
Copy link
Member Author

If I just "hack" the scrollIntoView into it, it works, it will not find the element, it will scroll and check if it exists, if not, it will scroll, and so on.

It seem fine to me if we extend the if statement with scrollIntoView if we are in a mobile and native context, e.g.

const browser = getBrowserObject(currentElement)
const shallSkipForMobileScrollIntoView = browser.isMobile && (await browser.getContext === 'NATIVE')

Thanks, that's a solution. If we have the isNativeContext we could even determine better. There's only one downside, and that is that will always do an extra webdriver call for mobile, no matter if it's web or native app

@christian-bromann
Copy link
Member

There's only one downside, and that is that will always do an extra webdriver call for mobile, no matter if it's web or native app

How about enhancing the context manager the way we discussed so the extra call is obsolete?

@wswebcreation
Copy link
Member Author

There's only one downside, and that is that will always do an extra webdriver call for mobile, no matter if it's web or native app

How about enhancing the context manager the way we discussed so the extra call is obsolete?

That's also what I wanted to do, but in a separate PR which would "revert" the extra call. I wanted to create "smaller" PRs because I don't have a lot of time the coming weeks

@wswebcreation
Copy link
Member Author

wswebcreation commented Nov 11, 2024

@christian-bromann

Not sure why other UTs are failing, I can't see any impact due to my changes (to the fetch Mock). Any ideas?

Fixed it

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@christian-bromann christian-bromann added the PR: New Feature 🚀 PRs that contain new features label Nov 13, 2024
@christian-bromann christian-bromann merged commit 21b53fd into main Nov 13, 2024
@christian-bromann christian-bromann deleted the ws/update-scrollintoview-mobile branch November 13, 2024 16:17
christian-bromann added a commit that referenced this pull request Nov 13, 2024
* feat: enhance scrollIntoView to support native mobile

Initial setup to support Native apps

* test: Add unit tests

* fix: fix types

* chore: add the docs and fix types

* fix: make use of $$ from the browser

- fix tests

* Update packages/webdriverio/src/commands/element/scrollIntoView.ts

Co-authored-by: Christian Bromann <git@bromann.dev>

* chore: updates after feedback

- changed code order
- updated error messages
- fixed UTs

* fix: exclude the scrollIntoView

* fix: fix type for scrollIntoView

* fix: fix type

* fix: type test

* test: fix all UTs

- due to the extra getContext call in mobile mode a lot of UT's failed

---------

Co-authored-by: Christian Bromann <git@bromann.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: New Feature 🚀 PRs that contain new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants