收藏
回答

【minium】config.json文件不生效怎么办?

使用Windows电脑进行真机运行,根目录下添加了config.json文件,内容如下:

{
  "project_path": "C:\\Users\\wb.chenchunzhi20\\Desktop\\小程序测试包\\测试环境\\V4.2.1测试",
  "dev_tool_path": "C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\.cli.bat",
  "platform": "Android"
}

first.test.py文件中的代码如下:

import minium

# mini = minium.Minium({
#     # 小程序项目目录地址,这里是Windows系统的目录
#     "project_path": "C:\\Users\\wb.chenchunzhi20\\Desktop\\小程序测试包\\测试环境\\V4.2.1测试",
#     # 开发者工具cli地址,Windows系统就是默认这个路径
#     "dev_tool_path": "C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.bat",
#     "platform": "Android"
#
# })

import minium
class ExceptionTest(minium.MiniTest):

    def test_get_current_page(self):
        self.page.get_element('view', inner_text='加入').click()


if __name__ == '__main__':
    ExceptionTest().test_get_current_page()

运行first_test.py无法调用微信开发者工具,报错内容如下:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.1\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/wb.chenchunzhi20/Desktop/UI自动化/小程序自动化/wechatDemo序自动化/wechatDemo/test/first_test.py", line 22, in <module>
    ExceptionTest().test_get_current_page()
  File "C:/Users/wb.chenchunzhi20/Desktop/UI自动化/小程序自动化/wechatDemo序自动化/wechatDemo/test/first_test.py", line 18, in test_get_current_page
    self.page.get_element('view', inner_text='加入').click()
  File "D:\Python3\lib\site-packages\minium-1.0.6-py3.9.egg\minium\framework\assertbase.py", line 346, in __getattribute__
    attr = super().__getattribute__(item)
  File "D:\Python3\lib\site-packages\minium-1.0.6-py3.9.egg\minium\framework\minitest.py", line 656, in page
    return self.mini.app.get_current_page()
AttributeError: 'NoneType' object has no attribute 'app'

将first.test.py上边注释掉的内容打开后,可以正常真机运行,但是依旧会报以下错误:

received async msg: 9dfd40ee-6d1c-4ecf-b234-e7634084aada
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.1\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/wb.chenchunzhi20/Desktop/UI自动化/小程序自动化/wechatDemo序自动化/wechatDemo/test/first_test.py", line 22, in <module>
    ExceptionTest().test_get_current_page()
  File "C:/Users/wb.chenchunzhi20/Desktop/UI自动化/小程序自动化/wechatDemo序自动化/wechatDemo/test/first_test.py", line 18, in test_get_current_page
    self.page.get_element('view', inner_text='加入').click()
  File "D:\Python3\lib\site-packages\minium-1.0.6-py3.9.egg\minium\framework\assertbase.py", line 346, in __getattribute__
    attr = super().__getattribute__(item)
  File "D:\Python3\lib\site-packages\minium-1.0.6-py3.9.egg\minium\framework\minitest.py", line 656, in page
    return self.mini.app.get_current_page()
AttributeError: 'NoneType' object has no attribute 'app'

这种情况下我想问以下问题:

1.config.json文件如何生效?

2.'NoneType' object has no attribute 'app'这个问题怎么解决?

回答关注问题邀请回答
收藏

3 个回答

  • yopofeng
    yopofeng
    2021-05-19

    请参考https://minitest.weixin.qq.com/#/minium/Python/framework/example

    2021-05-19
    有用
    回复
  • 墨言
    墨言
    2021-07-11

    同问,出现AttributeError: 'NoneType' object has no attribute 'trigger'是什么原因?如何解决?


    2021-07-11
    有用
    回复 1
    • 阳光正好
      阳光正好
      2021-12-26
      打印一下你的element,查看定位到的元素是否正确呢
      2021-12-26
      回复
  • 街灯以北
    街灯以北
    2021-05-19

    配置有问题吧,可以看看官方文档。

    2021-05-19
    有用
    回复 4
    • 风格随心、
      风格随心、
      2021-05-19
      这一块也配置了,运行后还是无法调用开发者工具:
      2021-05-19
      回复
    • 街灯以北
      街灯以北
      2021-05-20回复风格随心、
      cli工具的路径是不是有问题,我看你截图上写的是   .cli.bat  前面没有.
      2021-05-20
      回复
    • 风格随心、
      风格随心、
      发表于移动端
      2021-05-20回复街灯以北
      那个·我去掉了,也不行,但是通过命令行运行可以,通过运行python文件运行就不行
      2021-05-20
      回复
    • 街灯以北
      街灯以北
      2021-05-24回复风格随心、
      没懂你的意思,不过日志打印级别可以再config文件中设置,debug_mode,根据你的需要设置不同级别
      2021-05-24
      回复
登录 后发表内容