0
点赞
收藏
分享

微信扫一扫

windows应用-ui自动化

一.目的

最近接到一个测试任务windos版本的自助收银客户端测试工作,由于是个长期的迭代项目就考虑把稳定功能纳入自动化测试框架

二.框架调研,选用winAppDriver


三.python3.8+win10+winAppDriver +appium  搭建windows 桌面应用的UI自动化环境

1.安装python3.8 windows版本:https://www.python.org/getit/,安装pip同时升级pip的版本

2.pip安装 selenium,appium

3.安装 winAppDriver :

下载地址:https://github.com/Microsoft/WinAppDriver/releases

WinAppDriver(Windows Application Driver)是一个类似Selenium的UI自动化测试服务系统要求: Windows10或Windows Server 2016支持应用程序: UWP, WPF, WinForms, Win32

4.设置开发模式,让程序可以连接上WinAppDrive的服务


    5.inspect.exe  组件识别工具检查

系统一般自带, 路径C:\Program Files (x86)\Windows Kits\10\bin\x64,如果没有安装一个windowSDK;https://download.microsoft.com/download/4/d/2/4d2b7011-606a-467e-99b4-99550bf24ffc/windowssdk/winsdksetup.exe


四.样例实战,启动微信桌面版本,监控指定的群,有@自己和@all的时候自动回复信息

import time,os,sys

import unittest

from appiumimport webdriver

from selenium.webdriverimport ActionChains

from selenium.webdriver.common.keysimport Keys

class NotepadTests(unittest.TestCase):

@classmethod

    def setUpClass(self):

#启动WinAppDriver.exe

        os.system(r'@start  /d  "C:\Program Files (x86)\Windows Application Driver\" WinAppDriver.exe')

desired_caps = {}

#微信的安装路径

        desired_caps['app'] =r"C:\tools\WeChat\WeChat.exe"

        self.driver = webdriver.Remote(

command_executor='http://127.0.0.1:4723',

desired_capabilities=desired_caps)

#self.driver.maximize_window()

    @classmethod

    def tearDownClass(self):

self.driver.quit()

#关闭WinAppDriver.exe

        os.system(' @taskkill /f /im  WinAppDriver.exe')#@tasklist|findstr /i  WinAppDriver.exe  &&

    def test_edit(self):

new_msg=False

        self.driver.find_element_by_name('财务自由').click()#“财务自由”群的名字

        dd=self.driver.find_elements_by_xpath("//*[@LocalizedControlType='列表项目']")

for din dd:

print(d.get_attribute('Name'))

#@黄 自己的微信名字

if '@黄'  in  d.get_attribute('Name')or  '@所有人'  in  d.get_attribute('Name'):  

                new_msg=True

                  break

        if new_msg:

self.driver.find_element_by_name('输入').send_keys('我是机器人助理,主人暂时不在线')

time.sleep(3)

ActionChains(self.driver).send_keys(Keys.ENTER).perform()

time.sleep(3)

ActionChains(self.driver).send_keys(Keys.ENTER).perform()

self.driver.get_screenshot_as_file('1.png')#截图




if __name__ =="__main__":

suite = unittest.TestLoader().loadTestsFromTestCase(NotepadTests)

unittest.TextTestRunner(verbosity=2).run(suite)




举报

相关推荐

0 条评论