def __init__(self): self.caselist = readConfig().get_caselist() self.reportFile = os.path.join(path, 'report', 'report', 'report.html') # 测试报告路径 self.reportFile1 = os.path.join(path, 'report', 'report') # 测试报告目录 self.suite_all = caseSuite().set_case_suite() # 获取测试套件 self.report_result = []
def open_pc_appium2(): """打开夜神模拟器""" file_path = readConfig().get_exe()['appium'] app = application.Application(backend='uia') try: app.connect(title_re='Appium', class_name='Chrome_WidgetWin_1') sleep(8) except ElementNotFoundError: app.start(file_path) sleep(8) log.info('Sucess open appium!')
def open_pc_yesheng(): """打开夜神模拟器""" file_path = readConfig().get_exe()['yesheng'] app = application.Application(backend='uia') try: app.connect(title_re='夜神模拟器', class_name='Qt5QWindowIcon') sleep(5) except ElementNotFoundError: app.start(file_path) sleep(40) log.info('Sucess open 夜神模拟器!')
def open_pc_appium(): """打开appium""" file_path = readConfig().get_exe()['appium'] # 读取appium.exe文件路径 app = application.Application(backend='uia') # 定义application实例 # app.start(file_path) # sleep(2) # print(pywinauto.findwindows.find_elements(title='Appium')) app.connect(title_re='Appium', class_name='Chrome_WidgetWin_1') appium = app.window(title='Appium') # 指定窗口 appium.wait("exists ready", timeout=3, retry_interval=3) # 等待窗口就绪 # sleep(5) appium.print_control_identifiers() appium.Button4.click() # 点击指定按钮(Button4) log.info('Sucess start appium!')
# _*_ config: utf-8 _*_ # python3的MyUiautomator import time, subprocess, os import uiautomator2 as u2 from config.getMobile import get_mobile from config.readConfig import readConfig from common.log import Logger # 获取设备信息 mobile_data = get_mobile('uiauto2_android')[1] unlock_data = readConfig().get_unlock() log = Logger().get_logger() class MyUiautomator2(object): def connect_android(self, ip=mobile_data['ip']): """ 连接设备 :param ip: 设备ip,数据线连接传入None """ self.isconnect(ip) self.app = u2.connect(ip) # 连接设备 self.app.unlock() # self.app.healthcheck() # 解锁屏幕(但无法解开锁屏密码)并开启uiautomator2服务 def connect_app(self, start='session', appPackage=mobile_data['appPackage'], secs=4): """
def __init__(self): self.caseList = readConfig().get_caselist() # 测试用例文件 self.caseFile = os.path.join(path, 'Po') # 测试用例目录
import os import logging import time from config import getProjectPath from config.readConfig import readConfig from logging.handlers import TimedRotatingFileHandler path = getProjectPath.get_project_path() log = readConfig().get_log() class Logger(): """ Logger类 """ def __init__(self, logger_name='log...'): self.logger = logging.getLogger(logger_name) logging.root.setLevel(logging.NOTSET) # 设置日志总级别,不设置默认WARNING self.log_path = os.path.join(path, 'report', 'log', 'logs') # 日志文件路径 self.log_file_name = 'logs.txt' self.backup_Count = 5 # log文件数量 # 设置日志级别,日志级别:CRITICAL > ERROR > WARNING > INFO > DEBUG self.file_output_lever = log['file_output_lever'] self.console_output_lever = log['console_output_lever'] # 设置日志格式 self.Formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') def get_logger(self):
import unittest, time from common.MySelenium import mySelenium from Po.testpage.kugou_page import kugou_page from config.readConfig import readConfig kugou_path = readConfig().get_exe()['kugou'] backend = 'uia' title = '酷狗音乐' class_name = 'kugou_ui' class kugou_test(unittest.TestCase): @classmethod def setUpClass(cls): cls.dr = mySelenium() cls.dr.open_pc_exe(file_path=kugou_path, title=title, class_name=class_name, backend=backend) cls.kg = kugou_page(cls.dr) pass @classmethod def tearDownClass(cls): pass def test1_play_muisc(self): """酷狗播放音乐""" self.kg.kugou_play_music()
import unittest import time from common.MySelenium import mySelenium from common.log import Logger from config.getMobile import get_mobile from config.readConfig import readConfig log = Logger('common.Mymobile').get_logger() phone_data = get_mobile()[1] phone_data2 = readConfig().get_App() class Mymobile(unittest.TestCase): @classmethod def setUpClass(cls): log.info("**************************************** start **************************************************") cls.dr = mySelenium() cls.dr.mobile(phone_data) # enterApp_page(cls.dr).tgp_login_main() # 登录app @classmethod def tearDownClass(cls): time.sleep(5) log.info("**************************************** end **************************************************\n") cls.dr.quit()
from twilio.rest import Client from config.readConfig import readConfig from common.log import Logger twilio_data = readConfig().get_sms() log = Logger('common.SMS.py').get_logger() client = Client(twilio_data['account_sid'], twilio_data['account_token']) # 配置twilio def send_msg(body, to=twilio_data['to'], from_=twilio_data['from']): """通过twilio发送短信""" try: message = client.messages.create(to=to, from_=from_, body=body) # 新建短信 log.info('Success send messages, messages sid:{0}, body:{1}'.format( message.sid, message.body)) except Exception as e: log.error('Fail send messages!') log.error(e) print('发送短信失败,错误原因:{}'.format(e)) def call_num(): """通过twilio打电话""" try: call = client.calls.create( to=twilio_data['to'], from_=twilio_data['from'], url='http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient' ) # 新建短信
import time import os import yagmail from config.getProjectPath import get_project_path from config.readConfig import readConfig from common.log import Logger path = get_project_path() email_data = readConfig().get_email() load_time = time.strftime('%Y-%m-%d', time.localtime()) log_path = os.path.join(path, 'report', 'log', 'logs' + str(load_time) + '.log') report_path = os.path.join(path, 'report', 'report', 'report.html') log = Logger('sendEmail').get_logger() def send_annex_email(): """ 发送附件邮件 :return: """ t1 = time.time() try: if email_data['on_off'] == 'on': email = yagmail.SMTP(user=email_data['user'], password=email_data['password'], host=email_data['host']) content = '自动化报告' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) file_name = [report_path, log_path]
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from appium.webdriver.common.mobileby import MobileBy as By from selenium.webdriver.common.action_chains import ActionChains from config.getProjectPath import get_project_path from config.readConfig import readConfig from common.BeautifulReport import BeautifulReport from common.MyChromedriver import ChromeDriver # from pywinauto.application import Application path = get_project_path() phone_data = get_mobile()[2] # appium选择设备和app uiauto_phone_data = get_mobile('uiauto2_android')[1] # uiautomator2选择设备和app # phone_data = readConfig().get_App() browser_data = readConfig().get_browser() log = Logger('common.mySelenium').get_logger() screenshot_path = os.path.join(path, 'report', 'screen_shot') success = 'Success' fail = 'Fail' install_unicode = 'id->com.android.packageinstaller:id/btn_install_confirm' img_path = os.path.join(path, 'report', 'screen_shot') class mySelenium(object): def __init__(self): pass # def open_pc_exe(self, file_path, title=None, class_name=None,backend='win32'): # """ # 打开pc中exe应用