TA的每日心情 | 无聊 2024-7-12 13:16 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]测试小兵
|
4#
楼主 |
发表于 2017-6-20 10:25:06
|
只看该作者
- 这个是我的项目结构图,说明一下
- run_case.py
- run_case.py 是跑脚本得,配置好test case 路径去搜索 py文件,然后把test case加入到测试容器
- casepath = './/'+configure.game_name+'_TestCase'
- discover = unittest.defaultTestLoader.discover(casepath, pattern='test0*', top_level_dir=None)
- result 文件夹与 tmcs_images
- result 文件夹是存放测试报告与截图的
- tmcs_images 与 tmcs_TestCase 都是存放 图片的,为什么会有两个?。。一个是tmcs_TestCase 做unittest图片相对路径,一个runcase.py的相对路径
- configure.py
- configure.py 是配置信息的,game_name 是用来区分游戏的。主要作用是 在于 图片存放的路径和 搜索case的路径
- game_name = 'tmcs'
- device_name = '4c14b8b2'
- package_name = 'com.tencent.tmgp.shardsofdestiny'
- activity_name = 'com.zhankaigame.destiny.RenWanTangMainActivity'
- public.methods.py
- public.methods.py 是一些公共的方法,比如获取屏幕像素,断言方法(失败截图),查找元素等,图片操作等
- def size(self):
- if configure.device_name == '':
- size = 'adb shell wm size'
- else:
- size = 'adb -s %s shell wm size' % configure.device_name
- a = os.popen(size)
- for i in a:
- pass
- size =i.split(': ')
- size = size[1].split('x')
- size= [int(size[0]),int(size[1])] #size[0] 为width size[1] 为high
- return size
- def dy(self,driver,value1,value2,screen_name):
- self.driver = driver
- try:
- self.assertEqual(value1, value2)
- except:
- self.screencap(self.driver,name=screen_name)
- self.assertEqual(value1, value2)
- def dy_IsNone(self,driver,obj,screen_name):
- self.driver = driver
- try:
- self.assertIsNone(obj)
- except:
- self.screencap(self.driver,name=screen_name)
- self.assertIsNone(obj)
- def dy_IsNotNone(self,driver,obj,screen_name):
- self.driver = driver
- try:
- self.assertIsNotNone(obj)
- except:
- self.screencap(self.driver,name=screen_name)
- self.assertIsNotNone(obj)
- def element(self, driver, methods, value):
- '''
- :param driver:驱动
- :param methods: 方式
- :param value: 值
- :return: 返回对象
- '''
- self.driver = driver
- if methods == 'text':
- return self.driver(text=value)
- elif methods == 'xpath':
- return self.driver(xpath=value)
- elif methods == 'resourceId':
- return self.driver(resourceId=value)
- elif methods == 'className':
- return self.driver(className = value)
- def element_or_none(self, driver, methods, value):
- '''
- :param driver:驱动
- :param methods:方式
- :param value:知
- :return:元素存在返回元素,不存在,返回None
- '''
- self.driver = driver
- try:
- element = self.element(self.driver, methods, value)
- if len(element) == 0:
- self.assertEqual(True, False)
- except:
- element = None
- return element
- 因为atx 查找元素后,是一个list,如果list为空,也不报错的。。因此写了个方法,return None,主要用来做断言的
- def images_or_none(self,driver,images_name,timeout = 10):
- self.driver = driver
- game_name = configure.game_name
- try:
- self.wait_images(self.driver, images_name,timeout)
- except:
- pass
- images = self.driver.exists('./'+game_name+'_images/'+images_name)
- return images
- 这里用到 driver.wait() 和 driver.exists() 这里的图片相对路径,如果图片不存在,return None,主要用来做断言的
- def click_images(self, driver, images_name):
- self.driver = driver
- game_name = configure.game_name
- images = self.driver.click_image('./' + game_name +'_images/'+ images_name)
- return images
- def wait_images(self,driver,images,timeout = 10):
- self.driver = driver
- game_name = configure.game_name
- images= self.driver.wait('./' + game_name + '_images/' + images,timeout)
- return images
- 这里两个,等待图片出现,一个是 点击图片
- def tap(self,driver,value):
- self.driver = driver
- size = self.size()
- return self.driver.click(size[0] * value[0], size[1] * value[1])
- 点击坐标的方法,比例点击
- testcase
- case如下
- class YSDKSDK(unittest.TestCase,public.Methods):
- u'''YSDKC-sdk测试'''
- def setUp(self):
- if configure.device_name == '':
- self.driver = atx.connect()
- else:
- self.driver = atx.connect(configure.device_name)
- self.driver.start_app(configure.package_name,configure.activity_name)
- sleep(25)
- def tearDown(self):
- pass
- self.driver.stop_app(configure.package_name)
- def test_013(self):
- u'''调起微信支付,并取消'''
- self.click_images(self.driver, 'game-gonggao@auto.png')
- self.click_images(self.driver, 'game-weixin-login@auto.png')
- sleep(5)
- self.enter_game(self.driver)
- self.pay(self.driver)
- self.element(self.driver,'text','微信支付').click()
- images = self.images_or_none(self.driver,'weixinpay-view@auto.png',timeout=20)
- self.dy_IsNotNone(self.driver,images,'test_013')
- sleep(5)
- self.driver.keyevent('KEYCODE_BACK')
- sleep(5)
- ysdk_pay = self.element(self.driver, 'text', '确认支付方式')
- self.dy(self.driver, unicode(ysdk_pay.text), u'确认支付方式', 'test_013')
复制代码 |
|