import requests from public import Log log = Log.Logger(logger='APIDataInfo').getLog() url = 'http://ic.cs1.gwchina.cn/system/connect' def get_token(): try: host = 'http://ic.cs1.gwchina.cn' endpoint = '/system/connect' headers = { "oem_type": "LSSW", "key": "98243574", "lang": "chs", "serial_no": "sn-android-parent" } url = ''.join(host + endpoint) resp = requests.post(url=url, json=headers) text = resp.json() token_value = text['token'] log.info("My_api -> get_token -> 获取token值 %s " % token_value) return token_value except: log.info("My_api -> get_token -> 获取token值失败 ") class GetApi(object): host = 'http://ic.cs1.gwchina.cn' token = get_token()
* Fix missing scroll bars in detail log (Podi). """ # TODO: color stderr # TODO: simplify javascript using ,ore than 1 class in the class attribute? import datetime import io import sys import time import unittest from xml.sax import saxutils from public import Log log = Log.Logger(logger='HTMLTestRunner').getLog() # ------------------------------------------------------------------------ # The redirectors below are used to capture output during testing. Output # sent to sys.stdout and sys.stderr are automatically captured. However # in some cases sys.stdout is already cached before HTMLTestRunner is # invoked (e.g. calling logging.basicConfig). In order to capture those # output, use the redirectors for the cached stream. # # e.g. # >>> logging.basicConfig(stream=HTMLTestRunner.stdout_redirector) # >>> class OutputRedirector(object): """ Wrapper to redirect stdout or stderr """
from public import Log from selenium import webdriver from appium import webdriver from config import phoneGetConfigInfo log = Log.Logger(logger='Appium').getLog() desired_caps = phoneGetConfigInfo.ReadConfig().readDesiredCapsData() log.critical('desired_caps : (%s) ' % desired_caps) class Appium(object): def __init__(self): self.desired_caps = phoneGetConfigInfo.ReadConfig( ).readDesiredCapsData() def driverClear(self): desired_caps = { 'platformName': 'Android', 'platformVersion': self.desired_caps['platformVersion'], 'deviceName': self.desired_caps['deviceName'], 'appPackage': self.desired_caps['appPackage'], # 'noReset' : 'True', # 去掉,每次启动app都会清除数据 'automationName': self.desired_caps['automationName'], 'appActivity': self.desired_caps['appActivity'], 'uuid': self.desired_caps['deviceName'], } self.driver = webdriver.Remote(self.desired_caps['remote'], desired_caps) self.driver.implicitly_wait(30) return self.driver
from PO.po_page import A6_area_man_page import unittest from public import Common, GetPhoneInfo, CreatePng, GetApiData, Log, ScreenAssert from time import sleep log = Log.Logger(logger='AreaTest').getLog() class AreaTest(unittest.TestCase): '''《安全区域》''' @classmethod def setUpClass(cls): log.critical("--------------------安全区域测试开始--------------------") def setUp(self): self.driver = GetPhoneInfo.Appium().driver() self.page = A6_area_man_page.AreaPage(self.driver) self.base = Common.Action(self.driver) self.png = CreatePng.CreatePNG(self.driver) self.api = GetApiData.GetApi() self.log = log @ScreenAssert.decorator def test_area_001(self): '''验证进入安全区域页面''' self.page.go_area_homepage() self.assertIsNotNone( self.base.get_assert('id', self.page.add_area_btn[1])) @ScreenAssert.decorator def test_area_002(self):
import os,time,smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.header import Header from email import encoders from email.mime.base import MIMEBase from public import Log log = Log.Logger(logger='SendEmail').getLog() # 3.定义:发送邮件,发送最新测试报告html def SendEmail(html_path,log_path): try: # 打开文件 f = open(html_path, 'rb') # 读取文件内容 mail_body = f.read() # 关闭文件 f.close() # 发送邮箱服务器 smtpserver = 'smtp.exmail.qq.com' # 发送邮箱用户名/密码 user = '******' password = '******' # 发送邮箱 sender = '*****@*****.**' # 多个接收邮箱,单个收件人的话,直接是receiver='*****@*****.**' receiver = ['*****@*****.**','*****@*****.**'] # 发送邮件主题以及Html附件
import unittest from PO.po_page import B8_feedback_page from public import GetPhoneInfo, Common, Log, CreatePng, ScreenAssert log = Log.Logger(logger='FeedBack').getLog() class FeedBack(unittest.TestCase): '''《意见反馈》''' @classmethod def setUpClass(cls): log.critical("--------------------意见反馈测试开始--------------------") def setUp(self): self.driver = GetPhoneInfo.Appium().driver() self.Page = B8_feedback_page.config(self.driver) self.base = Common.Action(self.driver) self.png = CreatePng.CreatePNG(self.driver) @ScreenAssert.decorator def test_feedback_001(self): '''意见反馈页面跳转''' self.Page.go_feedback() self.assertIsNotNone( self.base.get_assert('id', self.Page.submit_loc[1])) @ScreenAssert.decorator def test_feedback_002(self): '''意见反馈下半个页面截图对比默认值''' self.Page.go_feedback() self.png.CreateCustomSizeNowPNG('test_feedback_002', 36, 855, 1080,
from PIL import Image from public import Log import os ''' 待添加逻辑 判断是xpath 、 id''' ''' 创建预期结果图片,首先截取元素所在的整体页面(存放 .\data\page ),在截图元素图片(存放 .\data\loc )''' ''' 用例对比,open .\data\loc 对应的元素 与 用例所截取的图片做对比 ''' PngDataPath = os.path.dirname(os.path.abspath('.')) + '\\data' log = Log.Logger(logger='CreatePNG').getLog() class CreatePNG(object): def __init__(self, driver): self.driver = driver def CreateNowPNG(self, v, png, loc): self.driver.get_screenshot_as_file(PngDataPath + '\\page\\%s_page.png' % png) log.info("截取当前页面图片保存至 .\data\page 目录下") if v == 'id': location = self.driver.find_element_by_id(loc).location size = self.driver.find_element_by_id(loc).size left = location['x'] top = location['y'] right = location['x'] + size['width'] bottom = location['y'] + size['height'] now = Image.open(PngDataPath + '\\page\\%s_page.png' % png) im = now.crop((left, top, right, bottom)) im.save(PngDataPath + '\\loc_now\\%s_page.png' % png)
import unittest from public import Log, Common, GetPhoneInfo, CreatePng, ScreenAssert from PO.po_page import Z1_Login_page from time import sleep log = Log.Logger(logger='LoginTest').getLog() class LoginTest(unittest.TestCase): '''《登录功能》''' @classmethod def setUpClass(cls): log.critical("--------------------登录功能测试开始--------------------") def setUp(self): self.driver = GetPhoneInfo.Appium().driverClear() self.Page = Z1_Login_page.LoginPage(self.driver) self.base = Common.Action(self.driver) self.createpng = CreatePng.CreatePNG(self.driver) @ScreenAssert.decorator def test_login_001(self): '''截图对比登录页面LOGO以及字样''' self.Page.click_video() self.Page.click_start() self.base.is_display(self.Page.username_loc[1]) self.createpng.CreateCustomSizeNowPNG('test_login_001', 0, 72, 1080, 700) old = self.base.gerLocOld('test_login_001') now = self.base.getLocNow('test_login_001') self.assertEqual(old, now)
import unittest from time import sleep from PO.po_page import A3_time_man_page from public import Common, GetPhoneInfo, CreatePng, Log, ScreenAssert log = Log.Logger(logger='TimeTest').getLog() class TimeTest(unittest.TestCase): '''《时间管理》''' @classmethod def setUpClass(cls): log.critical("--------------------时间管理测试开始--------------------") def setUp(self): self.driver = GetPhoneInfo.Appium().driver() self.page = A3_time_man_page.time_page(self.driver) self.png = CreatePng.CreatePNG(self.driver) self.base = Common.Action(self.driver) @ScreenAssert.decorator def test_time_A001(self): '''首次进入时间管理验证引导页显示''' self.page.click_time_btn() self.base.is_display(self.page.Guide_confirm_page_btn[1]) self.png.CreateCustomSizeNowPNG('test_time_001', 0, 490, 1080, 1350) self.assertEqual(self.base.gerLocOld('test_time_001'), self.base.getLocNow('test_time_001')) @ScreenAssert.decorator def test_time_A002(self):