npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@redbuck/h5-handler

v1.0.4

Published

一个用于辅助`miniprogram-automator`的web操作库。 解决了小程序自动化测试中,无法操作小程序内嵌h5页面的问题。 基于websocket,在测试用例中,创建服务端。 在待测试的h5页面,引入客户端。

Downloads

3

Readme

简介

一个用于辅助miniprogram-automator的web操作库。
解决了小程序自动化测试中,无法操作小程序内嵌h5页面的问题。
基于websocket,在测试用例中,创建服务端。
在待测试的h5页面,引入客户端。

安装

npm install @redbuck/h5-handler

使用

测试用例(node端)

api设计接近miniprogram-automator

const automator = require("miniprogram-automator");
const path = require("path");
const { URL } = require("url");
const assets = (_path) => path.resolve(__dirname, _path);
const H5Handler = require("@redbuck/h5-handler/server").default;

const SOCKET_CONFIG = {
    port: 5001,
    key: "testing"
  }

;(async () => {
  const miniProgram = await automator.launch({
    projectPath: "to/path/projectPath"
  });
  const h5Sever = new H5Handler(SOCKET_CONFIG);
  h5Sever.listen();
  
  // 0. 处理小程序连接,告知客户端如何连接服务端
  const h5link = '/page/h5?url=' + encodeURIComponent(h5Sever.processLink('http://localhost:8080/hello?world=0'))

  // 1. 用小程序的webview页面打开待测试h5链接
  await miniProgram.reLaunch(h5link);

  // 2. 等待h5连接成功
  await h5Sever.connected();
  
  // 3. 连接成功,页面还需要加载,等待期待的元素渲染完成
  await h5Sever.waitFor("#web-app");
  
  // 4. 获取客户端所在页面的元素并进行操作
  const el = await h5Sever.$("#some-el-id"); // return {payload, click}
  const ok = await el?.click(); // return 'click:ok'
  console.log(el?.payload.text, ok);
 
  // 5. 关闭服务端
  h5Sever.stop();
  await miniProgram.close();
})();

客户端

在应用入口引入即可。

// main.js
import '@redbuck/h5-handler'