# -*- coding: utf-8 -*-
from appium import webdriver
from time import sleep
import io
import unittest
import os
# import sys
# import time
# import re
# import datetime
# import HTMLTestRunner
import unittest,sys,time,re,datetime,HTMLTestRunner
reload(sys)
sys.setdefaultencoding('utf-8')
class RLPAndroidTest(unittest.TestCase):
def setUp(self):
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0.1'
desired_caps['deviceName'] = 'PD1616'
desired_caps['appPackage'] = 'com.sanqimei.app'
desired_caps['appActivity'] = 'welcome.activity.LauncherActivity'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
def tearDown(self):
self.driver.close_app()
self.driver.quit()
#获得机器屏幕大小x,y
def getSize(self):
x = self.driver.get_window_size()['width']
y = self.driver.get_window_size()['height']
return (x,y)
#屏幕向左滑动
def swipLeft(self):
for i in range(3):
l = self.getSize()
self.driver.swipe(l[0]*0.75,l[1]*0.5,l[0]*0.05,l[1]*0.5,1000)
#屏幕向上滑动
def swipUp(self):
for i in range(1):
s=self.getSize()
self.driver.swipe(s[0]*0.5,s[1]*0.75,s[0]*0.5,s[1]*0.25,1000)
#注册场景
def Login_p(self):
self.swipLeft()
sleep(2)
el_welcome = self.driver.find_element_by_xpath ("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.support.v4.view.ViewPager/android.widget.ImageView")
el_welcome.click()
sleep(7)
el_welcome = self.driver.find_element_by_id ("com.sanqimei.app:id/maintab_layout_profile")
el_welcome.click()
sleep(2)
#点击注册
el_signup = self.driver.find_element_by_id ("com.sanqimei.app:id/tv_sign_up").click()
sleep(1)
el_signup_phone = self.driver.find_element_by_id('com.sanqimei.app:id/ed_signup_phonenumber')
el_signup_phone.set_value("17626043523")
#验证码写死,不点击
#el_signup_sendcode = self.driver.find_element_by_id ("com.sanqimei.app:id/btn_signup_sendvertification").click()
el_signup_code = self.driver.find_element_by_id('com.sanqimei.app:id/ed_signup_vetification')
el_signup_code.set_value("1111")
#回收虚拟键盘
self.driver.press_keycode(111)
el_new_password = self.driver.find_element_by_id('com.sanqimei.app:id/ed_signup_password')
el_new_password.set_value("123456")
#回收下虚拟键盘
self.driver.press_keycode(111)
#点击注册完成
el_signup_complete = self.driver.find_element_by_id ("com.sanqimei.app:id/btn_signup_register").click()
sleep(4)
#注册成功后登录检测
el_username = self.driver.find_element_by_id ("com.sanqimei.app:id/login_account")
el_username.set_value ('17626043523')
el_password = self.driver.find_element_by_id ("com.sanqimei.app:id/login_password")
el_password.set_value ('123456')
sleep(1)
# # self.driver.hide_keyboard()
self.driver.press_keycode(111)
sleep(3)
el_loginButton = self.driver.find_element_by_id("com.sanqimei.app:id/login_btn").click()
sleep(3)
#登录后界面-断言
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/iv_setting'),'setting button is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/iv_aboutme_go_message'),'chat button is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/re_go_myinfo'),'username and picture are not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/about_me_integration'),'meidou and picture is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/re_aboutme_shiguang_card'),'shiguang_card is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/re_aboutme_reserve'),'yuyue is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/re_aboutme_all_order'),'dingdan is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/re_aboutme_collection'),'shoucang is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/re_aboutme_diary'),'diary is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/maintab_layout_homepage'),'master page is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/maintab_layout_star'),'beauty_star is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/maintab_layout_discover'),'discover is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/maintab_layout_profile'),'person_information is not exist,Fail')
sleep(1)
#登出
el_setting = self.driver.find_element_by_id("com.sanqimei.app:id/iv_setting").click()
sleep(1)
el_logout = self.driver.find_element_by_id("com.sanqimei.app:id/tv_setting_logoff").click()
sleep(2)
el_button1 = self.driver.find_element_by_id("android:id/button1").click()
sleep(3)
#登出后首页-断言
self.assertIsNotNone(self.driver.find_element_by_xpath ('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout[1]/android.support.v4.view.ViewPager/android.widget.ImageView'),'locals_banner_search error')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_xpath ('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/android.widget.AdapterView/android.widget.LinearLayout[1]'),'life_picture error')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_xpath ('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/android.widget.AdapterView/android.widget.LinearLayout[2]'),'hospital_picture error')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_xpath ('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/android.widget.AdapterView/android.widget.LinearLayout[3]'),'time_card_picture error')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_xpath ('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/android.widget.AdapterView/android.widget.LinearLayout[4]'),'order_server_picture error')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_xpath ('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.TextView[1]'),'37set_first_txt error')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_xpath ('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.TextView[2]'),'37set_second_txt error')
sleep(1)
self.swipUp()
sleep(2)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/maintab_layout_homepage'),'home page is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/maintab_layout_star'),'beauty star is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/maintab_layout_discover'),'discover is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/maintab_layout_profile'),'person_information is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('android:id/list'),'home page discover is not exist,Fail')
sleep(2)
#回到登录页面
el_welcome = self.driver.find_element_by_id ("com.sanqimei.app:id/maintab_layout_profile").click()
sleep(2)
#忘记密码-重置密码
el_forget = self.driver.find_element_by_id("com.sanqimei.app:id/tv_forget")
el_forget.click()
sleep(4)
el_forget_phone = self.driver.find_element_by_id('com.sanqimei.app:id/ed_forgetpassword_phone')
el_forget_phone.set_value("17626043523")
sleep(2)
#验证码写死,取消点击动作
el_verification = self.driver.find_element_by_id('com.sanqimei.app:id/ed_forgetpassword_verification')
el_verification.set_value("2222")
#输入新密码2次
el_newpasswd1 = self.driver.find_element_by_id('com.sanqimei.app:id/ed_forgetpassword_newpassword')
el_newpasswd1.set_value("111111")
el_newpasswd2 = self.driver.find_element_by_id('com.sanqimei.app:id/ed_forgetpassword_passwordagin')
el_newpasswd2.set_value("111111")
#点击完成
self.driver.press_keycode(111)
el_complete = self.driver.find_element_by_id('com.sanqimei.app:id/btn_forgetpassword_resignup').click()
sleep(4)
#验证登录
el_username = self.driver.find_element_by_id("com.sanqimei.app:id/login_account")
el_username.set_value ('17626043523')
el_password = self.driver.find_element_by_id ("com.sanqimei.app:id/login_password")
el_password.set_value ('111111')
sleep(1)
# # self.driver.hide_keyboard()回收虚拟键盘
self.driver.press_keycode(111)
sleep(3)
el_loginButton = self.driver.find_element_by_id("com.sanqimei.app:id/login_btn").click()
sleep(3)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/maintab_layout_homepage'),'homepage is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/maintab_layout_star'),'beauty star is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/maintab_layout_discover'),'discover is not exist,Fail')
sleep(1)
self.assertIsNotNone(self.driver.find_element_by_id ('com.sanqimei.app:id/maintab_layout_profile'),'person_information is not exist,Fail')
#关闭连接
def tearDown(self):
#self.driver.close_app()
self.driver.quit()
if __name__ == '__main__':
suite = unittest.TestSuite()
#注册 登录 注销 忘记密码
suite.addTest(RLPAndroidTest("Login_p"))
timestr = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
filename = "E:/appium_report/result_" + timestr + ".html"
print (filename)
fp = open(filename, 'wb')
runner = HTMLTestRunner.HTMLTestRunner(
stream=fp,
title='测试结果',
description='测试报告'
)
#suite = unittest.TestLoader().loadTestsFromTestCase(ContactsAndroidTests)
#unittest.TextTestRunner(verbosity=2).run(suite)
runner.run(suite)
#g_browser.quit()
fp.close() #测试报告关闭
网友评论