微信 测试
This commit is contained in:
parent
1ad2dc52be
commit
a2a1790b70
24
main.py
24
main.py
@ -1,12 +1,13 @@
|
|||||||
import uvicorn
|
import uvicorn
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from typing import Any
|
from typing import Any, Union
|
||||||
import uiautomator2 as u2
|
import uiautomator2 as u2
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
|
|
||||||
import tasks.douyin
|
import tasks.douyin
|
||||||
|
import tasks.wechat
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
@ -104,5 +105,26 @@ async def douyin_task(item: Device):
|
|||||||
d.xpath("老耗游戏").click()
|
d.xpath("老耗游戏").click()
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/task/app/wechat/search")
|
||||||
|
async def wechat_search_task(item: Device):
|
||||||
|
if item.serial not in devices:
|
||||||
|
return Response(code=500, msg="设备 {} 不存在".format(item.serial))
|
||||||
|
d = devices[item.serial]
|
||||||
|
tasks.wechat.click_search_btn(d)
|
||||||
|
|
||||||
|
|
||||||
|
class WechatSearchInput(Device):
|
||||||
|
text: str
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/task/app/wechat/search/input")
|
||||||
|
async def wechat_search_task(item: WechatSearchInput):
|
||||||
|
if item.serial not in devices:
|
||||||
|
return Response(code=500, msg="设备 {} 不存在".format(item.serial))
|
||||||
|
d = devices[item.serial]
|
||||||
|
tasks.wechat.click_search_btn(d)
|
||||||
|
tasks.wechat.input_search_text(d, item.text)
|
||||||
|
tasks.wechat.click_search_result(d)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
uvicorn.run('main:app', host='0.0.0.0', port=8000, reload=True)
|
uvicorn.run('main:app', host='0.0.0.0', port=8000, reload=True)
|
||||||
|
36
tasks/wechat/__init__.py
Normal file
36
tasks/wechat/__init__.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
from uiautomator2 import Device
|
||||||
|
|
||||||
|
|
||||||
|
def click_search_btn(d: Device):
|
||||||
|
selector = d.xpath('//*[@resource-id="com.tencent.mm:id/h5n"]')
|
||||||
|
if selector.exists:
|
||||||
|
selector.click()
|
||||||
|
else:
|
||||||
|
logging.warning("未找到组件")
|
||||||
|
|
||||||
|
|
||||||
|
def input_search_text(d: Device, text: str):
|
||||||
|
clear_btn = d.xpath('//*[@resource-id="com.tencent.mm:id/nhn"]')
|
||||||
|
if clear_btn.exists:
|
||||||
|
clear_btn.click()
|
||||||
|
|
||||||
|
selector = d.xpath('//*[@resource-id="com.tencent.mm:id/mdd"]')
|
||||||
|
|
||||||
|
if selector.exists:
|
||||||
|
selector.set_text(text)
|
||||||
|
else:
|
||||||
|
logging.warning("未找到组件")
|
||||||
|
|
||||||
|
|
||||||
|
def click_search_result(d: Device):
|
||||||
|
selector = d.xpath('//*[@resource-id="com.tencent.mm:id/kbo"]')
|
||||||
|
selector.wait(timeout=3)
|
||||||
|
elements = selector.all()
|
||||||
|
print(elements)
|
||||||
|
|
||||||
|
if len(elements) > 0:
|
||||||
|
elements[0].click()
|
||||||
|
else:
|
||||||
|
logging.warning("未找到组件")
|
Loading…
Reference in New Issue
Block a user