From cdf9b065f9481525b0fb7351a8b9ed73e3f23b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E5=98=89=E8=BE=89?= <961978925@qq.com> Date: Mon, 9 Dec 2024 14:36:58 +0800 Subject: [PATCH] setWebDebuggingAccess error --- .../src/main/ets/dataSources/dataSources.ets | 4 +++ .../SetWebDebuggingAccessError.ets | 27 +++++++++++++++++++ .../resources/base/profile/main_pages.json | 3 ++- ...oller_SetWebDebuggingAccessError.test.ets} | 10 ++++--- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 xtstemplate/entry/src/main/ets/pages/WebController/SetWebDebuggingAccessError.ets rename xtstemplate/entry/src/ohosTest/ets/test/{WebController_SetWebDebuggingAccess.test.ets => WebController_SetWebDebuggingAccessError.test.ets} (87%) diff --git a/xtstemplate/entry/src/main/ets/dataSources/dataSources.ets b/xtstemplate/entry/src/main/ets/dataSources/dataSources.ets index 3a22faf..d828733 100644 --- a/xtstemplate/entry/src/main/ets/dataSources/dataSources.ets +++ b/xtstemplate/entry/src/main/ets/dataSources/dataSources.ets @@ -19,6 +19,10 @@ export const DataSources:Array=[ title:"WebController_SetWebDebuggingAccessFalse", path:"pages/WebController/SetWebDebuggingAccessFalse" }, + { + title:"WebController_SetWebDebuggingAccessError", + path:"pages/WebController/SetWebDebuggingAccessError" + }, { title:"WebController_PageDown", path:"pages/WebController/PageDown" diff --git a/xtstemplate/entry/src/main/ets/pages/WebController/SetWebDebuggingAccessError.ets b/xtstemplate/entry/src/main/ets/pages/WebController/SetWebDebuggingAccessError.ets new file mode 100644 index 0000000..4d2dccf --- /dev/null +++ b/xtstemplate/entry/src/main/ets/pages/WebController/SetWebDebuggingAccessError.ets @@ -0,0 +1,27 @@ +// xxx.ets +import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { Back } from '../../components/goBack'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + @State errorMsg: string = ""; + aboutToAppear(): void { + try { + webview.WebviewController.setWebDebuggingAccess(undefined); + } catch (error) { + this.errorMsg = `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`; + console.error(this.errorMsg); + } + } + + build() { + Column() { + Back() + Text(`errorMsg:${this.errorMsg}`).id("errorCode") + Web({ src: 'https://www.baidu.com', controller: this.controller }) + } + } +} \ No newline at end of file diff --git a/xtstemplate/entry/src/main/resources/base/profile/main_pages.json b/xtstemplate/entry/src/main/resources/base/profile/main_pages.json index 75f21a7..3d371b1 100644 --- a/xtstemplate/entry/src/main/resources/base/profile/main_pages.json +++ b/xtstemplate/entry/src/main/resources/base/profile/main_pages.json @@ -6,6 +6,7 @@ "pages/WebController/SetWebDebuggingAccessTrue", "pages/WebController/PageDown", "pages/WebController/PostUrl", - "pages/WebController/SetWebDebuggingAccessFalse" + "pages/WebController/SetWebDebuggingAccessFalse", + "pages/WebController/SetWebDebuggingAccessError" ] } \ No newline at end of file diff --git a/xtstemplate/entry/src/ohosTest/ets/test/WebController_SetWebDebuggingAccess.test.ets b/xtstemplate/entry/src/ohosTest/ets/test/WebController_SetWebDebuggingAccessError.test.ets similarity index 87% rename from xtstemplate/entry/src/ohosTest/ets/test/WebController_SetWebDebuggingAccess.test.ets rename to xtstemplate/entry/src/ohosTest/ets/test/WebController_SetWebDebuggingAccessError.test.ets index 481ab6b..b4d3348 100644 --- a/xtstemplate/entry/src/ohosTest/ets/test/WebController_SetWebDebuggingAccess.test.ets +++ b/xtstemplate/entry/src/ohosTest/ets/test/WebController_SetWebDebuggingAccessError.test.ets @@ -25,8 +25,8 @@ import { import { Driver, ON, Component } from '@ohos.UiTest'; import { startAbility, stopAbility, waitUiReadyMs } from '../utils/index'; -export default function WebController_SetWebDebuggingAccessTest() { - describe('WebController_SetWebDebuggingAccessTest', () => { +export default function WebController_SetWebDebuggingAccessErrorTest() { + describe('WebController_SetWebDebuggingAccessErrorTest', () => { /** * beforeAll: PrePageControlTest at the test suite level, which are executed before the test suite is executed. */ @@ -42,7 +42,7 @@ export default function WebController_SetWebDebuggingAccessTest() { beforeEach(async () => { const driver: Driver = Driver.create(); await driver.delayMs(waitUiReadyMs); - const TAB: Component = await driver.findComponent(ON.text('WebController_SetWebDebuggingAccess')); + const TAB: Component = await driver.findComponent(ON.text('WebController_SetWebDebuggingAccessError')); await TAB.click(); await driver.delayMs(waitUiReadyMs); }); @@ -75,6 +75,10 @@ export default function WebController_SetWebDebuggingAccessTest() { console.log('SUB_Web_WebView_SetWebDebuggingAccess_Func_0100 test start'); const driver: Driver = Driver.create(); await driver.delayMs(waitUiReadyMs); + + const MY_TIPS: Component = await driver.findComponent(ON.id('errorMsg')); + const errorId: string = await MY_TIPS.getText(); + expect(`${errorId}`).assertContain('401'); }); }); -- Gitee