예제 #1
0
 def get_local_config(self, local_config):
     """
     读取配置文件
     :param local_config: 配置文件的key
     :return: 返回值的list
     """
     read_ini = ReadIni()
     ini = read_ini.get_value_tuple(local_config)
     return ini
예제 #2
0
 def get_element(self, file_path, section, key):
     read_ini = ReadIni(file_path)
     local = read_ini.get_value(section, key)
     by = local.split('>')[0]
     local_by = local.split('>')[1]
     if by == 'id':
         return self.driver.find_element_by_id(local_by)
     elif by == 'className':
         return self.driver.find_element_by_class_name(local_by)
     else:
         return self.driver.find_element_by_xpath(local_by)
예제 #3
0
	def __init__(self,driver):
		self.login_handle = LoginHandle(driver)
		self.driver = driver
		self.ini = ReadIni()
		self.txt = WriteTxt()
		self.login_page = LoginPage(driver)
		self.username = self.ini.get_value('username','login_value')
		self.password = self.ini.get_value('password','login_value')
		self.error_username = self.ini.get_value('error_username', 'login_value')
		self.error_pwd = self.ini.get_value('error_pwd', 'login_value')
		self.mt4 = self.ini.get_value('mt4id','login_value')
		self.error_mt4 = self.ini.get_value('error_mt4id','login_value')
		self.driver.implicitly_wait(15)
예제 #4
0
 def android_driver(self, i):
     ini = ReadIni(
         node="server_port",
         file_name=
         r"D:\测试\自动化测试\App自动化测试\appium--慕课网登录模块\config\userconfig.ini")
     deviceName = ini.get_value("devices" + str(i))
     port = ini.get_value("appium_port" + str(i))
     capabilities = {
         "platformName": "Android",
         # "automationName": "UiAutomator2",
         "deviceName": deviceName,
         "app": "D:\\测试\\APPnium\\mukewang.apk",
         "noReset": "true"
     }
     driver = webdriver.Remote("127.0.0.1:" + port + "/wd/hub",
                               capabilities)
     time.sleep(5)
     return driver
예제 #5
0
 def get_element(self, key):
     read_ini = ReadIni()
     data = read_ini.get_value(key)
     by = data.split('>')[0]
     value = data.split('>')[1]
     try:
         if by == 'id':
             return self.driver.find_element_by_id(value)
         elif by == 'name':
             return self.driver.find_element_by_name(value)
         elif by == 'className':
             return self.driver.find_element_by_class_name(value)
         else:
             return self.driver.find_element_by_xpath(value)
     except:
         self.driver.save_screenshot(
             'F:\Pycharm\muke\POpractice\image\%s.png' % value)
         return None
예제 #6
0
 def __init__(self, driver):
     self.register_handle = RegisterHandle(driver)
     self.driver = driver
     self.ini = ReadIni()
     self.txt = WriteTxt()
     self.register_page = RegisterPage(driver)
     self.login_handle = LoginHandle(driver)
     self.phone = self.ini.get_value('phone', 'register_input_value')
     self.verification_code = self.ini.get_value('Verification_Code',
                                                 'register_input_value')
     self.mail = self.ini.get_value('mail', 'register_input_value')
     self.call = self.ini.get_value('call', 'register_input_value')
     self.pwd = self.ini.get_value('pwd', 'register_input_value')
     self.confirm_pwd = self.ini.get_value('confirm_pwd',
                                           'register_input_value')
     self.introducer = self.ini.get_value('introducer',
                                          'register_input_value')
     self.driver.implicitly_wait(20)
예제 #7
0
 def __init__(self, driver):
     self.register_handle = RegisterHandle(driver)
     self.driver = driver
     self.ini = ReadIni()
     self.txt = WriteTxt()
     self.register = RegisterBusiness(self.driver)
     self.register_page = RegisterPage(driver)
     self.fill_data_handle = FillDataHandle(driver)
     self.driver.implicitly_wait(20)
