代码拉取完成,页面将自动刷新
# coding=utf-8
import smtplib
import time
# from lianxi.mail1101 import sendEmail
from appium import webdriver
import unittest
from HTMLTestRunner import HTMLTestRunner
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
from email.mime.multipart import MIMEMultipart
class test_appium(unittest.TestCase):
@classmethod
def setUpClass(cls):
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1.1' # 6.0
desired_caps['deviceName'] = 'Android Emulator' # Android Emulator
desired_caps['appPackage'] = 'com.changhong.app'
desired_caps['appActivity'] = 'com.iwant.ui.SplashActivity'
cls.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)
cls.driver.implicitly_wait(30)
def test_001Login(self):
'''登录测试'''
self.driver.find_element_by_id("com.changhong.app:id/phone").send_keys("12345678912")
self.driver.find_element_by_id("com.changhong.app:id/password").send_keys("1234")
self.driver.find_element_by_id("com.changhong.app:id/btn_login").click()
a = self.driver.find_element_by_id("com.changhong.app:id/tv_hot_name").text
assert a == "长虹随身WiFi_00000006"
print('登录成功!')
def test_002switch_operator(self):
'''切换运营商'''
#test_appium.test_Login(self)
self.driver.find_element_by_id("com.changhong.app:id/cmcc").click()
self.driver.find_element_by_id("com.changhong.app:id/custom_dialog_confirm").click()
print("切换运营商成功!")
def test_003change_password(self):
'''更换设备密码'''
#test_appium.test_switch_operator(self)
width = self.driver.get_window_size()['width']
height = self.driver.get_window_size()['height']
# print(width,height)
x1 = width * 0.5
y1 = height * 0.9
y2 = height * 0.25
self.driver.swipe(x1, y1, x1, y2)
self.driver.find_element_by_id("com.changhong.app:id/edt_hot_pwd").clear().send_keys('123456789') # 切换热点密码
self.driver.back() # 返回主页
self.driver.find_element_by_id("com.changhong.app:id/btn_commit").click() # 点击确认按钮
def test_004Recharge(self):
'''设备充值'''
self.driver.find_element_by_id("com.changhong.app:id/rb_charge").click() # 点击充值
b = self.driver.find_element_by_id("com.changhong.app:id/tv_charge_log").text
if b == "充值记录":
print("进入充值界面。")
self.driver.find_element_by_id("com.changhong.app:id/charge_text").click()
self.driver.find_element_by_id("com.changhong.app:id/cashpay_checkbox").click()
self.driver.find_element_by_id("com.changhong.app:id/confirm_pay_btn").click()
su = self.driver.find_element_by_id("com.changhong.app:id/pay_success").text
if su == "支付成功":
print("余额充值支付成功")
self.driver.find_element_by_id("com.changhong.app:id/result_confirm").click() # 点击确认按钮返回充值主页面
def test_005User_Info(self):
'''查询用户信息'''
self.driver.find_element_by_id("com.changhong.app:id/rb_mine").click()
tel = self.driver.find_element_by_id("com.changhong.app:id/user_tel").text
if tel == "12345678912":
print('用户信息查询成功')
def test_006about_us(self):
'''关于我们模块'''
self.driver.find_element_by_id("com.changhong.app:id/rl_about").click()
title = self.driver.find_element_by_id("com.changhong.app:id/bar_title").text
if title == "关于我们":
print("关于我们页面")
self.driver.back() # 返回我模块
def test_007contact_us(self):
'''联系我们模块'''
self.driver.find_element_by_id("com.changhong.app:id/rl_call").click() # 联系我们
self.driver.find_element_by_id("com.changhong.app:id/custom_dialog_cancel").click() # 暂时不用
def test_008Help_feedback(self):
'''帮助反馈'''
self.driver.find_element_by_id("com.changhong.app:id/rl_help").click() # 帮助反馈界面
bartitle = self.driver.find_element_by_id("com.changhong.app:id/bar_title").text
if bartitle == "帮助与反馈":
print("进入帮助反馈界面成功")
def test_009User_uide(self):
'''用户指南'''
self.driver.find_element_by_id("com.changhong.app:id/user_guide").click()
userti = self.driver.find_element_by_id("com.changhong.app:id/bar_title").text
if userti == "用户指南":
print("进入用户指南界面成功")
self.driver.back()
self.driver.back()
# # '''问题反馈'''
# # # driver.find_element_by_id("com.changhong.app:id/feed_back").click()
# # # # driver.find_element_by_id("com.changhong.app:id/feedback_content").send_keys("test123")
# # # # driver.find_element_by_id("com.changhong.app:id/contact_info").send_keys("820360532@qq.com")
# # # # driver.back()
# # # # driver.find_element_by_id("com.changhong.app:id/submit_feed_back").click()
# # # # #time.sleep(10)
# # # # print('问题反馈成功')
# # # driver.
# # # driver.back()
# #
def test_010Switching_device(self):
'''切换设备的IMEI'''
self.driver.find_element_by_id("com.changhong.app:id/rl_device_manager").click() # 点击设备
self.driver.quit()
# @classmethod
# def tearDownClass(cls):
# cls.driver.quit()
def sendEmail(filename):
# 输入寄件人邮件地址和口令
from_addr = "13265641516@163.com"
password = "Cp199351"
# 输入SMTP 服务器地址
smtp_server = 'smtp.163.com'
# 输入收件人地址
to_addr = "820360532@qq.com"
# plain 表示纯文本
#msg = MIMEText("hello, 超哥,我在学习Python...", "plain", "utf-8")
msg = MIMEMultipart()
# 填写完整点,不然会被判断为垃圾邮件
subject = '这是一个主题哦test'
msg['From'] = from_addr
msg['To'] = to_addr
msg['Subject'] = Header(subject, 'utf-8').encode()
with open(filename,'rb') as f:
fc = f.read()
txt = MIMEText(fc,'html','utf-8')
msg.attach(txt)
att = MIMEText(open(filename,'rb').read(),'html','utf-8')
att["Content-Type"] = "application/octet-stream"
att.add_header("Content-Disposition", "attachment", filename=("gbk", "", "長虹app测试结果.html"))
msg.attach(att)
import smtplib
# SMTP协议默认端口是25
server = smtplib.SMTP(smtp_server, 25)
# 打印出和SMTP服务器交互的所有信息
#server.set_debuglevel(1)
# 输入登陆信息
server.login(from_addr, password)
# 发送邮件
server.sendmail(from_addr, [to_addr], msg.as_string())
server.quit()
if __name__ == '__main__':
suite = unittest.TestSuite() #构造测试集
# suite.addTest(test_appium('test_001Login'))
# suite.addTest(test_appium('test_002switch_operator'))
# suite.addTest(test_appium('test_003change_password'))
# suite.addTest(test_appium('test_004Recharge'))
# suite.addTest(test_appium('test_005User_Info'))
# suite.addTest(test_appium('test_006about_us'))
# suite.addTest(test_appium('test_007contact_us'))
# suite.addTest(test_appium('test_008Help_feedback'))
# suite.addTest(test_appium('test_009User_uide'))
# suite.addTest(test_appium('test_010Switching_device'))
suite.addTest(unittest.makeSuite(test_appium))
now = time.strftime("%Y-%m-%d %H_%M_%S")
filename = r'E:\testdoem\lianxi\ '+ now + 'result.html'
fp=open(filename,'wb')
runner = HTMLTestRunner(stream=fp,title='长虹APP测试报告',description='测试情况')
runner.run(suite)
fp.close()
sendEmail(filename)
#unittest.runner(suite)
#unittest.TextTestRunner(verbosity=2).run(suite)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。