【每日学点HarmonyOS Next知识】压力测试、Web组件拦截器、nfc开关状态、定位能力、rn支持的三方库

234 阅读2分钟

1、HarmonyOS的wukong 支持运行python脚本进行压力或者常规测试吗?

  1. Python脚本调用hdc命令,执行hdc shell wukong XXX
  2. wukong只支持稳定性压测,普通测试建议使用arkxtest测试框架

2、Web组件页面内跳转时自定义WebHeader问题?

如果有比较多的业务是用的H5来实现,页面加载时,在httpHeader中会包含一些信息,比如用户信息,当前app主题信息等,HarmonyOS 上首次加载网页的时候可以用loadUrl带上header,但是在页面再次跳转时无法加上header信息,想问下这种场景有什么解决方案。目前尝试过在onInterceptRequest拦截请求再用http去发送请求带上header的方式,但是没有效果

针对ArkTS中使用webview,设置webHeader。可参考链接:developer.huawei.com/consumer/cn…

使用web的onInterceptRequest方法可以拦截 示例代码:

import web_webview from@ohos.web.webview@Entry
@Component
struct WebComponent {
  controller: web_webview.WebviewController = new web_webview.WebviewController()
  build() {
    Column() {
      Web({ src: $rawfile(‘i.html’), controller: this.controller })
        .onInterceptRequest((event) => {
          if (event) {
            console.log(‘urldddd:’ + event.request.getRequestUrl())
          }
          return null
        })
    }
  }
}
html:
<html>
<head>
  <script src="https://xxx.com/vue/dist/vue.js"></script>
  <script src="https://xxx.com/vue-router/dist/vue-router.js"></script>
  </head>
  <body>
  <div id="app">
  <h1>Vue Router 示例</h1>
  <ul>
  <li><router-link to="/">首页</router-link></li>
  <li><router-link to="/about">关于</router-link></li>
  </ul>
  <router-view></router-view>
  </div>
  <script>
  // 定义两个组件
  var Home = {template: '<div><h2>这是首页</h2><p>欢迎来到我的网站</p></div>' };
var About = {template: '<div><h2>这是关于页面</h2><p>Bing是一个智能的搜索引擎,可以帮你找到你想要的信息</p></div>' };
// 创建一个路由器实例 
var router = new VueRouter({
  // 定义路由规则 routes:
  [{ path: '/', component: Home },
  { path: '/about', component: About }]
});
// 创建和挂载根实例
var app = new Vue({el: '#app', router: router });
</script>
  </body>
  </html>

3、HarmonyOS 如何判断系统nfc的开关状态?

可以查询当前NFC状态,以及监听NFC状态变化,参考链接:developer.huawei.com/consumer/cn…

测试验证controller.isNfcOpen()返回值正确的,demo如下:

import controller from '@ohos.nfc.controller'

@Entry
@Component
struct TestNetConnectionPage {

  @State monitorNfcState: string = '';
  @State queryNfcState: string = '';
  @State isNfcOpen: boolean = false;

  aboutToAppear(): void {

    if (canIUse("SystemCapability.Communication.NFC.Core")) {
      controller.on("nfcStateChange", state => {
        this.monitorNfcState = state.toString();
      });
    }
  }

  build() {
    Row() {
      Column() {

        Row() {
          Text('监听NFC状态:').width('50%');
          Text(this.monitorNfcState).width('50%');
        }.alignSelf(ItemAlign.Start);

        if (canIUse("SystemCapability.Communication.NFC.Core")) {
          Row() {
            Button('查询NFC状态:').width('50%').onClick(() => {
              this.queryNfcState = controller.getNfcState().toString();
            });
            Text(this.queryNfcState).width('50%');
          }.alignSelf(ItemAlign.Start);
        }

        if (canIUse("SystemCapability.Communication.NFC.Core")) {
          Row() {
            Button('查询NFC开关:').width('50%').onClick(() => {
              this.isNfcOpen = controller.isNfcOpen();
            });
            Text(this.isNfcOpen + '').width('50%');
          }.alignSelf(ItemAlign.Start);
        }
      }
      .width('100%')
    }
    .height('100%')
  }
}

4、HarmonyOS 关于定位能力,有没有免费的kit提供?

关于定位,可以参照以下文档:developer.huawei.com/consumer/cn…

5、HarmonyOS 现在支持的rn第三方库有哪些?

当前已支持的适配RN三方库:github.com/orgs/react-…