예제 #8
0
class RegisterBusiness:
    def __init__(self, driver):
        self.register_handle = RegisterHandle(driver)
        self.driver = driver
        self.ini = ReadIni()
        self.txt = WriteTxt()
        self.register_page = RegisterPage(driver)
        self.login_handle = LoginHandle(driver)
        self.phone = self.ini.get_value('phone', 'register_input_value')
        self.verification_code = self.ini.get_value('Verification_Code',
                                                    'register_input_value')
        self.mail = self.ini.get_value('mail', 'register_input_value')
        self.call = self.ini.get_value('call', 'register_input_value')
        self.pwd = self.ini.get_value('pwd', 'register_input_value')
        self.confirm_pwd = self.ini.get_value('confirm_pwd',
                                              'register_input_value')
        self.introducer = self.ini.get_value('introducer',
                                             'register_input_value')
        self.driver.implicitly_wait(20)

    def register_demo_pass(self):
        '''
        成功注册demo用户
        '''
        self.login_handle.click_register()
        self.register_handle.click_register_au_btn()
        self.register_handle.switch_context()
        self.register_handle.send_phone(self.phone)
        self.register_handle.send_verification_code(self.verification_code)
        self.register_handle.click_next_step()
        self.register_handle.send_mail(self.mail)
        self.register_handle.send_call(self.call)
        self.register_handle.send_password(self.pwd)
        self.register_handle.send_confirm_password(self.confirm_pwd)
        self.register_handle.send_introducer(self.introducer)
        self.register_handle.click_accept_term()
        self.register_handle.click_accept_ad()
        self.register_handle.click_complete()
        time.sleep(20)
예제 #9
0
 def get_local_config(self, local_config, node=None, file_name=None):
     read_ini = ReadIni(node=node, file_name=file_name)
     info = read_ini.get_value_tuple(local_config)
     return info
예제 #10
0
class SendMail:
    def __init__(self, pass_list, fail_list,error_list):
        self.pass_list = pass_list
        self.fail_list = fail_list
        self.error_list = error_list
        self.reportname = self.new_report()
        self.read_ini = ReadIni()

    def _format_addr(self, s):
        name, addr = parseaddr(s)
        return formataddr((Header(name, 'utf-8').encode(), addr))

    def new_report(self):
        if len(os.listdir('../reports')) == 0:
            return None
        else:
            dirs = os.listdir('../reports')
            dirs.sort()
            reportname = dirs[-1]
            print('The new report name: {0}'.format(reportname))
            return reportname

    def mail_result(self, ):
        pass_num = float(len(self.pass_list))
        fail_num = float(len(self.fail_list))
        error_num = float(len(self.error_list))
        count_num = pass_num + fail_num + error_num
        pass_result = "%.2f%%" % (pass_num / count_num * 100)
        fail_result = "%.2f%%" % ((fail_num +error_num ) / count_num * 100)

        content = "此次一共运行用例个数为{0}个,通过个数为{1}个,失败个数为{2},出现错误个数为{3},通过率为{4},失败率为{5}".format(
            count_num, pass_num, fail_num, error_num,pass_result, fail_result)
        return content

    def send_mail(self):
        content = self.mail_result()
        send = self.read_ini.get_value('send',section='email')
        receive = self.read_ini.get_value('receive',section='email')
        receive = receive.split(',')
        pwd = self.read_ini.get_value('pwd',section='email')
        server_163 = self.read_ini.get_value('server_163',section='email')
        if self.reportname == None:
            print(u'报告为空')
        else:
            new_file = os.path.join('../reports', self.reportname)
            with open(new_file, "rb") as fr:
                mail = fr.read()
            # 构造容器
            msg = MIMEMultipart.MIMEMultipart()
            msg['From'] = self._format_addr(u'王明的测试邮箱<%s>' % send)
            msg['To'] = ';'.join(receive)
            msg['Subject'] = Header(u'AetosTrade自动化测试报告', 'utf-8').encode()
            # 构造att1附件
            att1 = MIMEText(mail, _subtype='plain', _charset='utf-8')
            att1["Content-Type"] = 'application/octet-stream'
            att1["Content-Disposition"] = 'attachment;filename = "{0}"'.format(self.reportname)
            msg.attach(att1)
            # 构造att2附件
            # if os.path.isfile("./screenshots.zip"):
            #     with open("./screenshots.zip", "rb").read() as file:
            #         att2 = MIMEText(file, 'base64', 'gb2312')
            #         att2["Content-Type"] = 'application/octet-stream'
            #         att2["Content-Disposition"] = 'attachment;filename = "screenshots.zip"'
            #         msg.attach(att2)



            # 构造发送内容
            con = MIMEText(content, _subtype='plain', _charset='utf-8')
            msg.attach(con)
            # 构造邮件服务器
            server = smtplib.SMTP(server_163)
            server.login(send, pwd)
            server.sendmail(send, receive, msg.as_string())
            server.quit()
            print("Send mail ok")
예제 #11
0
 def __init__(self, pass_list, fail_list,error_list):
     self.pass_list = pass_list
     self.fail_list = fail_list
     self.error_list = error_list
     self.reportname = self.new_report()
     self.read_ini = ReadIni()
예제 #12
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2019/9/9 22:37
# @Author  : Mandy
import conftest
from utils.read_ini import ReadIni

read = ReadIni(conftest.env_dir)


