Не удалось переключить контекст на веб-просмотр при автоматизации гибридных мобильных приложений с использованием webdriAndroid

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Anonymous
 Не удалось переключить контекст на веб-просмотр при автоматизации гибридных мобильных приложений с использованием webdri

Сообщение Anonymous »

Я пытаюсь настроить автоматизацию веб-просмотра для своего приложения, которое работает на устройствах Android и iOS как гибридное приложение (написанное в React Native0
Во время запуска моего кода автоматизацииЯ пытаюсь переключить веб-просмотр с помощью
const webviewName = `WEBVIEW_${packageName}`;
await driver.switchContext(webviewName);

На устройствах Android 14 переключение на веб-просмотр и выполнение следующей строки работает должным образом.
Когда я снова запускаю то же самое в Android 13, 15 устройств, не удается переключиться на контекст веб-просмотра, хотя веб-просмотр на моем устройстве активен.
Я взял этот код с github
/**
* Custom implementation to switch to a webview for Android and iOS
*/
async switchToContext({ context, title, url }: { context: ContextType, title?: string, url?: string }) {
if (context === CONTEXT_REF.NATIVE_APP) {
return driver.switchContext(CONTEXT_REF.NATIVE_APP);
}

// Title and url are optional, but if they are provided we can use them to find the correct webview.
// We can't only rely on the context name due to the fact that we can have multiple webviews which
// could have different titles/urls
if (!title && !url) {
console.warn('\nTo get the best result, provide a title and, or url which will be used to find the correct webview. The more information the bigger the chance it will find the correct webview.\n');
}

// Get the contexts with our custom method
const currentContexts = await this.getCurrentContexts();

let matchingContext;
let packageName;

// This is where the magic happens, we are going to find the correct context(pae) to switch to for iOS or Android.
if (driver.isIOS) {
matchingContext = this.findMatchingContext({ contexts: currentContexts, identifier: BUNDLE_ID, title, url });
} else {
packageName = await driver.getCurrentPackage();
// 1. To find the correct webview page for Android we need to switch to the webview first
const webviewName = `WEBVIEW_${packageName}`;
**await driver.switchContext(webviewName);**
// 2. Now we need to find the correct page inside the webview
matchingContext = this.findMatchingContext({ contexts: currentContexts, identifier: packageName, title, url });
}

if (!matchingContext) {
throw new Error(this.generateNonMatchingErrorMessage({
identifier: driver.isIOS ? BUNDLE_ID :
packageName as string,
title,
url,
}));
}

// For iOS we can just use the `driver.switchContext` method to switch to the webview,
// but for Android we are already in the webview. We now need to switch to the correct page inside the webview
const switchFunction = driver.isIOS ? driver.switchContext.bind(driver) : driver.switchToWindow.bind(driver);
// Now switch to the correct context
return switchFunction(matchingContext.id);
}

Справочный проект по автоматизации веб-просмотра, который я взял с GitHub:
https://github.com/webdriverio/appium-b ... blob/main/ tests/helpers/WebView.ts
Моя ошибка на устройствах Android 13 и 15:
[0-0] 2024-10-25T08:06:48.075Z INFO webdriver: COMMAND switchContext("WEBVIEW_com.example.app”)
[0-0] 2024-10-25T08:06:48.075Z INFO webdriver: [POST] http://127.0.0.1:4445/session/f2afefe4- ... 45/context
[0-0] 2024-10-25T08:06:48.075Z INFO webdriver: DATA { name: 'WEBVIEW_com.example.app' }
[0-0] Error of test: Error: waitUntil condition failed with the following reason: WebDriverError: This operation was aborted when running "context" with method "POST" and args "{"name":"WEBVIEW_com.example.app"}"

] at (/Users/vk/login/mobile-automation/node_modules/webdriverio/build/index.js:4684:11)
[0-0] at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
[0-0] at async Browser.wrapCommandFn (/Users/vk/login/mobile-automation/node_modules/@wdio/utils/build/index.js:1380:23)
[0-0] at async WebView.switchToContext (/Users/vk/login/mobile-automation/source/webview.ts:175:9)
[0-0] at async WebView.waitForWebsiteLoaded (/Users/vk/login/mobile-automation/source/webview.ts:320:9)
[0-0] at async UserContext. (/Users/vk/login/mobile-automation/source/specs/tests//sign-in-test.spec.ts:40:13)
[0-0] at async UserContext.executeAsync (/Users/vk/login/mobile-automation/node_modules/@wdio/utils/build/index.js:1500:20)
[0-0] at async UserContext.testFrameworkFnWrapper (/Users/vk/login/mobile/node_modules/@wdio/utils/build/index.js:1571:14)


Подробнее здесь: https://stackoverflow.com/questions/791 ... ation-usin
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Android»