Skip to content

feat: add two new mobile flags#13905

Merged
christian-bromann merged 4 commits intomainfrom
ws/add-new-mobile-flags
Nov 21, 2024
Merged

feat: add two new mobile flags#13905
christian-bromann merged 4 commits intomainfrom
ws/add-new-mobile-flags

Conversation

@wswebcreation
Copy link
Member

This PR adds new session flags called isNativeContext and mobileContext. These flags will tell you if

  • the mobile is in the native context or not
  • what the context is

It also reverts the extra WebDriver-call that was added to the implicitWait adnd use the isNativeContext flag

They will automatically change if the context changes

Given this config:

// wdio.conf.js
export const config = {
    // ...
    capabilities: [
      {
        platformName: 'iOS',
        app: 'net.company.SafariLauncher',
        udid: '123123123123abc',
        deviceName: 'iPhone',
        // ...
      }
    ],
    // ...
}

You can access these flags like all other (mobile) flags in your test like so:

console.log(driver.isMobile)        // outputs: true
console.log(driver.isNativeContext) // outputs: true
console.log(driver.mobileContext)   // outputs: NATIVE_APP

Because it's attached to the contextManager it will also update the status if you do this based on the below config

// wdio.conf.js
export const config = {
    // ...
    capabilities: [
      {
        platform name: 'iOS',
        browserName: 'safari',
        deviceName: 'iPhone',
        // ...
      }
    ],
    // ...
}

```js
//.....
console.log(driver.isNativeContext)   // outputs: false
console.log(driver.mobileContext)     // outputs: WEBVIEW_8919

await driver.switchContext('NATIVE_APP')
console.log(driver.isNativeContext)   // outputs: true
console.log(driver.mobileContext)     // outputs: NATIVE_APP
    
await driver.switchContext('WEBVIEW_8919')
console.log(driver.isNativeContext)   // outputs: false
console.log(driver.mobileContext)     // outputs: WEBVIEW_8919

Proposed changes

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

@wswebcreation wswebcreation changed the title feat: add two new flags feat: add two new mobile flags Nov 21, 2024
@wswebcreation
Copy link
Member Author

Closes #13887

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 21, 2024

Open in Stackblitz

eslint-plugin-wdio

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

@wdio/appium-service

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

@wdio/allure-reporter

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

@wdio/browser-runner

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

@wdio/browserstack-service

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

@wdio/cli

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

@wdio/concise-reporter

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

@wdio/config

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

@wdio/cucumber-framework

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

@wdio/dot-reporter

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

@wdio/firefox-profile-service

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

@wdio/globals

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

@wdio/jasmine-framework

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

@wdio/json-reporter

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

@wdio/junit-reporter

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

@wdio/lighthouse-service

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

@wdio/local-runner

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

@wdio/logger

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

@wdio/mocha-framework

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

@wdio/protocols

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

@wdio/repl

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

@wdio/reporter

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

@wdio/runner

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

@wdio/sauce-service

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

@wdio/shared-store-service

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

@wdio/smoke-test-cjs-service

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

@wdio/smoke-test-reporter

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

@wdio/smoke-test-service

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

@wdio/spec-reporter

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

@wdio/static-server-service

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

@wdio/sumologic-reporter

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

@wdio/testingbot-service

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

@wdio/utils

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

@wdio/types

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

@wdio/webdriver-mock-service

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

webdriver

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

webdriverio

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

commit: b78b3b5

@wswebcreation wswebcreation added the PR: New Feature 🚀 PRs that contain new features label Nov 21, 2024
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.

One tiny comment. I prefer to keep logic that don't use any class context outside of the class so it makes it easier to move them around

/**
* Keep track of the context to which we switch
*/
if (this.#browser.isMobile && event.command === 'switchContext') {
Copy link
Member

Choose a reason for hiding this comment

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

We don't have to do it in this PR but we should incorperate the Appium Bidi event that notifies us on context changes appium/appium#20741

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's do that later. I believe we also need to check with the Appium team on how to get the versions of the drivers. They are now not exposed and some features, like the bidi support are only in the latest. BS for example is still running Appium 1 as a default 🤦

@wswebcreation
Copy link
Member Author

One tiny comment. I prefer to keep logic that don't use any class context outside of the class so it makes it easier to move them around

Thanks, changed it. Hope this is better

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 merged commit 694f737 into main Nov 21, 2024
@christian-bromann christian-bromann deleted the ws/add-new-mobile-flags branch November 21, 2024 20:34
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