class CommonUrl:
    def __init__(self):
        self.user_register_url = self.join_url('/user/register')
        self.user_register_url = self.join_url('/user/register')
        self.user_info_url = self.join_url('/user/info')
        self.user_edit_info_url = self.join_url('/user/editInfo')
        self.user_edit_gender_url = self.join_url('/user/editFavGender')
        self.user_basic_info_url = self.join_url('/user/basic')

    def join_url(self, test_url):
        base_url = read.get_value('base_url', 'api')
        url = base_url + test_url
        return url


common = CommonUrl()
print(common.user_register_url)
예제 #13
0
#coding:utf-8
from selenium import webdriver
from utils.read_ini import ReadIni
from base.find_element import FindElement

read_ini = ReadIni("User")
user = read_ini.get_value("user")
pwd = read_ini.get_value("pwd")

class LoginFunction(object):
    def __init__(self,url):
        self.driver = self.get_driver(url)

    def get_driver(self,url):
        driver = webdriver.Chrome()
        driver.get(url)
        driver.maximize_window()
        return driver

    #输入用户信息
    def send_user_info(self,element,data):
        element.send_keys(data)

    #定位用户信息
    def get_user_element(self,key):
        find_element = FindElement(self.driver)
        user_element = find_element.get_element(key)
        return user_element

    def main(self):
        eles = self.get_user_element('user_name')
예제 #14
0
class LoginBusiness:
	def __init__(self,driver):
		self.login_handle = LoginHandle(driver)
		self.driver = driver
		self.ini = ReadIni()
		self.txt = WriteTxt()
		self.login_page = LoginPage(driver)
		self.username = self.ini.get_value('username','login_value')
		self.password = self.ini.get_value('password','login_value')
		self.error_username = self.ini.get_value('error_username', 'login_value')
		self.error_pwd = self.ini.get_value('error_pwd', 'login_value')
		self.mt4 = self.ini.get_value('mt4id','login_value')
		self.error_mt4 = self.ini.get_value('error_mt4id','login_value')
		self.driver.implicitly_wait(15)

	def username_login_pass(self):
		'''
		用户名和密码都输入正确
		'''
		self.login_handle.send_username(self.username)
		self.login_handle.send_password(self.password)
		self.login_handle.click_login()

	def username_login_username_error(self):
		'''
		用户名输入错误,密码输入正确
		'''
		self.login_handle.send_username(self.error_username)
		self.login_handle.send_password(self.password)
		self.login_handle.click_login()


	def username_login_password_error(self):
		'''
		用户名输入正确,密码输入错误
		'''
		self.login_handle.send_username(self.username)
		self.login_handle.send_password(self.error_pwd)
		self.login_handle.click_login()

	def mt4_login_pass(self,server):
		'''
		交易账号输入正确,密码输入正确
		'''
		self.login_handle.click_mt4_btn()
		self.login_handle.send_trade_account(self.mt4)
		self.login_handle.send_mt4_pwd(self.password)
		self.login_handle.click_server()
		self.login_handle.click_select_mt4_server(server)
		self.login_handle.click_login()

	def mt4_login_mt4_error(self,server):
		'''
		交易账号输入错误,密码输入正确
		'''
		self.login_handle.click_mt4_btn()
		self.login_handle.send_trade_account(self.error_mt4)
		self.login_handle.send_mt4_pwd(self.password)
		self.login_handle.click_server()
		self.login_handle.click_select_mt4_server(server)
		self.login_handle.click_login()

	def mt4_login_pwd_error(self,server):
		'''
		交易账号输入正确,密码输入错误
		'''
		self.login_handle.click_mt4_btn()
		self.login_handle.send_trade_account(self.mt4)
		self.login_handle.send_mt4_pwd(self.error_pwd)
		self.login_handle.click_server()
		self.login_handle.click_select_mt4_server(server)
		self.login_handle.click_login()
예제 #15
0
 def __init__(self):
     self.excel = OperationExcel()
     self.data_config = global_var()
     self.read = ReadIni(conftest.env_dir)
     self.op_json = OperationJson()
