{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/",
  "atlas": "https://www.pystone.net/?node=chatgpt-game-autotest-more-cases#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases.md",
  "context": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:chatgpt-game-autotest-more-cases",
  "slug": "chatgpt-game-autotest-more-cases",
  "title": "【ChatGPT】游戏自动化测试实践案例 - 更多案例",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "【ChatGPT】游戏自动化测试实践案例 更多案例",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "99-资料来源、摘录与归档",
  "tags": [],
  "mocs": [],
  "contentHash": "d7be0c3e66d1085acf7b27f7003c30cfcc9552f2bd92cbc2dc78e51a4fa19df8",
  "assets": [],
  "headings": [
    {
      "depth": 1,
      "text": "【ChatGPT】游戏自动化测试实践案例 - 更多案例",
      "anchor": "chatgpt游戏自动化测试实践案例---更多案例",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#chatgpt%E6%B8%B8%E6%88%8F%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E5%AE%9E%E8%B7%B5%E6%A1%88%E4%BE%8B---%E6%9B%B4%E5%A4%9A%E6%A1%88%E4%BE%8B"
    },
    {
      "depth": 4,
      "text": "目标：测试游戏的可用性和稳定性",
      "anchor": "目标测试游戏的可用性和稳定性",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E7%9B%AE%E6%A0%87%E6%B5%8B%E8%AF%95%E6%B8%B8%E6%88%8F%E7%9A%84%E5%8F%AF%E7%94%A8%E6%80%A7%E5%92%8C%E7%A8%B3%E5%AE%9A%E6%80%A7"
    },
    {
      "depth": 2,
      "text": "检查游戏是否仍然稳定可用 assert poco(\"gamemainui\").exists(), \"游戏崩溃或不稳定！\" except Exception as e:",
      "anchor": "检查游戏是否仍然稳定可用-assert-pocogamemainuiexists-游戏崩溃或不稳定-except-exception-as-e",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E6%A3%80%E6%9F%A5%E6%B8%B8%E6%88%8F%E6%98%AF%E5%90%A6%E4%BB%8D%E7%84%B6%E7%A8%B3%E5%AE%9A%E5%8F%AF%E7%94%A8-assert-pocogamemainuiexists-%E6%B8%B8%E6%88%8F%E5%B4%A9%E6%BA%83%E6%88%96%E4%B8%8D%E7%A8%B3%E5%AE%9A-except-exception-as-e"
    },
    {
      "depth": 4,
      "text": "目标：测试游戏的兼容性",
      "anchor": "目标测试游戏的兼容性",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E7%9B%AE%E6%A0%87%E6%B5%8B%E8%AF%95%E6%B8%B8%E6%88%8F%E7%9A%84%E5%85%BC%E5%AE%B9%E6%80%A7"
    },
    {
      "depth": 2,
      "text": "运行测试脚本 runtestsondevice(device)",
      "anchor": "运行测试脚本-runtestsondevicedevice",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E8%BF%90%E8%A1%8C%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC-runtestsondevicedevice"
    },
    {
      "depth": 4,
      "text": "目标：测试游戏内的教程和引导",
      "anchor": "目标测试游戏内的教程和引导",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E7%9B%AE%E6%A0%87%E6%B5%8B%E8%AF%95%E6%B8%B8%E6%88%8F%E5%86%85%E7%9A%84%E6%95%99%E7%A8%8B%E5%92%8C%E5%BC%95%E5%AF%BC"
    },
    {
      "depth": 2,
      "text": "完成教程任务 completetutorialtask(\"task1\")",
      "anchor": "完成教程任务-completetutorialtasktask1",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E5%AE%8C%E6%88%90%E6%95%99%E7%A8%8B%E4%BB%BB%E5%8A%A1-completetutorialtasktask1"
    },
    {
      "depth": 2,
      "text": "检查是否进入游戏主界面 assert poco(\"gamemainui\").exists(), \"完成教程后未进入游戏主界面！\"",
      "anchor": "检查是否进入游戏主界面-assert-pocogamemainuiexists-完成教程后未进入游戏主界面",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E8%BF%9B%E5%85%A5%E6%B8%B8%E6%88%8F%E4%B8%BB%E7%95%8C%E9%9D%A2-assert-pocogamemainuiexists-%E5%AE%8C%E6%88%90%E6%95%99%E7%A8%8B%E5%90%8E%E6%9C%AA%E8%BF%9B%E5%85%A5%E6%B8%B8%E6%88%8F%E4%B8%BB%E7%95%8C%E9%9D%A2"
    },
    {
      "depth": 4,
      "text": "目标：测试游戏内的社交功能",
      "anchor": "目标测试游戏内的社交功能",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E7%9B%AE%E6%A0%87%E6%B5%8B%E8%AF%95%E6%B8%B8%E6%88%8F%E5%86%85%E7%9A%84%E7%A4%BE%E4%BA%A4%E5%8A%9F%E8%83%BD"
    },
    {
      "depth": 4,
      "text": "示例1：验证登录功能",
      "anchor": "示例1验证登录功能",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E7%A4%BA%E4%BE%8B1%E9%AA%8C%E8%AF%81%E7%99%BB%E5%BD%95%E5%8A%9F%E8%83%BD"
    },
    {
      "depth": 4,
      "text": "示例2：验证登录功能（无效凭证）",
      "anchor": "示例2验证登录功能无效凭证",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E7%A4%BA%E4%BE%8B2%E9%AA%8C%E8%AF%81%E7%99%BB%E5%BD%95%E5%8A%9F%E8%83%BD%E6%97%A0%E6%95%88%E5%87%AD%E8%AF%81"
    },
    {
      "depth": 4,
      "text": "示例3：购买物品",
      "anchor": "示例3购买物品",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E7%A4%BA%E4%BE%8B3%E8%B4%AD%E4%B9%B0%E7%89%A9%E5%93%81"
    },
    {
      "depth": 2,
      "text": "进入商店并购买物品 shopbutton.click()",
      "anchor": "进入商店并购买物品-shopbuttonclick",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E8%BF%9B%E5%85%A5%E5%95%86%E5%BA%97%E5%B9%B6%E8%B4%AD%E4%B9%B0%E7%89%A9%E5%93%81-shopbuttonclick"
    },
    {
      "depth": 2,
      "text": "检查购买结果 purchasesuccessmessage = poco(\"purchasesuccessmessage\")",
      "anchor": "检查购买结果-purchasesuccessmessage-pocopurchasesuccessmessage",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E6%A3%80%E6%9F%A5%E8%B4%AD%E4%B9%B0%E7%BB%93%E6%9E%9C-purchasesuccessmessage-pocopurchasesuccessmessage"
    },
    {
      "depth": 4,
      "text": "示例4：更新个人资料",
      "anchor": "示例4更新个人资料",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E7%A4%BA%E4%BE%8B4%E6%9B%B4%E6%96%B0%E4%B8%AA%E4%BA%BA%E8%B5%84%E6%96%99"
    },
    {
      "depth": 2,
      "text": "更新个人资料 updateprofile(\"newnickname\", \"newemail\")",
      "anchor": "更新个人资料-updateprofilenewnickname-newemail",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E6%9B%B4%E6%96%B0%E4%B8%AA%E4%BA%BA%E8%B5%84%E6%96%99-updateprofilenewnickname-newemail"
    },
    {
      "depth": 2,
      "text": "检查更新结果 assertexists(poco(\"updatesuccessmessage\"), \"更新个人资料失败！\")",
      "anchor": "检查更新结果-assertexistspocoupdatesuccessmessage-更新个人资料失败",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E6%A3%80%E6%9F%A5%E6%9B%B4%E6%96%B0%E7%BB%93%E6%9E%9C-assertexistspocoupdatesuccessmessage-%E6%9B%B4%E6%96%B0%E4%B8%AA%E4%BA%BA%E8%B5%84%E6%96%99%E5%A4%B1%E8%B4%A5"
    },
    {
      "depth": 4,
      "text": "示例5：开始战斗",
      "anchor": "示例5开始战斗",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E7%A4%BA%E4%BE%8B5%E5%BC%80%E5%A7%8B%E6%88%98%E6%96%97"
    },
    {
      "depth": 2,
      "text": "开始战斗 battlestartbutton.click()",
      "anchor": "开始战斗-battlestartbuttonclick",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E5%BC%80%E5%A7%8B%E6%88%98%E6%96%97-battlestartbuttonclick"
    },
    {
      "depth": 2,
      "text": "检查战斗是否开始 assertexists(battlescene, \"战斗没有开始！\")",
      "anchor": "检查战斗是否开始-assertexistsbattlescene-战斗没有开始",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E6%A3%80%E6%9F%A5%E6%88%98%E6%96%97%E6%98%AF%E5%90%A6%E5%BC%80%E5%A7%8B-assertexistsbattlescene-%E6%88%98%E6%96%97%E6%B2%A1%E6%9C%89%E5%BC%80%E5%A7%8B"
    },
    {
      "depth": 4,
      "text": "示例6：完成游戏教程",
      "anchor": "示例6完成游戏教程",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E7%A4%BA%E4%BE%8B6%E5%AE%8C%E6%88%90%E6%B8%B8%E6%88%8F%E6%95%99%E7%A8%8B"
    },
    {
      "depth": 2,
      "text": "完成教程任务 completetutorialtask(\"task1\")",
      "anchor": "完成教程任务-completetutorialtasktask1-1",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E5%AE%8C%E6%88%90%E6%95%99%E7%A8%8B%E4%BB%BB%E5%8A%A1-completetutorialtasktask1-1"
    },
    {
      "depth": 2,
      "text": "检查是否进入游戏主界面 assertexists(poco(\"gamemainui\"), \"完成教程后未进入游戏主界面！\")",
      "anchor": "检查是否进入游戏主界面-assertexistspocogamemainui-完成教程后未进入游戏主界面",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E8%BF%9B%E5%85%A5%E6%B8%B8%E6%88%8F%E4%B8%BB%E7%95%8C%E9%9D%A2-assertexistspocogamemainui-%E5%AE%8C%E6%88%90%E6%95%99%E7%A8%8B%E5%90%8E%E6%9C%AA%E8%BF%9B%E5%85%A5%E6%B8%B8%E6%88%8F%E4%B8%BB%E7%95%8C%E9%9D%A2"
    },
    {
      "depth": 4,
      "text": "示例7：社交功能测试",
      "anchor": "示例7社交功能测试",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E7%A4%BA%E4%BE%8B7%E7%A4%BE%E4%BA%A4%E5%8A%9F%E8%83%BD%E6%B5%8B%E8%AF%95"
    },
    {
      "depth": 2,
      "text": "发送消息 sendmessage(\"friendusername\", \"Hello, friend!\")",
      "anchor": "发送消息-sendmessagefriendusername-hello-friend",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E5%8F%91%E9%80%81%E6%B6%88%E6%81%AF-sendmessagefriendusername-hello-friend"
    },
    {
      "depth": 2,
      "text": "删除好友 removefriend(\"friendusername\")",
      "anchor": "删除好友-removefriendfriendusername",
      "citation": "https://www.pystone.net/notes/chatgpt-game-autotest-more-cases/#%E5%88%A0%E9%99%A4%E5%A5%BD%E5%8F%8B-removefriendfriendusername"
    }
  ],
  "claims": [],
  "outgoing": [],
  "incoming": [
    {
      "id": "note:sources-excerpts-archive",
      "title": "资料来源、摘录与归档",
      "url": "https://www.pystone.net/notes/sources-excerpts-archive/",
      "atlas": "https://www.pystone.net/?node=sources-excerpts-archive#knowledge-atlas",
      "label": "资料来源、摘录与归档",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "02-AI对话与研究原始输出中的“【ChatGPT】游戏自动化测试实践案例 - 更多案例”导航项",
      "citation": "https://www.pystone.net/notes/sources-excerpts-archive/#02-ai%E5%AF%B9%E8%AF%9D%E4%B8%8E%E7%A0%94%E7%A9%B6%E5%8E%9F%E5%A7%8B%E8%BE%93%E5%87%BA"
    }
  ],
  "contentMarkdown": "# 【ChatGPT】游戏自动化测试实践案例 - 更多案例\n\n> [!note] ChatGPT 问答录\n> 本文保存一次 ChatGPT 问答原始输出，仅作为资料来源；其中结论未自动视为已验证知识，使用前应结合可靠来源复核。\n\n\n> 创建时间：2023/6/11 19:06\n\n#### 目标：测试游戏的可用性和稳定性\n\n场景：测试游戏在连续运行多个小时后是否仍然稳定可用。\n\n实例：\n\npython\n\nimport time\n\ndef run_game_stability_test(duration_hours): # 登录游戏 login(\"valid_user\", \"valid_password\")\n\nstart_time = time.time()\n\nwhile time.time() - start_time < duration_hours * 3600:\n\ntry:\n\nnavigate_to(\"shop\")\n\nnavigate_to(\"battle\")\n\nnavigate_to(\"profile\")\n\n## 检查游戏是否仍然稳定可用 assert poco(\"game_main_ui\").exists(), \"游戏崩溃或不稳定！\" except Exception as e:\n\nprint(f\"游戏稳定性测试中发生错误：{e}\")\n\nbreakrun_game_stability_test(duration_hours=4)\n\n#### 目标：测试游戏的兼容性\n\n场景：测试游戏在不同设备和操作系统版本上的表现。\n\n实例：在不同的设备和操作系统版本上运行测试脚本，检查游戏是否能正常运行并且没有明显的界面问题或功能缺陷。\n\npython\n\ndevices_and_os_versions = [\n\n(\"device_1\", \"Android_10\"),\n\n(\"device_2\", \"Android_11\"),\n\n(\"device_3\", \"iOS_14\"),\n\n(\"device_4\", \"iOS_15\"),\n\n]\n\nfor device, os_version in devices_and_os_versions:\n\nprint(f\"正在测试设备：{device}，操作系统版本：{os_version}\")\n\n## 运行测试脚本 run_tests_on_device(device)\n\n#### 目标：测试游戏内的教程和引导\n\n场景：测试新玩家在完成游戏教程后能否正确进入游戏主界面。\n\n实例：\n\npython\n\ndef test_game_tutorial(): # 开始游戏教程 start_tutorial_button = poco(\"start_tutorial_button\")\n\nstart_tutorial_button.click()\n\n## 完成教程任务 complete_tutorial_task(\"task_1\")\n\ncomplete_tutorial_task(\"task_2\")\n\ncomplete_tutorial_task(\"task_3\")\n\n## 检查是否进入游戏主界面 assert poco(\"game_main_ui\").exists(), \"完成教程后未进入游戏主界面！\"\n\ntest_game_tutorial()\n\n#### 目标：测试游戏内的社交功能\n\n场景：测试玩家可以添加好友、发送消息和删除好友。\n\n实例：\n\npython\n\ndef test_social_features(): # 添加好友 add_friend(\"friend_username\")\n\nassert poco(\"friend_added\").exists(), \"添加好友失败！\" # 发送消息 send_message(\"friend_username\", \"Hello, friend!\")\n\nassert poco(\"message_sent\").exists(), \"发送消息失败！\" # 删除好友 remove_friend(\"friend_username\")\n\nassert not poco(\"friend_removed\").exists(), \"删除好友失败！\"\n\ntest_social_features()\n\n在使用 Airtest 进行游戏自动化测试时，可以使用 assert_exists() 和 assert_not_exists() 函数来替换原生的 Python 断言语句。以下是根据您的要求修改过的示例：\n\n#### 示例1：验证登录功能\n\npython\n\nfrom airtest.core.api import assert_exists, assert_not_exists\n\ndef test_login(): login(\"valid_user\", \"valid_password\")\n\nassert_exists(poco(\"user_logged_in\"), \"登录失败！\")\n\n#### 示例2：验证登录功能（无效凭证）\n\npython\n\ndef test_login_invalid_credentials(): login(\"invalid_user\", \"invalid_password\")\n\nassert_not_exists(poco(\"user_logged_in\"), \"登录应该失败，但成功了！\")\n\n#### 示例3：购买物品\n\npython\n\ndef test_shop_purchase(): # 等待商店界面加载完成 shop_button = poco(\"shop_button\")\n\nshop_button.wait_for_appearance()\n\n## 进入商店并购买物品 shop_button.click()\n\npurchase_button = poco(\"purchase_button\")\n\npurchase_button.wait_for_appearance()\n\npurchase_button.click()\n\n## 检查购买结果 purchase_success_message = poco(\"purchase_success_message\")\n\npurchase_success_message.wait_for_appearance()\n\nassert_exists(purchase_success_message, \"购买失败！\")\n\n#### 示例4：更新个人资料\n\npython\n\ndef test_profile_update(): try:\n\n## 更新个人资料 update_profile(\"new_nickname\", \"new_email\")\n\n## 检查更新结果 assert_exists(poco(\"update_success_message\"), \"更新个人资料失败！\")\n\nexcept Exception as e:\n\nprint(f\"测试过程中发生错误：{e}\")\n\n#### 示例5：开始战斗\n\npython\n\ndef test_battle_start(): # 等待战斗开始按钮出现（最多等待 10 秒） battle_start_button = poco(\"battle_start_button\")\n\nbattle_start_button.wait_for_appearance(timeout=10)\n\n## 开始战斗 battle_start_button.click()\n\nbattle_scene = poco(\"battle_scene\")\n\nbattle_scene.wait_for_appearance(timeout=20)\n\n## 检查战斗是否开始 assert_exists(battle_scene, \"战斗没有开始！\")\n\n#### 示例6：完成游戏教程\n\npython\n\ndef test_game_tutorial(): # 开始游戏教程 start_tutorial_button = poco(\"start_tutorial_button\")\n\nstart_tutorial_button.click()\n\n## 完成教程任务 complete_tutorial_task(\"task_1\")\n\ncomplete_tutorial_task(\"task_2\")\n\ncomplete_tutorial_task(\"task_3\")\n\n## 检查是否进入游戏主界面 assert_exists(poco(\"game_main_ui\"), \"完成教程后未进入游戏主界面！\")\n\ntest_game_tutorial()\n\n#### 示例7：社交功能测试\n\npython\n\ndef test_social_features(): # 添加好友 add_friend(\"friend_username\")\n\nassert_exists(poco(\"friend_added\"), \"添加好友失败！\")\n\n## 发送消息 send_message(\"friend_username\", \"Hello, friend!\")\n\nassert_exists(poco(\"message_sent\"), \"发送消息失败！\")\n\n## 删除好友 remove_friend(\"friend_username\")\n\nassert_not_exists(poco(\"friend_removed\"), \"删除好友失败！\")\n\ntest_social_features()\n"
}
