这估计是全网为数不多的比较完整的python+uiautomator2+pytest app自动化测试实例!!!!!适合小白,大神嘴下留情,高抬贵手。
1、测试的app:hawa,以及一些应用界面请看下面的图:
2、测试框架:python+uiautomator2+pytest,定位元素则是使用weditor
3、代码框架
3、1 Base.py是封装了一下是通过xpath获取元素定位以及其他方式获取元素定位的方法
3、2 Page_Element.py是存放元素定位的文件
3、3 test_case文件中是测试用例(conftest.py除外),conftest.py的用法请度娘。我这conftest.py是前置处理启动的弹窗、签到弹窗的处理
3、4 生成的报告放置在report
3、5 执行测试用例文件则是main.py
4、测试用例
我简单的按照底部四个tab进行划分写的用例,这里主要是home tab以及message tab的一些功能测试用例
代码就贴下面了,别的就不说了,有兴趣自己去下载来玩玩。
Base.py
# -*- coding: utf-8 -*-
# @Author : qyq
class Base:
def __init__(self, driver):
self.driver = driver
def find_element(self, element):
if "xpath" in element.keys():
return self.driver.xpath(element["xpath"])
else:
return self.driver(**element)
Page_Element.py
# -*- coding: utf-8 -*-
# @Author : qyq
class Page_Element:
"""========home页面元素=============="""
package_name = "com.hawatalk.live"
#home tab按钮
home={"xpath":'//*[@text="Home"]'}
#签到关闭按钮
sign_close={"resourceId":"com.hawatalk.live:id/view_close"}
#权限取消按钮
permissions_cancel={"resourceId":"android:id/button2"}
#home页面排行榜
home_rank={"resourceId":"com.hawatalk.live:id/layout_ranking"}
#home页面cp
home_cp={"resourceId":"com.hawatalk.live:id/layout_cp"}
#home页面活动
home_activity={"resourceId":"com.hawatalk.live:id/layout_activity"}
#home页面hot分类
home_hot={"resourceId":"com.hawatalk.live:id/tv_menu_item","text":"Hot"}
#home页面新人分类
home_newcomer={"resourceId":"com.hawatalk.live:id/tv_menu_item","text":"NewComer"}
#home页面本地分类
home_local={"resourceId":"com.hawatalk.live:id/tv_menu_item","text":"Local"}
#home页面列表
home_list={"resourceId":"com.hawatalk.live:id/cardView_hot"}
#home页面列表hot_banner
home_hot_banner_list={"xpath":'//*[@resource-id="com.hawatalk.live:id/recyclerView"]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]'}
#home页面顶部hot_banner
home_hot_banner_top={"xpath":'//*[@resource-id="com.hawatalk.live:id/collapsing_toobar"]/android.widget.RelativeLayout[1]'}
#home页面点击banner进入h5页面标题
home_banner_title={"xpath":"//android.widget.RelativeLayout/android.widget.TextView[1]"}
#home页面点击banner进入h5页面分享按钮
home_banner_share={"xpath":'//*[@resource-id="com.hawatalk.live:id/iv_right"]'}
#home页面顶部me按钮
home_me={"xpath":'//*[@resource-id="com.hawatalk.live:id/title_container"]/android.widget.TextView[1]'}
#home_me页面创建自己的房间按钮
home_me_create={"resourceId":"com.hawatalk.live:id/cv_userinfo"}
#home_me页面我的房间退出按钮
home_me_create_room_exit={"xpath":'//*[@resource-id="com.hawatalk.live:id/rv_bottom_function"]/android.widget.LinearLayout[2]/android.widget.ImageView[1]'}
#home_me页面浏览记录按钮
home_me_browse={"xpath":'//*[@resource-id="com.hawatalk.live:id/status_layout"]/android.widget.LinearLayout[1]/android.widget.FrameLayout[2]/android.widget.FrameLayout[1]/android.widget.HorizontalScrollView[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[2]/android.view.View[1]'}
#home_me页面following按钮
home_me_following={"xpath":'//*[@resource-id="com.hawatalk.live:id/status_layout"]/android.widget.LinearLayout[1]/android.widget.FrameLayout[2]/android.widget.FrameLayout[1]/android.widget.HorizontalScrollView[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[2]/android.view.View[2]'}
#home页面顶部hot按钮
home_hot_button={"xpath":'//*[@resource-id="com.hawatalk.live:id/title_container"]/android.widget.TextView[2]'}
#home页面顶部small talk按钮
home_smalltalk={"xpath":'//*[@text="Small talk"]'}
#home页面smalltalk tab今日热门分类tab
home_smalltalk_todayhotspot={"xpath":'//*[@resource-id="com.hawatalk.live:id/view_indicator"]/android.widget.FrameLayout[1]/android.widget.HorizontalScrollView[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[2]/android.view.View[1]'}
#home页面smalltalk tab 全部聊天房间分类tab
home_smalltalk_allchat = {"xpath": '//*[@resource-id="com.hawatalk.live:id/view_indicator"]/android.widget.FrameLayout[1]/android.widget.HorizontalScrollView[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[2]/android.view.View[2]'}
#home页面smalltalk tab talktalk分类tab
home_smalltalk_talktalk = {"xpath": '//*[@resource-id="com.hawatalk.live:id/view_indicator"]/android.widget.FrameLayout[1]/android.widget.HorizontalScrollView[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[2]/android.view.View[3]'}
# home页面smalltalk tab funclub分类tab
home_smalltalk_funclub = {"xpath": '//*[@resource-id="com.hawatalk.live:id/view_indicator"]/android.widget.FrameLayout[1]/android.widget.HorizontalScrollView[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[2]/android.view.View[4]'}
#home_smalltalk列表卡片
home_smalltalk_list={"resourceId":"com.hawatalk.live:id/mViewCardContainer"}
#home_smalltalk列表随机匹配按钮
home_smalltalk_randommatch={"resourceId":"com.hawatalk.live:id/cardRandomRoomLayoutView"}
#home页面顶部搜索按钮
home_search={"resourceId":"com.hawatalk.live:id/iv_search"}
#home页面顶部hot按钮
home_top_hot={"xpath":'//*[@text="Hot"]'}
"""========room聊天页面元素================"""
#room聊天页面退出按钮
room_turnoff={"xpath":'//*[@resource-id="com.hawatalk.live:id/iv_room_operate"]/android.widget.ImageView[1]'}
#room聊天页面分享按钮
room_share={"xpath":'//*[@resource-id="com.hawatalk.live:id/iv_room_share"]/android.widget.ImageView[1]'}
#room聊天页面关闭按钮
room_exit={"xpath":'//*[@resource-id="com.hawatalk.live:id/rv_bottom_function"]/android.widget.LinearLayout[3]/android.widget.ImageView[1]'}
#房间聊天页面输入框
room_msg_send={"resourceId":"com.hawatalk.live:id/iv_room_send_msg"}
#房间礼物按钮
room_gift={"resourceId":"com.hawatalk.live:id/icon_room_send_gift_bg"}
#房间消息信箱
room_msgbox={"resourceId":"com.hawatalk.live:id/rl_room_msg"}
#房间设置按钮
room_setting={"resourceId":"com.hawatalk.live:id/icon_room_mic_in_list"}
#房间游戏按钮
room_game={"resourceId":"com.hawatalk.live:id/iv_more_game"}
#房间火箭按钮
room_rocket={"resourceId":"com.hawatalk.live:id/jewel_box"}
#房间活动按钮
room_activity={"resourceId":"com.hawatalk.live:id/activity_img"}
#房间密码输入框
room_password_input={"resourceId":"com.hawatalk.live:id/pic_login_input"}
#房间密码输入弹窗取消按钮
room_password_cancel={"resourceId":"com.hawatalk.live:id/btn_cancel"}
#房间密码输入弹窗确认按钮
room_password_ok={"resourceId":"com.hawatalk.live:id/btn_confirm"}
"""rank排行榜元素"""
#财富tab按钮
rank_wealth={"text":"Wealth"}
#charm tab按钮
rank_charm={"text":"Charm"}
#room tab按钮
rank_room={"text":"Room"}
#日榜按钮
rank_day={"xpath":'//*[@resource-id="com.hawatalk.live:id/view_indicator"]/android.widget.FrameLayout[1]/android.widget.HorizontalScrollView[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[2]/android.view.View[1]'}
#周榜按钮
rank_week={"xpath":'//*[@resource-id="com.hawatalk.live:id/view_indicator"]/android.widget.FrameLayout[1]/android.widget.HorizontalScrollView[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[2]/android.view.View[2]'}
#月榜按钮
rank_month={"xpath":'//*[@resource-id="com.hawatalk.live:id/view_indicator"]/android.widget.FrameLayout[1]/android.widget.HorizontalScrollView[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[2]/android.view.View[3]'}
#上月榜按钮
rank_last_month = {"xpath":'//*[@resource-id="com.hawatalk.live:id/view_indicator"]/android.widget.FrameLayout[1]/android.widget.HorizontalScrollView[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[2]/android.view.View[4]'}
#room小时榜按钮
rank_hour={"xpath":'//*[@resource-id="com.hawatalk.live:id/view_indicator"]/android.widget.FrameLayout[1]/android.widget.HorizontalScrollView[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[2]/android.view.View[5]'}
#第一名头像
#第一名头像
rank_first={"resourceId":"com.hawatalk.live:id/avatar_first"}
#第二名头像
rank_second={"resourceId":"com.hawatalk.live:id/avatar_second"}
#第三名头像
rank_third={"resourceId":"com.hawatalk.live:id/avatar_third"}
#排行榜其他人
rank_other={"resourceId":"com.hawatalk.live:id/ranking_number"}
"""cp榜页面元素"""
#转盘top1
cprank_wheel_top1={"xpath":'//*[@resource-id="wheel_0"]/android.view.View[1]'}
#转盘top2
cprank_wheel_top2={"xpath":'//*[@resource-id="wheel_1"]/android.view.View[1]'}
#转盘top3
cprank_wheel_top3={"xpath":'//*[@resource-id="wheel_2"]/android.view.View[1]'}
#转盘top4
cprank_wheel_top4={"xpath":'//*[@resource-id="wheel_3"]/android.view.View[1]'}
#转盘top5
cprank_wheel_top5={"xpath":'//*[@resource-id="wheel_4"]/android.view.View[1]'}
#cp广场按钮
cprank_square={"resourceId":"couple_square"}
#cp排行榜按钮
cprank_rank={"resourceId":"find_forward_rank"}
#cp收入按钮
cprank_reward={"resourceId":"find_couple_rank_reward"}
#cp排行页面的帮助按钮
cprank_rank_help={"xpath":'//*[@content-desc="Send CP gift to form CP"]'}
#cp排行页面的帮助弹窗关闭按钮
cprank_rank_help_close={"xpath":'//*[@content-desc="close"]'}
#礼物特效
gift_effect={"resourceId":"com.hawatalk.live:id/nt_ll_gift_container"}
#个人主页加载按钮
person_load_more={"resourceId":"com.hawatalk.live:id/loading_2"}
"""活动页面元素"""
#我参与的活动
activity_my_activity={"resourceId":"com.hawatalk.live:id/right_action","text":"My Activity"}
#正在进行的活动
activity_progress_activity={"text":"In Progress"}
#即将开始的活动
activity_coming_activity={"text":"Coming Soon"}
#结束的活动
activity_finished_activity={"text":"Finished"}
#活动列表,选择第几个,通过[*]实现
activity_list1={"className":"android.view.ViewGroup"}
#活动详情页面返回按钮
activity_back={"resourceId":"com.hawatalk.live:id/iv_vip_back"}
#活动详情页面分享按钮
activity_share={"text":"Share"}
#活动详情页面订阅按钮
activity_subscribe={"resourceId":"com.hawatalk.live:id/iv_subscriptioned"}
#活动详情页面进入房间按钮
activity_joinroom={"xpath":'//android.widget.ScrollView/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.ImageView[1]'}
#活动页面头像,选择第几个,通过[*]实现
activity_avatar={"resourceId":"com.hawatalk.live:id/fr_avatar"}
"""我的活动页面元素"""
#已订阅tab按钮
my_activity_subscribed={"text":"Subscription"}
#posted tab按钮
my_activity_posted={"text":"Posted"}
#我的活动页面返回按钮
my_activity_finished={"resourceId":"com.hawatalk.live:id/back_btn"}
#我的活动页面添加创建按钮
my_activity_add={"resourceId":"com.hawatalk.live:id/right_action"}
#创建活动标题输入框
my_activity_title={"resourceId":"com.hawatalk.live:id/et_activity_title"}
#创建活动描述输入框
my_activity_description={"resourceId":"com.hawatalk.live:id/et_activity_dec"}
#创建活动起始时间
my_activity_starttime={"text":"start time"}
#创建活动起始时间——月选择
my_activity_starttime_month={"resourceId":"com.hawatalk.live:id/month"}
#创建活动起始时间——日选择
my_activity_starttime_day={"resourceId":"com.hawatalk.live:id/day"}
#创建活动起始时间——小时选择
my_activity_starttime_hour={"resourceId":"com.hawatalk.live:id/hour"}
#创建活动起始时间——分钟选择
my_activity_starttime_minute={"resourceId":"com.hawatalk.live:id/min"}
#创建活动起始时间——确定按钮
my_activity_starttime_confirm={"resourceId":"com.hawatalk.live:id/btnSubmit"}
# 创建活动时长
my_activity_duration = {"text": "activity duration"}
#创建活动时长选择按钮
my_activity_duration_select = {"resourceId": "com.hawatalk.live:id/options1"}
#创建活动时长确认按钮
my_activity_duration_confirm = {"resourceId": "com.hawatalk.live:id/btnSubmit"}
#创建活动下一步按钮
my_activity_next = {"resourceId": "com.hawatalk.live:id/ll_release"}
#创建活动release按钮
my_activity_release = {"resourceId": "com.hawatalk.live:id/ll_release"}
#创建活动页面背景选择,通过[*]选择第几个
my_activity_background = {"resourceId": "com.hawatalk.live:id/iv_poster"}
#创建活动详情页面返回按钮
my_activity_back = {"resourceId": "com.hawatalk.live:id/iv_vip_back"}
#创建活动详情页面customized按钮
my_activity_customized = {"text": "Customized"}
#创建活动拍照按钮
my_activity_takephoto = {"text": "Take photos to upload"}
#创建活动相册按钮
my_activity_album = {"text": "Local photo album"}
#相册权限允许按钮
my_activity_album_allow = {"text": "始终允许"}
#相片选择,通过[*]选择第几个
my_activity_album_select = {"resourceId": "com.hawatalk.live:id/tvCheck"}
#相片选择完成按钮
my_activity_album_select_completed={"resourceId": "com.hawatalk.live:id/ps_tv_complete"}
#相片裁剪确认按钮
my_activity_album_select_crop_confirm = {"resourceId": "com.hawatalk.live:id/menu_crop"}
#相片选择大于5m弹窗文案提示
my_activity_album_select_5m_text = {"resourceId": "com.hawatalk.live:id/tv_content"}
#相片选择大于5m弹窗确定按钮
my_activity_album_select_5m_ok = {"resourceId": "com.hawatalk.live:id/btnOk"}
#创建活动拍照按钮
my_activity_shutter = {"resourceId":"com.android.camera:id/shutter_button"}
#创建活动拍照完成按钮
my_activity_shutter_done = {"resourceId":"com.android.camera:id/done_button"}
#创建活动拍照完成取消按钮
my_activity_shutter_cancel = {"resourceId":"com.android.camera:id/done_button"}
#创建活动拍照完成,裁剪按钮确定按钮
my_activity_shutter_crop_confirm = {"resourceId":"com.hawatalk.live:id/menu_crop"}
"""消息tab页面元素"""
#消息tab按钮
message={"xpath": '//*[@text="Message"]'}
#消息tab页面朋友按钮
message_friends={"resourceId":"com.hawatalk.live:id/iv_friend"}
#消息tab页面关注按钮
message_following={"resourceId":"com.hawatalk.live:id/iv_follow"}
#消息tab页面粉丝按钮
message_followers={"resourceId":"com.hawatalk.live:id/rl_fans"}
#消息tab页面黑名单按钮
message_blacklist={"resourceId":"com.hawatalk.live:id/iv_black_list"}
#消息tab页面消息列表,选择第几个,通过[*]实现
message_list={"resourceId":"com.hawatalk.live:id/rl_msg_item"}
#消息tab页面搜索框
message_search={"resourceId":"com.hawatalk.live:id/search_edit"}
#消息tab页面搜索框取消按钮
message_search_cancel={"resourceId":"com.hawatalk.live:id/cancel"}
#消息tab页面顶部四个按钮点击进入后列表人物头像
message_avatar={"resourceId":"com.hawatalk.live:id/avatar"}
#消息tab页面顶部四个按钮点击进入后列表人物点击进入聊天页面按钮
message_chat={"resourceId":"com.hawatalk.live:id/ll_content"}
#消息tab页面顶部四个按钮点击进入后列表人物点击关注、取消关注按钮
message_followornot={"resourceId":"com.hawatalk.live:id/iv_action"}
#消息tab页面顶部四个按钮点击进入后列表人物点击关注、取消关注按钮出现弹窗
message_followornot_popup={"xpath":'//*[@resource-id="android:id/content"]/android.view.ViewGroup[1]/android.view.ViewGroup[1]'}
#消息tab页面顶部四个按钮点击进入后列表人物点击取消关注出现的弹窗确认按钮
message_followornot_popup_confirm={"resourceId":"com.hawatalk.live:id/tv_cancel_follow"}
#消息tab页面顶部四个按钮点击进入后列表人物点击取消关注出现的弹窗取消按钮
message_followornot_popup_cancel={"resourceId":"com.hawatalk.live:id/tv_close"}
"""聊天页面元素"""
#聊天页面语音按钮
chat_voice={"resourceId":"com.hawatalk.live:id/buttonAudioMessage"}
#聊天页面键盘按钮
chat_keyboard={"resourceId":"com.hawatalk.live:id/buttonAudioMessageKeyboard"}
#聊天页面输入框
chat_input={"resourceId":"com.hawatalk.live:id/editTextMessage"}
#聊天页面表情按钮
chat_emoji={"resourceId":"com.hawatalk.live:id/emoji_button"}
#聊天页面表情列表,选择第几个,通过[*]实现
chat_emoji_list={"resourceId":"com.hawatalk.live:id/imgEmoji"}
#聊天页面礼物按钮
chat_gift={"resourceId":"com.hawatalk.live:id/buttonGiftMessage"}
#聊天页面发送按钮
chat_send={"resourceId":"com.hawatalk.live:id/buttonSendMessage"}
#聊天页面加号按钮
chat_more={"resourceId":"com.hawatalk.live:id/buttonImageMessage"}
test_case文件中conftest.py
# -*- coding: utf-8 -*-
# @Author : qyq
import uiautomator2
from auto_test.test_hawa.page_element import Page_Element
from auto_test.test_hawa.base import Base
import time
import pytest
#处理启动页的每日签到以及权限弹窗
@pytest.fixture(scope='class',autouse=True)
def qyq_fixture():
driver = uiautomator2.connect()
page=Page_Element.Page_Element
base=Base.Base(driver).find_element
driver.app_start(page.package_name,use_monkey=True,stop=True)
time.sleep(12)
if base(page.sign_close).exists:
base(page.sign_close).click_gone(maxretry=3,interval=1) #点击每日签到关闭按钮
else:
print("没有出现签到弹窗")
time.sleep(1)
driver.implicitly_wait(10)
if base(page.permissions_cancel).exists:
base(page.permissions_cancel).click_gone(maxretry=3, interval=1) # 点击权限弹窗取消按钮
else:
print("没有权限弹窗出现")
test_case文件中test_home.py
# -*- coding: utf-8 -*-
# @Author : qyq
import uiautomator2
import time
import pytest
import allure
from auto_test.test_hawa.base import Base
from auto_test.test_hawa.page_element import Page_Element
class Test_home:
driver=uiautomator2.connect()
page=Page_Element.Page_Element
base=Base.Base(driver).find_element
"""home页面hot中新用户tab点击,滑动"""
def test_home_hot__newcomer(qyq_fixture): #qyq_fixture中启动并处理了弹窗
Test_home.base(Test_home.page.home_newcomer).click()
print("click newcomer success")
time.sleep(2)
Test_home.driver.swipe(700,2700,700,400)
time.sleep(1)
Test_home.driver.swipe(500, 600, 500, 2900)
time.sleep(1)
#返回hottab
Test_home.base(Test_home.page.home_hot).click()
time.sleep(2)
"""点击hot列表中的房间进入房间再退出"""
def test_home_hot__hot(self):
Test_home.base(Test_home.page.home_hot).click()
print("click hot success")
time.sleep(2)
Test_home.base(Test_home.page.home_list)[2].click()
time.sleep(2)
# 需要判断房间是否要密码,要密码就不进
if Test_home.base(Test_home.page.room_password_input).exists:
Test_home.base(Test_home.page.room_password_cancel).click()
else:
Test_home.driver.swipe_ext("right")
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350,350,1000,350)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.room_exit).click(timeout=240)
print("click exit success")
"""点击到local分类,进入房间再退出,然后滑动列表"""
def test_home_hot__local(self):
#切换到local分类
Test_home.base(Test_home.page.home_local).click_gone(maxretry=1,interval=1)
print("click local success")
#点击列表进入聊天房间
Test_home.base(Test_home.page.home_list)[4].click()
time.sleep(5)# 需要判断房间是否要密码,要密码就不进
if Test_home.base(Test_home.page.room_password_input).exists:
Test_home.base(Test_home.page.room_password_cancel).click()
else:
pass
#Test_home.base(Test_home.page.room_turnoff).click()
#点击发送信息按钮,然后收起
Test_home.base(Test_home.page.room_msg_send).click_gone(maxretry=1,interval=1)
time.sleep(2)
Test_home.driver.swipe_ext("right")
time.sleep(2)
#点击礼物按钮,然后收起
Test_home.base(Test_home.page.room_gift).click()
time.sleep(2)
Test_home.driver.swipe_ext("right")
#点击信箱按钮,然后收起
Test_home.base(Test_home.page.room_msgbox).click_gone(maxretry=1,interval=1)
time.sleep(2)
Test_home.driver.swipe_ext("right")
#点击设置按钮,然后收起
Test_home.base(Test_home.page.room_setting).click_gone(maxretry=1,interval=1)
time.sleep(2)
Test_home.driver.swipe_ext("right")
#点击游戏按钮,然后收起
Test_home.base(Test_home.page.room_game).click()
time.sleep(2)
Test_home.driver.swipe_ext("right")
#点击火箭按钮,然后收起
Test_home.base(Test_home.page.room_rocket).click()
time.sleep(2)
Test_home.driver.swipe_ext("right")
#点击活动按钮,然后收起
Test_home.base(Test_home.page.room_activity).click_gone(maxretry=2,interval=1)
time.sleep(2)
Test_home.driver.swipe_ext("right")
time.sleep(2)
#退出房间
Test_home.driver.swipe_ext("right")
Test_home.driver.implicitly_wait(10)
time.sleep(2)
Test_home.base(Test_home.page.room_exit).click(timeout=260)
#返回到local分类,滑动列表
Test_home.driver.swipe(700, 2700, 700, 400)
time.sleep(1)
Test_home.driver.swipe(500, 600, 500, 2900)
time.sleep(2)
# 返回hottab
Test_home.base(Test_home.page.home_hot).click()
time.sleep(1)
"""点击rank排行榜进入,点击切换各榜单"""
def test_home_hot_rank(self):
Test_home.base(Test_home.page.home_rank).click()
print("click rank success")
time.sleep(5)
#点击第一名头像,然后返回
Test_home.base(Test_home.page.rank_first).click()
Test_home.base(Test_home.page.person_load_more).wait_gone(timeout=10)
time.sleep(5)
Test_home.driver.swipe_ext("right")
print("first ok")
#点击第二名头像,然后返回
time.sleep(0.5)
Test_home.base(Test_home.page.rank_second).click()
Test_home.base(Test_home.page.person_load_more).wait_gone(timeout=10)
time.sleep(5)
Test_home.driver.swipe_ext("right")
print("second ok")
#点击第三名头像,然后返回
time.sleep(0.5)
Test_home.base(Test_home.page.rank_third).click()
Test_home.base(Test_home.page.person_load_more).wait_gone(timeout=10)
time.sleep(5)
Test_home.driver.swipe_ext("right")
print("third ok")
#点击其他人,然后返回
time.sleep(0.5)
Test_home.base(Test_home.page.rank_other)[1].click()
Test_home.base(Test_home.page.person_load_more).wait_gone(timeout=10)
time.sleep(5)
Test_home.driver.swipe_ext("right")
#切换到charm,week,month,last_month排行榜切换
time.sleep(2)
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350, duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.rank_charm).click(timeout=240)
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350, duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.rank_week).click(timeout=240)
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350, duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.rank_month).click(timeout=260)
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350, duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.rank_last_month).click(timeout=260)
#切换到房间,week,month,last_month排行榜切换
time.sleep(0.5)
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350, duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.rank_room).click(timeout=260)
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350, duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.rank_week).click(timeout=260)
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350, duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.rank_month).click(timeout=260)
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350, duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.rank_last_month).click(timeout=260)
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350, duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.rank_hour).click(timeout=260)
time.sleep(2)
#返回hottab
Test_home.driver.swipe_ext("right")
time.sleep(1)
'''点击cp榜,进入;然后点转盘进入用户主页,返回;切换cp广场、排行榜、收入榜,切换回排行榜,点击帮助、关闭帮助弹窗'''
def test_home_hot_cp(self):
Test_home.base(Test_home.page.home_cp).click()
print("click cp success")
time.sleep(15)
#点击转盘,进入用户主页,返回
Test_home.base(Test_home.page.cprank_wheel_top1).click(timeout=60)
time.sleep(2)
while Test_home.base(Test_home.page.person_load_more).exists:
time.sleep(2)
break
Test_home.driver.swipe_ext("right")
time.sleep(2)
Test_home.base(Test_home.page.cprank_wheel_top3).click(timeout=60)
while Test_home.base(Test_home.page.person_load_more).exists:
time.sleep(2)
break
time.sleep(2)
Test_home.driver.swipe_ext("right")
time.sleep(2)
#切换到cpsquare
Test_home.base(Test_home.page.cprank_square).click()
time.sleep(2)
#切换到reward
Test_home.base(Test_home.page.cprank_reward).click()
time.sleep(2)
#切换到cp rank
Test_home.base(Test_home.page.cprank_rank).click()
time.sleep(5)
#点击帮助,关闭帮助
Test_home.base(Test_home.page.cprank_rank_help).click()
time.sleep(2)
Test_home.base(Test_home.page.cprank_rank_help_close).click()
time.sleep(2)
# 返回hottab
Test_home.driver.swipe_ext("right")
time.sleep(2)
"""活动页面点击进入,然后进入某个活动详情页面,点击页面的分享、订阅、进入房间、用户头像等,在退出活动详情页面,返回列表切换到正在进行的、结束的活动tab"""
def test_home_hot_activity(self):
Test_home.base(Test_home.page.home_activity).click()
print("click activity success")
time.sleep(2)
#点击活动进入活动详情页面
Test_home.base(Test_home.page.activity_list1)[4].click()
time.sleep(1)
#点击订阅活动
Test_home.base(Test_home.page.activity_subscribe).click()
#点击分享
Test_home.base(Test_home.page.activity_share).click()
time.sleep(1)
Test_home.driver.swipe_ext("right")
#取消订阅
time.sleep(2)
Test_home.base(Test_home.page.activity_subscribe).click()
#点击进入房间按钮,然后退出房间
Test_home.base(Test_home.page.activity_joinroom).click()
time.sleep(2)
# 需要判断房间是否要密码,要密码就不进
if Test_home.base(Test_home.page.room_password_input).exists:
Test_home.base(Test_home.page.room_password_cancel).click()
else:
Test_home.driver.swipe_ext("right")
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.room_exit).click(timeout=240)
time.sleep(5)
#点击头像
Test_home.base(Test_home.page.activity_avatar)[2].click()
time.sleep(2)
Test_home.driver.swipe_ext("right")
time.sleep(2)
# 点击活动页面返回按钮退出活动
Test_home.driver.swipe_ext("right")
time.sleep(2)
#Test_home.base(Test_home.page.activity_back).click(timeout=260)
#切换到正在进行的活动tab
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.activity_progress_activity).click(timeout=260)
#切换到已结束的活动tab
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.activity_finished_activity).click(timeout=260)
time.sleep(2)
# 返回hottab
Test_home.driver.swipe_ext("right")
time.sleep(2)
"""进入到我的活动页面,两个tab相互切换"""
def test_home_hot_activity_myactivity(self):
Test_home.base(Test_home.page.home_activity).click()
print("click activity success")
time.sleep(2)
#点击我的活动进入我的活动页面
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.activity_my_activity).click(timeout=260)
time.sleep(1)
#切换到posted tab
Test_home.base(Test_home.page.my_activity_posted).click()
time.sleep(1)
#切换到subscribed tab
Test_home.base(Test_home.page.my_activity_subscribed).click()
time.sleep(2)
# 返回hottab
Test_home.driver.swipe_ext("right")
time.sleep(1)
Test_home.driver.swipe_ext("right")
time.sleep(1)
"""进入活动页面--》我的活动--》创建活动"""
def test_home_hot_activity_create_activity(self):
Test_home.base(Test_home.page.home_activity).click()
print("click activity success")
time.sleep(2)
# 点击我的活动进入我的活动页面
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.activity_my_activity).click(timeout=260)
time.sleep(1)
#点击创建活动
Test_home.base(Test_home.page.my_activity_add).click()
time.sleep(1)
#输入活动标题、描述
Test_home.base(Test_home.page.my_activity_title).set_text("yy")
time.sleep(1)
Test_home.base(Test_home.page.my_activity_description).set_text("测试活动描述")
"""选择时间、活动时长"""
#选择时间
Test_home.base(Test_home.page.my_activity_starttime).click()
time.sleep(1)
#滑动选择月
Test_home.driver.swipe(420,2950,420,2800)
time.sleep(1)
#滑动选择日
Test_home.driver.swipe(720, 2950, 720, 2800)
time.sleep(1)
#滑动选择小时
Test_home.driver.swipe(1020, 2950, 1020, 2800)
time.sleep(1)
#滑动选择分钟
Test_home.driver.swipe(1320, 2950, 1320, 2800)
time.sleep(1)
#点击确定
Test_home.base(Test_home.page.my_activity_starttime_confirm).click()
#点击选择活动时长按钮
Test_home.base(Test_home.page.my_activity_duration).click()
time.sleep(1)
#滑动选择时长
Test_home.driver.swipe(720,3000,720,2800)
time.sleep(1)
#点击确定
Test_home.base(Test_home.page.my_activity_duration_confirm).click()
#点进创建活动下一步按钮
Test_home.base(Test_home.page.my_activity_next).click()
time.sleep(1)
"""选择活动背景图片"""
#点击选择图片按钮,通过[*]选择第几张
Test_home.base(Test_home.page.my_activity_background)[2].click()
time.sleep(1)
#点击customized
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.my_activity_customized).click(timeout=260)
time.sleep(1)
#点击选择拍照按钮
Test_home.base(Test_home.page.my_activity_takephoto).click()
time.sleep(1)
#点击进行拍照
Test_home.base(Test_home.page.my_activity_shutter).click()
#点击拍照完成按钮
Test_home.base(Test_home.page.my_activity_shutter_done).click()
time.sleep(1)
#拍照完成点击裁剪确认
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.my_activity_shutter_crop_confirm).click(timeout=260)
time.sleep(3)
# 再次点击customized
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.my_activity_customized).click(timeout=260)
time.sleep(1)
#点击相册按钮
Test_home.base(Test_home.page.my_activity_album).click()
time.sleep(1)
#如果有相册权限弹窗出现,选择允许
if Test_home.base(Test_home.page.my_activity_album_allow).exists:
Test_home.base(Test_home.page.my_activity_album_allow).click()
else:
pass
#点击选择图片
Test_home.base(Test_home.page.my_activity_album_select)[17].click()
#如果选择的相片有大于5m,出现提示,点击关闭提示弹窗
if Test_home.base(Test_home.page.my_activity_album_select_5m_text).exists:
Test_home.base(Test_home.page.my_activity_album_select_5m_ok).click()
time.sleep(1)
Test_home.driver.swipe_ext("right")
else:
Test_home.base(Test_home.page.my_activity_album_select_completed).click()
time.sleep(1)
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.my_activity_album_select_crop_confirm).click(timeout=260)
time.sleep(3)
#返回到home页面
Test_home.driver.swipe_ext("right")
time.sleep(1)
Test_home.driver.swipe_ext("right")
time.sleep(1)
Test_home.driver.swipe_ext("right")
time.sleep(1)
Test_home.driver.swipe_ext("right")
time.sleep(5)
"""hot列表banner点击,若点击到活动,返回;若点击进入房间,返回"""
def test_home_hot_banner_list(self):
Test_home.base(Test_home.page.home_hot_banner_list).click()
time.sleep(1)
if Test_home.base(Test_home.page.home_banner_share).exists:
Test_home.driver.swipe_ext("right")
print("1")
elif Test_home.base(Test_home.page.room_gift).exists:
# 需要判断房间是否要密码,要密码就不进
if Test_home.base(Test_home.page.room_password_input).exists:
Test_home.base(Test_home.page.room_password_cancel).click()
else:
Test_home.driver.swipe_ext("right")
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.room_exit).click(timeout=240)
print("click")
else:
Test_home.driver.swipe_ext("right")
print("2")
"""hot顶部banner点击,若点击到活动,返回;若点击进入房间,返回"""
def test_home_hot_banner_top(self):
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350,duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.home_hot_banner_top).click(timeout=240)
time.sleep(2)
if Test_home.base(Test_home.page.home_banner_share).exists:
Test_home.driver.swipe_ext("right")
time.sleep(1)
print("1")
elif Test_home.base(Test_home.page.room_gift).exists:
# 需要判断房间是否要密码,要密码就不进
if Test_home.base(Test_home.page.room_password_input).exists:
Test_home.base(Test_home.page.room_password_cancel).click()
else:
Test_home.driver.swipe_ext("right")
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.room_exit).click(timeout=240)
else:
pass
print("2")
"""从home页面的hot tab切换到me tab,进入房间,返回,切换回到hot tab"""
def test_home_me(self):
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350, duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.home_me).click(timeout=240)
print("click home_me success")
time.sleep(1)
#点击进入房间,在退出
Test_home.base(Test_home.page.home_list)[0].click()
time.sleep(2)
# 需要判断房间是否要密码,要密码就不进
if Test_home.base(Test_home.page.room_password_input).exists:
Test_home.base(Test_home.page.room_password_cancel).click()
else:
Test_home.driver.swipe_ext("right")
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350,duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.room_exit).click(timeout=240)
time.sleep(1)
#切换到followingtab,进入房间,在退出,返回到browae tab
Test_home.base(Test_home.page.home_me_following).click()
time.sleep(1)
Test_home.base(Test_home.page.home_list)[0].click()
time.sleep(2)
# 需要判断房间是否要密码,要密码就不进
if Test_home.base(Test_home.page.room_password_input).exists:
Test_home.base(Test_home.page.room_password_cancel).click()
else:
Test_home.driver.swipe_ext("right")
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350,duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.room_exit).click(timeout=240)
time.sleep(1)
Test_home.base(Test_home.page.home_me_browse).click()
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350,350,1000,350)
else:
pass
Test_home.base(Test_home.page.home_top_hot).click(timeout=240)
"""切换到me,然后点击自己创建的房间,进入后退出"""
def test_home_me_create_room(self):
#礼物特效处理
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350,350,1000,350)
else:
pass
Test_home.base(Test_home.page.home_me).click(timeout=240)
print("click home_me success")
time.sleep(1)
#点击进入房间,在退出
Test_home.base(Test_home.page.home_me_create).click()
time.sleep(2)
Test_home.driver.swipe_ext("right")
Test_home.driver.implicitly_wait(5)
Test_home.base(Test_home.page.home_me_create_room_exit).click()
time.sleep(1)
#切换到hot tab
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350,350,1000,350)
else:
pass
Test_home.base(Test_home.page.home_top_hot).click(timeout=240)
"""切换到smalltalk,点击切换smalltalk中各个分类tab"""
def test_home_smalltalk(self):
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350,350,1000,350,duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.home_smalltalk).click(timeout=240)
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350,350,1000,350,duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.home_smalltalk_allchat).click(timeout=240)
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350,350,1000,350,duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.home_smalltalk_talktalk).click(timeout=240)
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350,350,1000,350,duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.home_smalltalk_funclub).click(timeout=240)
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350,350,1000,350,duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.home_smalltalk_todayhotspot).click(timeout=240)
#点击列表中的房间进入,然后退出
Test_home.base(Test_home.page.home_smalltalk_list)[0].click()
time.sleep(2)
#需要判断房间是否要密码,要密码就不进
if Test_home.base(Test_home.page.room_password_input).exists:
Test_home.base(Test_home.page.room_password_cancel).click()
else:
Test_home.driver.swipe_ext("right")
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350,350,1000,350,duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.room_exit).click(timeout=240)
#点击smalltalk列表的随机按钮进入房间然后退出
Test_home.base(Test_home.page.home_smalltalk_randommatch).click()
time.sleep(2)
if Test_home.base(Test_home.page.room_password_input).exists:
Test_home.base(Test_home.page.room_password_cancel).click()
else:
Test_home.driver.swipe_ext("right")
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350, 350, 1000, 350,duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.room_exit).click(timeout=240)
#返回hottab
if Test_home.base(Test_home.page.gift_effect).exists:
Test_home.driver.swipe(350,350,1000,350,duration=0.1)
print("清除礼物特效")
else:
pass
Test_home.base(Test_home.page.home_top_hot).click(timeout=240)
test_case文件中test_message.py
# -*- coding: utf-8 -*-
# @Author : qyq
import uiautomator2
import time
import pytest
import allure
from auto_test.test_hawa.base import Base
from auto_test.test_hawa.page_element import Page_Element
class Test_message:
driver=uiautomator2.connect()
page=Page_Element.Page_Element
base=Base.Base(driver).find_element
"""messagetab顶部四个按钮点击,进入后分别点击列表中的用户头像、点击进入聊天以及关注与否按钮,最后返回到message tab"""
def test_message_top_4button(self):
#切换到message tab
Test_message.base(Test_message.page.message).click()
#处理页面顶部可能出现的礼物特效
if Test_message.base(Test_message.page.gift_effect).exists:
Test_message.driver.swipe(350, 350, 1000, 350, duration=0.1)
time.sleep(0.5)
print("清除礼物特效")
else:
pass
#点击blacklist按钮,进入,然后返回
Test_message.base(Test_message.page.message_blacklist).click(timeout=10)
time.sleep(1)
Test_message.driver.swipe_ext("right")
time.sleep(1)
# 处理页面顶部可能出现的礼物特效
if Test_message.base(Test_message.page.gift_effect).exists:
Test_message.driver.swipe(350, 350, 1000, 350, duration=0.1)
time.sleep(0.5)
print("清除礼物特效")
else:
pass
#点击followers按钮,进入,点击列表中的头像,进入个人主页返回,点击进入聊天页面返回,点击关注,然后返回message tab
Test_message.base(Test_message.page.message_followers).click(timeout=10)
time.sleep(1)
Test_message.base(Test_message.page.message_avatar).click()
time.sleep(5)
Test_message.driver.swipe_ext("right")
time.sleep(1)
Test_message.base(Test_message.page.message_chat).click()
Test_message.driver.swipe_ext("right")
time.sleep(3)
Test_message.base(Test_message.page.message_followornot).click()
time.sleep(1)
if Test_message.base(Test_message.page.message_followornot_popup).exists:
Test_message.base(Test_message.page.message_followornot_popup_cancel).click()
time.sleep(1)
else:
time.sleep(1)
Test_message.driver.swipe_ext("right")
time.sleep(1)
# 处理页面顶部可能出现的礼物特效
if Test_message.base(Test_message.page.gift_effect).exists:
Test_message.driver.swipe(350, 350, 1000, 350, duration=0.1)
time.sleep(0.5)
print("清除礼物特效")
else:
pass
#点击follwing按钮,进入,点击列表中的头像,进入个人主页返回,点击进入聊天页面返回,点击关注,然后返回message tab
Test_message.base(Test_message.page.message_following).click(timeout=10)
time.sleep(1)
Test_message.base(Test_message.page.message_avatar).click()
time.sleep(5)
Test_message.driver.swipe_ext("right")
time.sleep(1)
Test_message.base(Test_message.page.message_chat).click()
Test_message.driver.swipe_ext("right")
time.sleep(3)
Test_message.base(Test_message.page.message_followornot).click()
time.sleep(1)
if Test_message.base(Test_message.page.message_followornot_popup).exists:
Test_message.base(Test_message.page.message_followornot_popup_cancel).click()
time.sleep(1)
else:
time.sleep(1)
Test_message.driver.swipe_ext("right")
time.sleep(1)
# 处理页面顶部可能出现的礼物特效
if Test_message.base(Test_message.page.gift_effect).exists:
Test_message.driver.swipe(350, 350, 1000, 350, duration=0.1)
time.sleep(0.5)
print("清除礼物特效")
else:
pass
# 点击friends按钮,进入,点击列表中的头像,进入个人主页返回,点击进入聊天页面返回,点击关注,然后返回message tab
Test_message.base(Test_message.page.message_friends).click(timeout=10)
time.sleep(1)
Test_message.base(Test_message.page.message_avatar).click()
time.sleep(5)
Test_message.driver.swipe_ext("right")
time.sleep(1)
Test_message.base(Test_message.page.message_chat).click()
Test_message.driver.swipe_ext("right")
time.sleep(3)
Test_message.base(Test_message.page.message_followornot).click()
time.sleep(1)
if Test_message.base(Test_message.page.message_followornot_popup).exists:
Test_message.base(Test_message.page.message_followornot_popup_cancel).click()
time.sleep(1)
else:
time.sleep(1)
Test_message.driver.swipe_ext("right")
"""message顶部四个按钮前三个按钮进入后的搜索框搜索测试:在搜索框输入内容进行搜索,然后点击取消,返回消息tab"""
def test_message_search(self):
#切换到message tab
Test_message.base(Test_message.page.message).click()
time.sleep(1)
#处理页面顶部可能出现的礼物特效
if Test_message.base(Test_message.page.gift_effect).exists:
Test_message.driver.swipe(350, 350, 1000, 350, duration=0.1)
time.sleep(0.5)
print("清除礼物特效")
else:
pass
#点击friends按钮,进入,点击搜索框进行搜索返回
Test_message.base(Test_message.page.message_friends).click(timeout=10)
time.sleep(1)
Test_message.base(Test_message.page.message_search).click()
time.sleep(1)
Test_message.base(Test_message.page.message_search).set_text("测试")
time.sleep(4)
Test_message.base(Test_message.page.message_search).click()
Test_message.driver.press("enter")
time.sleep(1)
Test_message.base(Test_message.page.message_search).clear_text()
time.sleep(1)
if Test_message.base(Test_message.page.gift_effect).exists:
Test_message.driver.swipe(350, 350, 1000, 350, duration=0.1)
time.sleep(0.5)
print("清除礼物特效")
else:
pass
Test_message.base(Test_message.page.message_search_cancel).click()
Test_message.driver.swipe_ext("right")
time.sleep(1)
"""messagetab点击列表用的用户进入聊天,发送,然后返回message tab"""
def test_message_chat(self):
# 切换到message tab
Test_message.base(Test_message.page.message).click()
time.sleep(1)
Test_message.base(Test_message.page.message_list)[0].click()
time.sleep(0.5)
Test_message.base(Test_message.page.chat_voice).click()
time.sleep(1)
Test_message.base(Test_message.page.chat_keyboard).click()
Test_message.base(Test_message.page.chat_gift).click()
time.sleep(2)
Test_message.driver.swipe_ext("right")
Test_message.base(Test_message.page.chat_more).click()
Test_message.driver.swipe_ext("right")
Test_message.base(Test_message.page.chat_input).set_text("HELLO")
Test_message.base(Test_message.page.chat_emoji).click()
Test_message.base(Test_message.page.chat_emoji_list)[1].click()
#Test_message.base(Test_message.page.chat_send).click()
Test_message.driver.swipe_ext("right")
time.sleep(1)
Test_message.driver.swipe_ext("right")
main.py
# -*- coding: utf-8 -*-
# @Author : qyq
import pytest
import time
#给测试报告名字加上时间戳
new=time.strftime("%Y%m%d%H%M%S")
pytest.main(["-vs","--html=./report/test_report{}.html".format(new)])
测试报告部分截图