예제 #16
0
class GetSheetData:
    def __init__(self):
        self.excel = OperationExcel()
        self.data_config = global_var()
        self.read = ReadIni(conftest.env_dir)
        self.op_json = OperationJson()

    """获取case行数"""
    def get_case_lines(self):
        lines = self.excel.get_rows()
        return lines

    """是否运行"""
    def is_run(self, row):
        col = self.data_config.get_col_run()
        run_model = self.excel.get_cell_value(row, col)
        flag = None
        if run_model == 'yes':
            flag = True
        else:
            flag = False
        return flag

    """获取case id"""
    def get_id(self, row):
        col = self.data_config.get_col_id()
        case_id = self.excel.get_cell_value(row, col)
        return case_id

    """获取api,拼接接口地址"""
    def get_url(self, row):
        col = self.data_config.get_col_api()
        api = self.excel.get_cell_value(row, col)
        url = self.read.get_value('base_url', 'api') + api
        return url

    """获取请求方法"""
    def get_method(self, row):
        col = self.data_config.get_col_method()
        method = self.excel.get_cell_value(row, col)
        return method

    """获取是否有header,是则从json数据中获取headers"""
    def get_header(self, row):
        col = self.data_config.get_col_header()
        header = self.excel.get_cell_value(row, col)
        header_data = self.op_json.get_data('headers')
        if header == 'yes':
            return header_data
        else:
            return None

    """获取依赖的case id"""
    def get_depend_id(self, row):
        col = self.data_config.get_col_depend_id()
        depend_id = self.excel.get_cell_value(row, col)
        if depend_id == '':
            return None
        else:
            return depend_id

    """获取依赖的数据"""
    def get_depend_data(self, row):
        col = self.data_config.get_col_depend_data()
        depend_data = self.excel.get_cell_value(row, col)
        if depend_data == '':
            return None
        else:
            return depend_data

    """获取依赖数据的字段"""
    def get_depend_key(self, row):
        col = self.data_config.get_col_depend_key()
        depend_key = self.excel.get_cell_value(row, col)
        if depend_key == '':
            return None
        else:
            return depend_key

    """根据命名的请求json名,获取请求数据"""
    def get_request_data(self, row):
        col = self.data_config.get_col_request_data()
        request_data_key = self.excel.get_cell_value(row, col)
        request_data = self.op_json.get_data(request_data_key)
        if request_data == '':
            return None
        else:
            return request_data

    """根据sql语句,获取期望值"""
    def get_expect(self, row):
        col = self.data_config.get_col_expect()
        expect = self.excel.get_cell_value(row, col)
        return expect

    """把结果写入实际结果中"""
    def write_result(self, row, result,):
        col = self.data_config.get_col_result()
        self.excel.write_data(row, col, result)
예제 #17
0
 def __init__(self):
     self.dos = DosCmd()
     self.ini = ReadIni(
         file_name=
         r"D:\测试\自动化测试\App自动化测试\appium--慕课网登录模块\config\userconfig.ini")
예제 #18
0
class Server(object):
    def __init__(self):
        self.dos = DosCmd()
        self.ini = ReadIni(
            file_name=
            r"D:\测试\自动化测试\App自动化测试\appium--慕课网登录模块\config\userconfig.ini")

    def kill_node_server(self):
        server_list = self.dos.execute_cmd_result('tasklist | find "node.exe"')
        if len(server_list) > 0:
            self.dos.execute_cmd("taskkill -F -PID node.exe")

    def get_devices(self):
        """
        获取设备信息
        :return: 格式化后的设备信息
        """
        devices = self.dos.execute_cmd_result("adb devices")
        if len(devices) >= 2:
            result = [
                i.replace("\tdevice", "") for i in devices if "\tdevice" in i
            ]
        else:
            result = None
        return result

    def connect_device(self, devices_list):
        for i in devices_list:
            self.dos.execute_cmd("adb connect " + i)

    def create_port_list(self, start_port):
        """获取port"""
        p = Port()
        port_list = p.create_port_list(start_port, self.get_devices())
        return port_list

    def create_command_list(self):
        """创建一个启动appium的cmd命令"""
        command_list = []
        appium_port_list = self.create_port_list(4700)
        bootstrap_port_list = self.create_port_list(4900)
        devices_list = self.get_devices()
        self.connect_device(devices_list)
        for i in range(len(devices_list)):
            self.ini.write_ini("server_port", "appium_port" + str(i),
                               str(appium_port_list[i]))
            self.ini.write_ini("server_port", "bootstrap_port" + str(i),
                               str(bootstrap_port_list[i]))
            self.ini.write_ini("server_port", "devices" + str(i),
                               str(devices_list[i]))
            command = "appium -p " + str(appium_port_list[i]) + " -bp " + str(
                bootstrap_port_list[i]) + " -U " + str(
                    devices_list[i]) + " --no-reset --session-override"
            command_list.append(command)
        return command_list

    def start_server(self, i):
        self.dos.execute_cmd(i)

    def start_server_thread(self):
        self.kill_node_server()
        for i in self.create_command_list():
            self.appium_start = threading.Thread(target=self.start_server,
                                                 args=(i, ))
            self.appium_start.start()
        time.sleep(10)