import uiautomator2 as ui2
import os
import time
import unittest
import HTMLTestRunnerCN
class HLJ_Shopping_Menu(unittest.TestCase):
'''关注'''
def setUp(self):
# self.driver=ui2.connect('192.168.216.253')
self.driver=ui2.connect('GWY0217719000655')
# self.driver.app_start('cn.rainbow.westore')
os.system('adb shell am force-stop cn.rainbow.westore')# 强制关闭
time.sleep(2)
os.system('adb shell am start -n cn.rainbow.westore/.ui.LauncherActivity')
# print('启动...')
time.sleep(3)
self.driver(resourceId="cn.rainbow.westore:id/iv", className="android.widget.ImageView", instance=1).click()
def tearDown(self):
# for i in range(0,3):
# self.driver.press('back')# 按返回键退出
# self.driver.app_stop('cn.rainbow.westore')
os.system('adb shell am force-stop cn.rainbow.westore')# 强制关闭
# print('关闭...')
def test_a_hlj(self):
'''商品关注'''
time.sleep(1)
# self.driver(resourceId="cn.rainbow.westore:id/sdv1", className="android.widget.ImageView", instance=1).click()
self.driver.click(120,880)
self.driver(text='常用分类').click()
self.driver(resourceId="cn.rainbow.westore:id/iv_image",instance=0).click()
self.driver(resourceId="cn.rainbow.westore:id/item_image",instance=0).click()
if self.driver(text='关注'):
self.driver(text='关注').click()
time.sleep(2)
if self.driver(text='账号登录'):
self.driver(resourceId="cn.rainbow.westore:id/username").set_text('18320762135')
self.driver(resourceId="cn.rainbow.westore:id/password").set_text('test_lss')
self.driver(resourceId="cn.rainbow.westore:id/button_login_normal").click()
time.sleep(2)
self.driver(text='关注').click()
time.sleep(2)
self.assertTrue(self.driver(text='已关注'))
print('商品关注成功')
else:
self.assertTrue(self.driver(text='已关注'))
print('商品已关注')
pass
time.sleep(1)
def test_b_hlj(self):
'''店铺关注'''
time.sleep(1)
# self.driver(resourceId="cn.rainbow.westore:id/sdv1", className="android.widget.ImageView", instance=1).click()
self.driver.click(120,880)
self.driver(text='常用分类').click()
self.driver(resourceId="cn.rainbow.westore:id/iv_image",instance=0).click()
self.driver(resourceId="cn.rainbow.westore:id/item_image",instance=0).click()
self.driver(text='店铺').click_exists(timeout=15)
if self.driver(text='关注'):
self.driver(text='关注').click()
time.sleep(2)
if self.driver(text='账号登录'):
self.driver(resourceId="cn.rainbow.westore:id/username").set_text('18320762135')
self.driver(resourceId="cn.rainbow.westore:id/password").set_text('test_lss')
self.driver(resourceId="cn.rainbow.westore:id/button_login_normal").click()
time.sleep(2)
self.driver(text='关注').click()
time.sleep(2)
self.assertTrue(self.driver(text='已关注'))
print('店铺关注成功')
self.driver.press('back')
else:
self.assertTrue(self.driver(text='已关注'))
print('店铺已关注')
time.sleep(1)
def test_c_hlj(self):
'''退出重新登录是否还关注'''
self.driver(resourceId="cn.rainbow.westore:id/iv", className="android.widget.ImageView", instance=4).click()
self.driver(resourceId="cn.rainbow.westore:id/ivSet").click()
self.driver(text='退出当前账号').click()
self.driver(text='确定').click()
self.driver(text='登录/注册').click()
self.driver(resourceId="cn.rainbow.westore:id/username").set_text('18320762135')
self.driver(resourceId="cn.rainbow.westore:id/password").set_text('test_lss')
self.driver(resourceId="cn.rainbow.westore:id/button_login_normal").click()
time.sleep(1)
self.driver(text='关注').click()
time.sleep(2)
self.assertTrue(self.driver(resourceId="cn.rainbow.westore:id/item_image"))
self.driver(resourceId="cn.rainbow.westore:id/item_image").click()
self.assertTrue(self.driver(text='已关注'))
self.driver.press('back')
self.driver(text='店铺关注').click()
self.driver(resourceId="cn.rainbow.westore:id/item_icon").click()
self.assertTrue(self.driver(text='已关注'))
print('退出重新登录查看显示关注')
def test_d_hlj(self):
'''取消关注'''
self.driver(resourceId="cn.rainbow.westore:id/iv", className="android.widget.ImageView", instance=4).click()
self.driver(text='关注').click()
time.sleep(2)
self.assertTrue(self.driver(resourceId="cn.rainbow.westore:id/item_image"))
self.driver(resourceId="cn.rainbow.westore:id/item_image").click()
self.driver(text='已关注').click()
self.assertTrue(self.driver(text='关注'))
self.driver.press('back')
self.assertFalse(self.driver(resourceId="cn.rainbow.westore:id/item_image"))
self.driver(text='店铺关注').click()
self.driver(resourceId="cn.rainbow.westore:id/item_icon").click_exists(timeout=15)
self.assertTrue(self.driver(text='已关注'))
self.driver(text='已关注').click_exists(timeout=15)
self.assertTrue(self.driver(text='关注'))
self.driver.press('back')
self.assertFalse(self.driver(resourceId="cn.rainbow.westore:id/item_image"))
print('已取消关注')
def test_e_hlj(self):
'''退出重新登是否已取消关注'''
self.driver(resourceId="cn.rainbow.westore:id/iv", className="android.widget.ImageView", instance=4).click()
self.driver(resourceId="cn.rainbow.westore:id/ivSet").click()
self.driver(text='退出当前账号').click()
self.driver(text='确定').click()
self.driver(text='登录/注册').click()
self.driver(resourceId="cn.rainbow.westore:id/username").set_text('18320762135')
self.driver(resourceId="cn.rainbow.westore:id/password").set_text('test_lss')
self.driver(resourceId="cn.rainbow.westore:id/button_login_normal").click()
self.driver(text='关注').click()
time.sleep(2)
self.assertFalse(self.driver(resourceId="cn.rainbow.westore:id/item_image"))
self.driver(text='店铺关注').click()
self.assertFalse(self.driver(resourceId="cn.rainbow.westore:id/item_icon"))
print('退出重新登录查看已取消关注')
if __name__=='__main__':
# unittest.main()
suite=unittest.TestSuite()
suite.addTest(HLJ_Shopping_Menu('test_a_hlj'))
suite.addTest(HLJ_Shopping_Menu('test_b_hlj'))
suite.addTest(HLJ_Shopping_Menu('test_c_hlj'))
suite.addTest(HLJ_Shopping_Menu('test_d_hlj'))
suite.addTest(HLJ_Shopping_Menu('test_e_hlj'))
with open('report_hlj.html','wb')as f:
runner=HTMLTestRunnerCN.HTMLTestReportCN(stream=f,title='虹领巾购物菜单测试',description='虹领巾自动化测试用例',tester='test')
runner.run(suite)