Esempio n. 1
0
def generate_test_data(devices):
    dict_tmp = {}
    for d in devices:
        dict_tmp[d['serial']] = {}
        dict_tmp[d['serial']]['user_name'] = ReadConfig().get_testdata(
            'user_name')[devices.index(d)]
        dict_tmp[d['serial']]['password'] = ReadConfig().get_testdata(
            'password')[devices.index(d)]
    with open(data_path, "w") as f:
        json.dump(dict_tmp, f, ensure_ascii=False)
        f.close()
    print("Test data data.json generated success")
Esempio n. 2
0
    def run(self, command):
        # 根据method 获取android设备
        method = ReadConfig().get_method().strip()
        if method == 'SERVER':
            # get ATX-Server Online devices
            # devices = ATX_Server(ReadConfig().get_server_url()).online_devices()
            print('Checking available online devices from ATX-Server...')
            devices = get_online_devices()
            print('\nThere has %s alive devices in ATX-Server' % len(devices))
        elif method == 'IP':
            # get  devices from config devices list
            print('Checking available IP devices from config... ')
            devices = get_devices()
            print('\nThere has %s  devices alive in config IP list' %
                  len(devices))
        elif method == 'USB':
            # get  devices connected PC with USB
            print('Checking available USB devices connected on PC... ')
            devices = connect_devices()
            print('\nThere has %s  USB devices alive ' % len(devices))

        else:
            raise Exception('Config.ini method illegal:method =%s' % method)

        if not devices:
            print('There is no device found,test over.')
            return

        # # # 测试前准备
        # download_apk()  # 下载小影最新的apk

        print('Starting Run test >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
        runs = []
        for i in range(len(devices)):
            runs.append(RunCases(devices[i]))
        print(runs)
        # run on every device 开始执行测试
        pool = Pool(processes=len(runs))
        for run in runs:
            pool.apply_async(self._run_cases, args=(
                run,
                command,
            ))
            # time.sleep(2)
        print('Waiting for all runs done........ ')
        pool.close()
        pool.join()
        print('All runs done........ ')
Esempio n. 3
0
def get_devices():
    '''get the devices from Pubilc/config.ini devices list
    return alive devices'''
    devices_ip = ReadConfig().get_devices_ip()
    print('Connect devices from config devices IP list %s' % devices_ip)
    pool = Pool(processes=len(devices_ip))
    tmp_list = []
    for run in devices_ip:
        tmp_list.append(pool.apply_async(check_alive, args=(run, )))
    pool.close()
    pool.join()
    devices_list = []
    for i in tmp_list:
        if i.get():
            devices_list.append(i.get())
    return devices_list
Esempio n. 4
0
def get_online_devices():
    '''get the devices from ATX-Server
    return alive devices'''
    devices = ATX_Server(ReadConfig().get_server_url()).online_devices()
    print('There has %s online devices on ATX-Server' % len(devices))
    if devices:
        pool = Pool(processes=len(devices))
        tmp_list = []
        for run in devices:
            tmp_list.append(pool.apply_async(check_alive, args=(run, )))
        pool.close()
        pool.join()
        devices_list = []
        for i in tmp_list:
            if i.get():
                print(i.get())
                devices_list.append(i.get())

        return devices_list
    else:
        raise Exception('ATX-Server has no online device!!! ')
Esempio n. 5
0
    def open_browser(self, driver):
        read = ReadConfig()
        browser = read.getValue("browserType", "browserName")
        options = read.getValue("pattern", "options")
        url = read.getValue("testServer", "URL")
        is_visible = read.getValue("pattern", "is_visible")

        if options.lower() == 'web':
            if browser == "Firefox":
                if is_visible == 'F':
                    options = webdriver.FirefoxOptions()
                    options.add_argument('-headless')
                    # options.add_argument('--disable-gpu')
                    driver = webdriver.Firefox(executable_path=firefox_driver,
                                               options=options)
                else:
                    driver = webdriver.Firefox(executable_path=firefox_driver)
                    log.info("启动{}浏览器".format(browser))

            elif browser == "Chrome":
                if is_visible == 'F':
                    option = webdriver.ChromeOptions()
                    option.add_argument('headless')
                    driver = webdriver.Chrome(chrome_driver,
                                              chrome_options=option)
                else:
                    driver = webdriver.Chrome(chrome_driver)
                    log.info("启动{}浏览器".format(browser))

            # elif browser == "IE":
            #     driver = webdriver.Ie(driver_path)
            #     log.info("启动{}浏览器".format(browser))
        elif options.lower() == 'wap':
            mobileEmulation = {"deviceName": "iPhone 6"}
            options = webdriver.ChromeOptions()
            options.add_experimental_option('mobileEmulation', mobileEmulation)
            options.add_argument('--disable-search-geolocation-disclosure')
            driver = webdriver.Chrome(chrome_options=options)

        driver.get(url)
        log.info("打开链接:{}".format(url))
        driver.maximize_window()
        log.info("最大化窗口")
        driver.implicitly_wait(10)
        log.info("隐式等待10s")
        return driver
#coding=utf-8
import os
import sys
sys.path.append('/home/selenium_python')
from public.readconfig import ReadConfig

# Read configuration file
config_file_path = os.path.split(os.path.realpath(__file__))[0]
read_config = ReadConfig(os.path.join(config_file_path, 'config.ini'))
# Project parameter setting
prj_path = read_config.getValue('projectConfig', 'project_path')
# Log path
log_path = os.path.join(prj_path, 'report', 'log')
# Screenshot file path
img_path = os.path.join(prj_path, 'report', 'image')
#Exception screenshot file path
eximg_path = os.path.join(prj_path, 'report', 'exception_img')
#Test report path
report_path = os.path.join(prj_path, 'report', 'test_report')
#Upload the autoit file path
auto_path = os.path.join(prj_path, 'up_files', 'autoit_pic')
# Default browser
browser = 'phantomjs'
# Test data path
data_path = os.path.join(prj_path, 'data', 'testdata')
Esempio n. 7
0
"""
 @desc:邮件发送
 @author: yansh
"""
import os
import sys
import smtplib
import time
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
# from public.log import Log
from public.readconfig import ReadConfig

# log = Log()
read = ReadConfig()
# root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
root_path = os.path.dirname(os.path.abspath(sys.argv[0]))

# 测试报告的路径
reportPath = os.path.join(root_path, 'report', 'testreport')
mail_server = read.getValue('Mail', 'mail_server')
mail_subject = read.getValue('Mail', 'mail_subject')
# 配置收发件人
recvaddress = read.getValue('Mail',
                            'mail_to')  # ['*****@*****.**', '*****@*****.**']
sendaddr_name = read.getValue('Mail', 'mail_from')
sendaddr_pwd = read.getValue('Mail', 'mail_from_pwd')


class SendMail:
    def __init__(self, recver=None):
Esempio n. 8
0
#!/usr/bin/python3
# coding=utf-8
from public.readconfig import ReadConfig
import os

project_path = os.path.split(os.path.split(os.path.realpath(__file__))[0])[0]
'''Gets the project absolute path (获取项目绝对路径)'''
# print(project_path)

config_file_path =os.path.split(os.path.realpath(__file__))[0]
'''Get the config folder path (获取config文件夹路径)'''
# print(config_file_path)

read_config = ReadConfig(os.path.join(os.path.split(os.path.realpath(__file__))[0], 'config.ini'))
'''Read configuration file (读取config配置文件)'''
# print(read_config)

log_path = os.path.join(project_path, "report", "logs")
'''write log path (写入的log路径)'''
# print(log_path)

image_path = os.path.join(project_path, "report", "image")
'''The common screenshot path (普通截图路径)'''
# print(image_path)

exception_image_path = os.path.join(project_path, "report", "expection_image")
'''The exception screenshot file path (异常截图路径)'''
# print(exception_image_path)

report_path = os.path.join(project_path, "report", "test_report")
'''Test report path (测试报告路径)'''