当前位置:首页 » 《随便一记》 » 正文

AI测试|颠覆客户端UI自动化?别担心,你还不会失业!AppAgent框架简单试用

27 人参与  2024年02月18日 13:26  分类 : 《随便一记》  评论

点击全文阅读


2024软件测试面试刷题,这个小程序(永久刷题),靠它快速找到工作了!(刷题APP的天花板)-CSDN博客文章浏览阅读2k次,点赞85次,收藏11次。你知不知道有这么一个软件测试面试的刷题小程序。里面包含了面试常问的软件测试基础题,web自动化测试、app自动化测试、接口测试、性能测试、自动化测试、安全测试及一些常问到的人力资源题目。最主要的是他还收集了像阿里、华为这样的大厂面试真题,还有互动交流板块……https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5501

01 AppAgent会成为新的趋势吗?

近日,腾讯团队发表了一篇论文,并开源了一款基于大语言模型的,用于手机端执行复杂任务的多模态智能代理框架——AppAgent。该框架设计的初衷,是让 AI 智能体能自己操作手机,完成特定的任务,这一创新技术引起了广泛关注。

图片

项目地址:https://appagent-official.github.io/

开源地址:https://github.com/mnotgod96/AppAgent

论文地址:https://arxiv.org/abs/2312.13771

根据该论文的说明,大型语言模型(LLM)的最新进展促使人们创建了能够执行复杂任务的智能代理。

论文介绍了一种新颖的基于 LLM 的多模态代理框架,旨在操作智能手机应用程序。

AppAgent框架使代理能够通过简化的操作空间来操作智能手机应用,模仿人类的交互方式,如点击和轻扫。这种新颖的方法绕过了对系统后端访问的需求,从而扩大了其在各种应用程序中的适用性。代理功能的核心是其创新的学习方法。该代理通过自主探索或观察人类演示来学习导航和使用新应用。这个过程会生成一个知识库,代理在执行不同应用程序的复杂任务时可以参考这个知识库。

为了证明我们的代理的实用性,我们对 10 种不同应用中的 50 个任务进行了广泛测试,包括社交媒体、电子邮件、地图、购物和复杂的图像编辑工具。测试结果肯定了我们的代理在处理各种高级任务方面的能力。

图片

AppAgent 的能力展示。AppAgent 是一种由大型语言模型驱动的高级多模态代理,能够掌握并利用 ANY 应用程序执行复杂的任务。它通过直观的点击和轻扫手势与应用程序进行交互,模仿人类的动作。

图片

X平台(原Twitter)科技大V“AK”也转发了这篇论文,腾讯团队论文作者Chi Zhang转发表示感谢,并公布了这一项目的一个重大更新:AppAgent现在支持Android模拟器,建议没有Android设备的的研究人员可以尝试一下!

02 AppAgent简单试用

以下为TesterHome社区的小伙伴的试用总结:

每一次有自动化的新工具问世,就有一堆人会说:“啊呀呀呀,测试要失业了。” 几天前 AppAgent 出来时,嗅觉灵敏的自媒体就开始搬运,然后剑锋直指测试工程师,于是咱们又失业了一次。因为团队内部对应用自动化测试也有诉求,所以第一时间就在自己电脑上跑起来看看。

安装步骤

安装很简单,我用的是 Windows 11 64bit,Android 环境已经装好(其实只要装了 adb 就可以了),python 环境也安装好了(我的 python 环境用的是 conda,大家可以自行百度)。然后把代码下载下来,pip install -r requirements.txt 安装好依赖就可以用了。

英语好的,直接看:https://github.com/mnotgod96/AppAgent

运行前配置

其实就是因为它用了 openAI 的 Gpt-4-vision-preview 模型,所以咱们必须得有 openAI 的收费账户,然后拿到对应的 OPENAI_API_KEY。对应 AppAgent 的配置文件 config.yaml

...OPENAI_API_BASE: "https://api.openai.com/v1/chat/completions"OPENAI_API_KEY: "sk-xxxx"  # Set the value to sk-xxx if you host the openai interface for open llm modelOPENAI_API_MODEL: "gpt-4-vision-preview"  # The only OpenAI model by now that accepts visual input...

这些参数会在 model.py 里调用,

ask_gpt4v 方法:这个方法是和 openAI 交互的方法。

def ask_gpt4v(content):   headers = {       "Content-Type": "application/json",       "Authorization": f"Bearer {configs['OPENAI_API_KEY']}"   }   payload = {       "model": configs["OPENAI_API_MODEL"],       "messages": [           {               "role": "system",               "content": content           }       ],       "temperature": configs["TEMPERATURE"],       "max_tokens": configs["MAX_TOKENS"]   }   response = requests.post(configs["OPENAI_API_BASE"], headers=headers, json=payload)   print_with_color("resp: ", response)   if "error" not in response.json():       usage = response.json()["usage"]       prompt_tokens = usage["prompt_tokens"]       completion_tokens = usage["completion_tokens"]       print_with_color(f"Request cost is "                        f"${'{0:.2f}'.format(prompt_tokens / 1000 * 0.01 + completion_tokens / 1000 * 0.03)}",                        "yellow")   return response.json()

