uiautomator2 测试

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)



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值