(Appium:CodeceptJS) Can't recognize the page element if previous test against webview

Dear,
My mobile app (Android) is a hybrid application and includes some webview such as T & C page and FAQ page.

Now I write some test cases by Appium of CodeceptJS, looks like if the previous test case is for webview is completed, then during the next test case can’t locate the normal mobile page’s element.

For example, from my case is total 3 test cases:

  1. The first test case is switch to webview page: T&C/FAQ
  2. The second test case, at the first of launch page can’t detect the mobile page element (not webview), for example, LOGIN button.

please check the error log below:

$ npm run codeceptjs

> codeceptjs-tests@0.1.0 codeceptjs
> codeceptjs run --steps

CodeceptJS v3.0.6
Using test root "/Users/qa1/repo/local/codeceptjs-appium-mobile"

App.FAQ Page --
  FAQ page open test should be passed
    loginPage: launch 
      I see app is installed "com.xxx"
      I wait for element "LOGIN", 5                     // LOGIN element can be located at the first test case
    loginPage: openFaq 
      I tap "FAQ"
      I wait for element "//android.webkit.WebView", 5
      I switch to web 
  ✔ OK in 6441ms

App.Home page --
  Home page launch should be passed
2021-05-12T15:30:09.956Z ERROR webdriver: Request failed with status 405 due to unknown method: Not implemented yet for script.
unknown method: Not implemented yet for script.
    loginPage: launch 
      I see app is installed "com.xxx"
      I wait for element "LOGIN", 5          // LOGIN element can't be located now
  ✖ FAILED in 7387ms

App.T&C Page --
  T&C page open test should be passed
2021-05-12T15:30:24.092Z ERROR webdriver: Request failed with status 405 due to unknown method: Not implemented yet for script.
unknown method: Not implemented yet for script.
    loginPage: launch 
      I see app is installed "com.xxx"
      I wait for element "LOGIN", 5               // LOGIN element can't be located now
  ✖ FAILED in 7339ms


-- FAILURES:

  1) App.Home page
       "before each" hook: Before for "Home page launch should be passed":
     element (LOGIN) still not present on page after 5 sec
      at /Users/qa1/repo/local/codeceptjs-appium-mobile/node_modules/webdriverio/build/commands/browser/waitUntil.js:66:23
      at async Browser.wrapCommandFn (node_modules/@wdio/utils/build/shim.js:78:29)
  
  Scenario Steps:
  - I.waitForElement("LOGIN", 5) at Object.launch (./tests/pages/Login.js:17:7)
  - I.seeAppIsInstalled("com.xxx") at Object.launch (./tests/pages/Login.js:16:7)
  

  2) App.T&C Page
       "before each" hook: Before for "T&C page open test should be passed":
     element (LOGIN) still not present on page after 5 sec
      at /Users/qa1/repo/local/codeceptjs-appium-mobile/node_modules/webdriverio/build/commands/browser/waitUntil.js:66:23
      at async Browser.wrapCommandFn (node_modules/@wdio/utils/build/shim.js:78:29)
  
  Scenario Steps:
  - I.waitForElement("LOGIN", 5) at Object.launch (./tests/pages/Login.js:17:7)
  - I.seeAppIsInstalled("com.xxx") at Object.launch (./tests/pages/Login.js:16:7)
  


  FAIL  | 1 passed, 2 failed   // 44s

Beside the above issue, from the log get the webdriver issue as well:

ERROR webdriver: Request failed with status 405 due to unknown method: Not implemented yet for script.

unknown method: Not implemented yet for script.

Could you kindly help to provide the solution for these issues in advance?

Thanks.

I solved the problem by adding switchToNative() function when the webview test completed.

After(async ({I}) => {
  I.switchToNative();
});

and the appium service start with parameters: --allow-insecure chromedriver_autodownload, so the appium start completed command is:

appium --allow-insecure chromedriver_autodownload