从 openAI 回来的数据会在 parse_explore_rsp 里进行解析,我感觉这个方法是最重要的,它利用 openAI 的 Thought/Action/Action Input/Observation 机制,对结构化的返回进行解析。很多这种 agent 其实都是基于这个机制,openai 的这块做的比较好,每次都能按照这个模式来给你返回,所以目前来说插件体系啥的也只有 openai 的搞起来了(From 挺神)。这里也挺有意思的,本来我想 openAI 太贵,AppAgent 调用一次,0.02 刀的样子,想换成阿里云的通义千问,翻了一遍文档,似乎没有 Thought/Action/Action Input/Observation 机制,这个我不专业,有懂的同学可以指正下。

所以这里话又说回来了,你还得花这个 openAI 的钱,否则你得大改 APPAgent 的代码。

图片

运行

运行很简单,按官方文档,先 learn 再 run。我这里拿 CSDN 做例子,先在手机上把 CSDN 打开,然后执行 python .\learn.py

图片

这里我选 human demonstration,autonomous exploration 没时间跑。在终端输入2,回车,就会进入下一步:

What is the name of the target app?CSDNWarning! No module named 'sounddevice'Warning! No module named 'matplotlib'Warning! No module named 'keras'List of devices attached:['42954ffb']Device selected: 42954ffbScreen resolution of 42954ffb: 1440x3216

这里会通过 adb 命令,把设备信息拿回来。APPAgent 里自己封装了 adb 命令,比如点击就是用的 adb shell input tap 坐标,比较原始(我一开始以为会封装个啥 Appium 之类的),在文件 and_controller.py 里。这些信息打印好之后,会立刻让你输入你后面动作的描述。这里我就写 “search for testerhome”,然后回车,就会弹出一个界面来。

Please state the goal of your following demo actions clearly, e.g. send a message to Johnsearch for testerhome(然后回车,就会弹出一个界面来,看英语说的,红色的是可以点击的,蓝色的是可以滚动的,看下面这个图。)All interactive elements on the screen are labeled with red and blue numeric tags. Elements labeled with red tags are clickable elements; elements labeled with blue tags are scrollable elements.

图片

我们鼠标聚焦到图片之后,按回车,图片就会消失,接着提示我们就可以根据可以点击的地方,来操作,比如这里搜索的按钮是25,那我就需要点击25这个元素。

Choose one of the following actions you want to perform on the current screen:tap, text, long press, swipe, stoptapWhich element do you want to tap? Choose a numeric tag from 1 to 83:25

这个时候,点击就成功了,会再把点击搜索按钮之后的界面截图出来,

图片

接下来都是一样的操作,总共 5 个步骤。

Which element do you want to tap? Choose a numeric tag from 1 to 14:3Choose one of the following actions you want to perform on the current screen:tap, text, long press, swipe, stoptextWhich element do you want to input the text string? Choose a numeric tag from 1 to 14:3Enter your input text below:testerhomeChoose one of the following actions you want to perform on the current screen:tap, text, long press, swipe, stoptapWhich element do you want to tap? Choose a numeric tag from 1 to 15:4Choose one of the following actions you want to perform on the current screen:tap, text, long press, swipe, stopstopDemonstration phase completed. 5 steps were recorded.

然后就是 chatGPT 开始工作了,

Warning! No module named 'sounddevice'Warning! No module named 'matplotlib'Warning! No module named 'keras'Starting to generate documentations for the app CSDN based on the demo demo_CSDN_2023-12-24_20-46-47Waiting for GPT-4V to generate documentation for the element net.csdn.csdnplus.id_ll_order_tag_net.csdn.csdnplus.id_iv_home_bar_search_1resp:Request cost is $0.00Documentation generated and saved to ./apps\CSDN\demo_docs\net.csdn.csdnplus.id_ll_order_tag_net.csdn.csdnplus.id_iv_home_bar_search_1.txtWaiting for GPT-4V to generate documentation for the element android.widget.LinearLayout_1008_144_net.csdn.csdnplus.id_et_search_content_1resp:Request cost is $0.00Documentation generated and saved to ./apps\CSDN\demo_docs\android.widget.LinearLayout_1008_144_net.csdn.csdnplus.id_et_search_content_1.txtWaiting for GPT-4V to generate documentation for the element android.widget.LinearLayout_1008_144_net.csdn.csdnplus.id_et_search_content_1resp:Request cost is $0.00Documentation generated and saved to ./apps\CSDN\demo_docs\android.widget.LinearLayout_1008_144_net.csdn.csdnplus.id_et_search_content_1.txtWaiting for GPT-4V to generate documentation for the element android.widget.LinearLayout_1440_176_net.csdn.csdnplus.id_tv_search_search_2resp:Request cost is $0.00Documentation generated and saved to ./apps\CSDN\demo_docs\android.widget.LinearLayout_1440_176_net.csdn.csdnplus.id_tv_search_search_2.txtDocumentation generation phase completed. 4 docs generated.

