关于小程序:1000套微信小程序源码开源版附H5小游戏源码及商城源码

4次阅读

共计 3637 个字符,预计需要花费 10 分钟才能阅读完成。

随着微信小程序性能和生态的日益完善,很多企业的产品业务逐步从 App 扩大到微信小程序和微信公众号。随着小程序我的项目页面越来越多,业务逻辑越来越简单,现有的小程序元源码数量和品种不能满足快速增长的业务需要。

残缺源码:y.wxlbyx.icu

但因为小程序自身的一些个性,业界不足成熟欠缺的解决方案,总会呈现各种问题(包含腾讯微信官网提供的自动化工具)。明天咱们要带来的是一些微信小程序自动化测试的最佳实际和教训,包含微信小程序的根本测试技术和操作方法,以及如何应用 appium 的 WebView 测试技术 +ADB 代理来实现微信小程序的自动化测试(可能是目前最实用的小程序自动测试技术),并附上 PHP 版源码。

小程序源码运行环境

平台差别:尽管运行环境很类似,但还是有一些区别:

JavaScript 语法和 API 反对不统一:从语法上来说,开发者能够通过开启 ES6 到 Es5 的性能来防止(详情);此外,applet 根底库内置了必要的 Polyfill 来补救 API 的差别。

wxss 渲染性能不统一:尽管开启款式补全能够防止大部分问题,但倡议开发者须要别离在 IOS 和 Android 上查看小程序的真实性能。

微信小程序技术架构

微信小程序的技术架构如下图所示:


应用 chrome 调试小程序

应用 Chrome 浏览器提供的 inspect 剖析工具,在浏览器中输出如下地址:

chrome://inspect/#devices

应用 Chrome 浏览器查看手机上关上的 WebView 过程和根本信息:

能够应用 chrome inspect 来剖析微信小程序的控制结构和布局:

应用控制台执行您本人的 JavaScript 代码:

小程序性能测试

这里附上一个小程序性能测试图:


微信小程序自动测试


微信小程序自动测试关键步骤

1. 原生自动化模式。

●能够应用 appium 来实现。毛病是管制定位不够精确,无奈深刻小程序;

2、WebView 自动化模式:能够取得更多小程序外部品质数据。

●设置正确的 chromedriver 版本

●设置 chrome 选项并将其传递给 chromedriver

●应用 ADB 代理解决修复 chromedriver 的 bug

3、为什么很多人还不确定?

●低版本的 chromedriver 在高版本的手机上有 bug

●chromedriver 与微信定制的 chrome 内核的连贯实现有问题

源码示例:

  class TestWXMicroWebView:
  #For demonstration convenience, page object mode is not used
  def setup(self):
  caps = {}
  caps["platformName"] = "android"
  Caps ["devicename"] = "programmer Yifan. Com"
  caps["appPackage"] = "com.tencent.mm"
  caps["appActivity"] = "com.tencent.mm.ui.LauncherUI"
  caps["noReset"] = True
  caps['unicodeKeyboard'] = True
  caps['resetKeyboard'] = True
  caps['chromedriverExecutable'] = \
  '/Users/seveniruby/projects/chromedriver/chromedrivers/chromedriver_78.0.3904.11'
  # options = ChromeOptions()
  # options.add_experimental_option('androidProcess', 'com.tencent.mm:appbrand0')
  caps['chromeOptions'] = {'androidProcess': 'com.tencent.mm:appbrand0'}
  caps['adbPort'] = 5038
  self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
  self.driver.implicitly_wait(30)
  self. driver. find_ Element (by. XPath, "// * [@ text ='address book']")
  self.driver.implicitly_wait(10)
  self.enter_micro_program()
  print(self.driver.contexts)
  def enter_micro_program(self):
  #Native automated testing
  size = self.driver.get_window_size()
  self.driver.swipe(size['width'] * 0.5, size['height'] * 0.4, size['width'] * 0.5, size['height'] * 0.9)
  self.driver.find_element(By.CLASS_NAME, 'android.widget.EditText').click()
  self. driver. find_ Element (by. XPath, "// * [@ text ='Cancel'])
  self. driver. find_ element(By.CLASS_NAME, "android.widget.EditText"). send_ Keys ("snowball")
  self.driver.find_element(By.CLASS_NAME, 'android.widget.Button')
  self.driver.find_element(By.CLASS_NAME, 'android.widget.Button').click()
  self. driver. find_ Element (by. XPath, "// * [@ text ='optional'])
  def find_top_window(self):
  for window in self.driver.window_handles:
  print(window)
  if ":VISIBLE" in self.driver.title:
  print(self.driver.title)
  else:
  self.driver.switch_to.window(window)
  def test_search_webview(self):
  #Enter WebView
  self.driver.switch_to.context('WEBVIEW_xweb')
  self.driver.implicitly_wait(10)
  self.find_top_window()
  #CSS positioning
  self.driver.find_element(By.CSS_SELECTOR, "[src*=stock_add]").click()
  #Wait for new window
  WebDriverWait(self.driver, 30).until(lambda x: len(self.driver.window_handles) > 2)
  self.find_top_window()
  self.driver.find_element(By.CSS_SELECTOR, "._input").click()
  #Input
  self.driver.switch_to.context("NATIVE_APP")
  ActionChains(self.driver).send_keys("alibaba").perform()
  #Click
  self.driver.switch_to.context('WEBVIEW_xweb')
  self.driver.find_element(By.CSS_SELECTOR, ".stock__item")
  self.driver.find_element(By.CSS_SELECTOR, ".stock__item").click()

小程序自源码开发须要逾越的几个关卡:

●WebView 开关 /x5 内核调试开关

●chromeoption 选项须要填写

●WebView 版本和 chromedriver 版本对应问题

●chrome 驱动低版本须要修复 ps 命令的 bug

●上下文 API 有肯定提早,须要期待

正文完
 0