The first open source AI automated testing project in the whole network

Many outsourcing companies have a set of automated testing platforms that can be sold to Party A (banking and insurance companies); and some major Internet companies develop through their own technical personnel, and generally carry out in-depth development on the basis of appium. The idea of ​​AI automation is to combine appium to add image recognition and ocr, and add image recognition and text recognition (ocr) on the basis of the eight positioning elements to realize automated testing.

The following is the actual login in the work app, using Baidu Feizhi for ocr recognition, then calculating the coordinate position, clicking on it, and then entering the user name

from appium import webdriver
import time
from config import setting
from paddleocr import PaddleOCR

desired_caps = dict()
desired_caps['platformName'] = 'Android'  # 可以写成android
desired_caps['platformVersion'] = '12'  # 11.1.0等都可以写成11
desired_caps['deviceName'] = '测试手机型号'  # 设备名字可以随便写,但是不可以为空
desired_caps['appPackage'] = '测试app包'
desired_caps['appActivity'] = '你测试app的MainActivity'
desired_caps['noReset'] = True  # 打开app时不清除数据
desired_caps['udid'] = "你的测试设备"
# desired_caps['udid'] = "80fe4bfb"
# desired_caps['udid'] = "9WDNW21107036993"
# desired_caps['automationName'] = "UiAutomator2"
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True
#启动appium服务
# cmd = r'start appium -a 127.0.0.1 -p 4723 -bp 4724'
# pr = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
# pr.wait(timeout=3)
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
time.sleep(10)  # 等待20秒"
img_folder = setting.OCR_DIR
screen_save_path = img_folder + '登录.png'
# # time1 = time.strftime('%Y%m%d%H%M', time.localtime(time.time()))
# # screen_save_path = img_folder + time1 + '.png'
driver.get_screenshot_as_file(screen_save_path)
ocr = PaddleOCR()
result = ocr.ocr(screen_save_path)
point = []
print(result)
for line in result[0]:
    if line[1][0] == '用户名':
        print(line[0])
        # left, top, right, bottom = line[0]
        # print(top)
        a = 0
        b = 0
        for line1 in line[0]:
            a = a + line1[0]
            b = b + line1[1]
        # print(a)
        # print(b)
        c = a // 4
        e = b // 4
        point.append(c)
        point.append(e)
x, y = point
time.sleep(2)
# action.tap(x=x, y=y).perform()
driver.tap([(x, y)], 100)
time.sleep(3)
driver.switch_to.active_element.send_keys("编程老怪")  # 输入文本
time.sleep(20)
driver.quit()

 

 

Guess you like

Origin blog.csdn.net/yuanhou110/article/details/131559427