最后生成的样子是这样的:

图片

其中 task_desc 就是我们前面的 search for testerhome,record 是每一步的命令的合并,然后有打标签的截图等等。

到这里,我们的学习就完成了,下面就要运行了, python run.py

Warning! No module named 'sounddevice'Warning! No module named 'matplotlib'Warning! No module named 'keras'Welcome to the deployment phase of AppAgent!Before giving me the task, you should first tell me the name of the app you want me to operate and what documentation base you want me to use. I will try my best to complete the task without your intervention. First, please enter the main interface of the app on your phone and provide the following information.What is the name of the target app?CSDNWarning! No module named 'sounddevice'Warning! No module named 'matplotlib'Warning! No module named 'keras'Documentations generated from human demonstration were found for the app CSDN. The doc base is selected automatically.List of devices attached:['42954ffb']Device selected: 42954ffbScreen resolution of 42954ffb: 1440x3216Please enter the description of the task you want me to complete in a few sentences:search for testerhomeRound 1Documentations retrieved for the current interface:Documentation of UI element labeled with the numeric tag '25':This UI element is clickable. To assist you effectively, I'll need to see the screenshots of the mobile app you're referring to. Please provide the images showing the UI element before and after it has been tapped.Thinking about what to do in the next step...resp:Request cost is $0.01Observation:The image shows a smartphone screen with a Google search bar at the top. There are various app icons on the screen, and the UI element labeled '25' appears to be the Google search bar.Thought:To complete the given task, I should tap on the Google search bar to bring up the keyboard and enter the search term "testerhome."Action:tap(25)Summary:I have tapped on the Google search bar to initiate a search for "testerhome."Round 2Documentations retrieved for the current interface:Documentation of UI element labeled with the numeric tag '3':This UI element is clickable. I'm sorry, but I can't provide assistance without the images being displayed. If you can provide the screenshots of the mobile app before and after tapping the UI element, I would be able to help you describe its functionality.This UI element can receive text input. The text input is used for the following purposes: I'm sorry, but I can't provide assistance without the images being displayed. If you can provide the screenshots you mentioned, I'd be happy to help describe the functionality of the UI element labeled with the number 3.Documentation of UI element labeled with the numeric tag '4':This UI element is clickable. I'm sorry, but I can't provide assistance without the images being displayed. If you can provide the screenshots you mentioned, I'd be happy to help you with the description of the UI element.Thinking about what to do in the next step...resp:Request cost is $0.01Observation:I'm sorry, but I cannot provide observations without an image being displayed. If you can provide the screenshot you mentioned, I'd be happy to assist you further.Thought:Since I cannot see the image, I am unable to determine the next step to complete the given task.Action:FINISHSummary:I have tapped on the Google search bar to initiate a search for "testerhome," but without the image, I cannot proceed further with the task.Task completed successfully

这个过程,其实就是拿着前面 learn 的时候,记录的这些信息,去组成 prompt 模板,再去调用 chatGPT。代码是下图,里面的 image_url,就是打标签的图片。把某一步的操作和对应的图片提交给 GPT。

图片

我前面运行 run.py 里面第一步就成功的把图片和 tap 的操作给传给 chatGPT 了,GPT 说 tap(25) 。但是大家再往下看的时候,就发现 GPT 开始胡说八道了,所以很遗憾,我 learn 时候的操作,并没有在 run 的时候重放出来。

试用总结

至此,基本把 APPAgent 跑了一遍了,我和群友说,demo 很性感,现实很骨感,显然 chatGPT 对 CSDN 不够了解。在我看来,现阶段的 AppAgent 只不过是一个客户端录制回放的,而且非常简陋的工具。但是思路非常不错,我自己组里准备着手改造,看看能不能真正用起来。

针对TesterHome社区小伙伴的本次试用,AppAgent的作者之一,也在TesterHome社区进行了回应。所以,对于AppAgent这个创新项目,大家可以试用起来,有什么问题,也可以在TesterHome社区发帖、留言,AppAgent项目官方的同学们也都会看得到。

行动吧,在路上总比一直观望的要好,未来的你肯定会感谢现在拼搏的自己!如果想学习提升找不到资料,没人答疑解惑时,请及时加入群: 786229024,里面有各种测试开发资料和技术可以一起交流哦。

最后: 下方这份完整的软件测试视频教程已经整理上传完成,需要的朋友们可以自行领取【保证100%免费】在这里插入图片描述
软件测试面试文档
我们学习必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有字节大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。在这里插入图片描述
在这里插入图片描述

在这里插入图片描述


点击全文阅读


本文链接:http://zhangshiyu.com/post/68944.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1