天天看點

Windows應用程式自動化測試架構demo

環境要求

1 pycharm

2 winappdriver

https://github.com/Microsoft/WinAppDriver

腳本說明

1 import 内容

import time

import unittest

from appium import webdriver

import pyautogui 用于實作按坐标點選,輕按兩下,輸入字元等内容

import random

import datetime

#import psutil 用于監控程序,實際尚未使用到

from selenium.webdriver.common.action_chains import ActionChains 使用目的是用來 輕按兩下按name查找的内容

2 擷取坐标初始化

screenWidth, screenHeight = pyautogui.size() # Get the size of the primary monitor.

currentMouseX, currentMouseY = pyautogui.position() # Get the XY position of the mouse.

3 setup class主要是啟動應用,在執行前需要修改應用位置

def setUpClass(self):
    #set up appium
    desired_caps = {}
    desired_caps["app"] = "E:\xxx\xxx.exe"
    self.driver = webdriver.Remote(
        command_executor='http://127.0.0.1:4723',
        desired_capabilities= desired_caps)
    time.sleep(3)
    self.str = "xxx.exe"
    self.action = ActionChains(self.driver)
           

繼續閱讀