示例#1
0
	def __init__(self):
		self.driver = webdriver.Chrome()
		self.driver.get('http://www.18crm.com')
		self.login_b = LoginBussiness(self.driver,'../config/LocalElement.ini')
		self.login_h = LoginHandle(self.driver,'../config/LocalElement.ini')
		self.rd = ReadIni('../config/TestData.ini')
		self.base = CommonUtil()
示例#2
0
class LoginCase:
	def __init__(self):
		self.driver = webdriver.Chrome()
		self.driver.get('http://www.18crm.com')
		self.login_b = LoginBussiness(self.driver,'../config/LocalElement.ini')
		self.login_h = LoginHandle(self.driver,'../config/LocalElement.ini')
		self.rd = ReadIni('../config/TestData.ini')
		self.base = CommonUtil()
	
	def login_test01(self):
		'''
		不输入用户名、密码登录
		提示:用户账号格式为: 用户名@公司简称
		'''
		result = self.login_b.loginTest(self.rd.get_value('login','test01_username'),self.rd.get_value('login','test01_password'))
		return self.base.verifyTextMatch(self.driver,result,self.rd.get_value('login','test01_expect'))

	def login_test02(self):
		'''
		手机格式错误登录:130
		提示:输入的手机号格式不正确!
		'''
		result = self.login_b.loginTest(self.rd.get_value('login','test02_username'),self.rd.get_value('login','test02_password'))
		return self.base.verifyTextMatch(self.driver,result,self.rd.get_value('login','test02_expect'))

	def login_test03(self):
		'''
		用户名、密码错误:manager@test , 123456
		提示:用户名或密码错误
		'''
		result = self.login_b.loginTest(self.rd.get_value('login','test03_username'),self.rd.get_value('login','test03_password'))
		return self.base.verifyTextMatch(self.driver,result,self.rd.get_value('login','test03_expect'))

	def login_test04(self):
		'''
		企业号未开通登录:manager@999 , 123
		提示:企业号:999 不正确,或者您还没有开通软件,请点击“我要购买”进行开通
		'''
		result = self.login_b.loginTest(self.rd.get_value('login','test04_username'),self.rd.get_value('login','test04_password'))
		return self.base.verifyTextMatch(self.driver,result,self.rd.get_value('login','test04_expect'))

	def login_test05(self):
		'''
		登陆成功:manager@test , 123
		进入首页,姓名 == manager
		'''
		self.login_b.loginTest(self.rd.get_value('login','test05_username'),self.rd.get_value('login','test05_password'))
		try:
			result = self.login_h.homePageMyName().text
		except:
			result = ''
		return self.base.verifyTextMatch(self.driver,result,self.rd.get_value('login','test05_expect'))
示例#3
0
class CustomHandle:
    def __init__(self, driver):
        self.fd = FindElement(driver, '../config/LocalElement.ini')
        self.util = WebdriverUtil()
        self.base = CommonUtil()
        self.driver = driver

    def toCustom(self):
        #点击"我的客户"
        ActionChains(self.driver).move_to_element(
            self.fd.get_element('custom', 'custom')).perform()
        self.fd.get_element('custom', 'myCustom').click()
        #切换到主Frame
        self.util.switchFrame(self.driver, 'frame', 'mainframe')
        return self.driver

    def clickAdd(self):
        self.driver = self.toCustom()
        #点击新增按钮
        oldHandle = self.driver.current_window_handle
        self.fd.get_element('custom', 'add').click()
        #切换到新弹出的"新增客户"页面
        allHandle = self.driver.window_handles
        self.util.switchWindow(self.driver, oldHandle, allHandle)
        return self.driver

    def addCustom(self, username, notnull):
        self.driver = self.clickAdd()
        #输入姓名、必填项,点击确定 ,username,notnull
        self.fd.get_element('custom', 'customName').send_keys(username)
        self.fd.get_element('custom', 'notNullText').send_keys(notnull)
        self.fd.get_element('custom', 'save').click()

    def getFirstCustom(self):
        return self.fd.get_element('custom', 'fistCustom').text

    def getSecondCustom(self):
        return self.fd.get_element('custom', 'secondCustom').text

    def getCountCustom(self):
        element = self.fd.get_element('custom', 'totalCustom')
        return element.get_attribute('value')

    def deleteCustom(self):
        print(self.getCountCustom())
        self.fd.get_element('custom', 'checkCustom').click()
        self.fd.get_element('custom', 'deleteCustom').click()
        self.base.acceptAlert(self.driver)
        sleep(5)
        self.base.acceptAlert(self.driver)
        sleep(5)
        print(self.getCountCustom())
示例#4
0
class LoginBussiness:
    def __init__(self, driver, filename):
        self.login_h = LoginHandle(driver, filename)
        self.util = CommonUtil()
        self.driver = driver

    def loginTest(self, username, password):
        self.login_h.sendUsername(username)
        self.login_h.sendPassword(password)
        self.login_h.clickLoginBt()
        alertText = self.util.getAlertText(self.driver)
        self.util.acceptAlert(self.driver)
        return alertText
示例#5
0
class CustomHandle:
    def __init__(self):
        self.base = CommonUtil()
        #self.fd = FindElement(driver,'../config/LocalElement.ini')
        self.util = WebdriverUtil()

    def toCustom(self):
        driver = self.base.login()
        fd = FindElement(driver, '../config/LocalElement.ini')
        ActionChains(driver).move_to_element(fd.get_element(
            'custom', 'custom')).perform()
        fd.get_element('custom', 'myCustom').click()
        return driver

    def addCustom(self):
        driver = self.toCustom()
        oldHandle = driver.current_window_handle
        fd = FindElement(driver, '../config/LocalElement.ini')
        ActionChains(driver).move_to_element(fd.get_element(
            'custom', 'custom')).perform()
        fd.get_element('custom', 'myCustom').click()

        self.util.switchFrame(driver, 'frame', 'mainframe')

        fd.get_element('custom', 'add').click()

        allHandle = driver.window_handles
        self.util.switchWindow(driver, oldHandle, allHandle)
        fd.get_element('custom', 'customName').send_keys('hjkl')
        sleep(2)
class CustomCase:
    def __init__(self):
        self.driver = CommonUtil().login()
        self.customer_b = CustomerBussiness(self.driver)
        self.custom_h = CustomHandle(self.driver)
        self.base = CommonUtil()

    def custom_test01(self):
        # 不输入姓名保存
        result = self.customer_b.addCustom(userName='', notNullText='123')
        return self.base.verifyTextMatch(self.driver, result, '客户姓名不能为空')

    def custom_test02(self):
        # 不输入必填项保存
        result = self.customer_b.addCustom(userName='******', notNullText='')
        return self.base.verifyTextMatch(self.driver, result, '必填测试不能为空')

    def custom_test03(self):
        # 新增成功
        userName = self.base.getUniqueName()
        notNullText = self.base.getUniqueName()
        result = self.customer_b.addCustom(userName, notNullText)
        return self.base.verifyTextContain(self.driver, result, '新增成功')
示例#7
0
class RunTest:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = GetData()
        self.com_util = CommonUtil()

    def go_on_run(self):
        pass_count = []
        fail_count = []

        #10行就,返回10,
        rows_count = self.data.get_lines()
        #第0行是头信息,从1行开始
        for i in range(1, rows_count):
            is_run = self.data.get_is_run(i)
            if is_run:
                url = self.data.get_url(i)
                method = self.data.get_request_method(i)
                requestData = self.data.get_data(i)
                headers = self.data.is_header(i)
                expect = self.data.get_expect(i)
                depend_case = self.data.is_depend(i)
                if depend_case != None:
                    dependData = DependentData()
                    #获取依赖响应数据
                    dependResData = dependData.get_data_by_key(i)
                    #获取依赖的field
                    dependField = self.data.get_dependField(i)
                    requestData[dependField] = dependResData
                res = self.run_method.run_main(method, url, requestData,
                                               headers)
                print(type(res))
                if self.com_util.is_contain(expect, res):
                    print("=测试Pass="******"=测试Fail=")
                    self.data.write_result(i, res)
                    fail_count.append(i)

        sendMail = SendEmail()
        sendMail.send_main(pass_count, fail_count)
示例#8
0
 def __init__(self):
     self.base = CommonUtil()
     #self.fd = FindElement(driver,'../config/LocalElement.ini')
     self.util = WebdriverUtil()
示例#9
0
from database.db_init import DB
from common.common_util import CommonUtil as util

db_username = util.get_value_from_ssm_parameter_store('/_username')
db_password = util.get_value_from_ssm_parameter_store('/rds/_password')
db_host = DB.get_rds_host()


def create_session():
    """this will create a db session"""
    db = DB(user=db_username,
            password=db_password,
            host=db_host,
            database='test')
    Session = db.getSession()
    session = Session()
    return session
示例#10
0
 def __init__(self):
     self.run_method = RunMethod()
     self.data = GetData()
     self.com_util = CommonUtil()
示例#11
0
 def __init__(self):
     self.run_method = RunMethod()
     self.data = RequestData()
     self.util = CommonUtil()
     self.send_email = SendMail()
示例#12
0
class RunMain:
    def __init__(self):
        self.run_method = RunMethod()
        self.data = RequestData()
        self.util = CommonUtil()
        self.send_email = SendMail()

    #程序执行主入口
    def get_go_run(self):
        #日志打印配置
        logs_path = config.get_run_logs_path()
        if os.path.exists(r"{path}".format(path=logs_path)):
            os.remove(r"{path}".format(path=logs_path))
        logging_setting(logs_path)
        #用例主体方法
        res = None
        pass_count = []
        fail_count = []
        rows_count = self.data.get_case_lines()
        for i in range(1, rows_count):
            url = self.data.get_request_url(i)
            request_mode = self.data.get_request_method(i)
            is_run = self.data.get_is_run(i)
            is_number = self.data.get_number_value(i)
            data = self.data.get_data_json(i)
            expect = self.data.get_expect_data(i)
            hander = self.data.get_is_hander(i)
            depend_case = self.data.is_depend(i)
            if is_run == True:
                if depend_case != None:
                    self.depend_data = DependtndData()
                    #获取依赖的响应数据
                    depend_response_data = self.depend_data.get_data_for_key(i)
                    #获取依赖的key
                    depend_key = self.data.get_depend_data(i)
                    request_mode[depend_key] = depend_response_data
                if hander == "W":
                    res = self.run_method.run_main(request_mode, url, data)
                    op_hander = OpenHeader(url, data)
                    op_hander.write_cookie()
                elif hander == "Y":
                    op_json = OpenJson(
                        os.path.abspath('..' + '/json/cookies.json'))
                    cookie = op_json.get_cookie()
                    res = self.run_method.run_main(request_mode, url, data,
                                                   cookie)
                else:
                    res = self.run_method.run_main(request_mode, url, data)
                if self.util.is_contain(expect, res):
                    self.data.write_excel(i, "pass")
                    pass_count.append(i)
                    logging.debug("test case (%s) True" % is_number)
                    logging.debug("pass_count:%s True" % len(pass_count))
                else:
                    self.data.write_excel(i, res)
                    fail_count.append(i)
                    logging.error("test case (%s) Flase" % is_number)
                    logging.debug("fail_count:%s True" % len(fail_count))
        logging.debug("发送邮件中")
        self.send_email.send_main(pass_count, fail_count)
        get_Message_push(pass_count, fail_count)
        logging.debug("发送邮件成功")
示例#13
0
 def __init__(self):
     self.driver = CommonUtil().login()
     self.customer_b = CustomerBussiness(self.driver)
     self.custom_h = CustomHandle(self.driver)
     self.base = CommonUtil()
示例#14
0
 def __init__(self, driver, filename):
     self.login_h = LoginHandle(driver, filename)
     self.util = CommonUtil()
     self.driver = driver
示例#15
0
import sys
import os
sys.path.append('..')
from time import sleep
from common.common_util import CommonUtil
from selenium.webdriver import ActionChains
from common.webdriver_util import WebdriverUtil

driver = CommonUtil().login()
ActionChains(driver).move_to_element(driver.find_element_by_link_text('客户')).perform()
sleep(2)
driver.find_element_by_link_text('我的客户').click()

xf = driver.find_element_by_xpath('//*[@id="mainframe_18crm"]')
driver.switch_to.frame(xf)


driver.find_element_by_xpath(r"//*[@id='table_maindata']/tbody/tr[3]/td[1]/input[1]").click()
示例#16
0
        self.fd.get_element('custom', 'save').click()

    def getFirstCustom(self):
        return self.fd.get_element('custom', 'fistCustom').text

    def getSecondCustom(self):
        return self.fd.get_element('custom', 'secondCustom').text

    def getCountCustom(self):
        element = self.fd.get_element('custom', 'totalCustom')
        return element.get_attribute('value')

    def deleteCustom(self):
        print(self.getCountCustom())
        self.fd.get_element('custom', 'checkCustom').click()
        self.fd.get_element('custom', 'deleteCustom').click()
        self.base.acceptAlert(self.driver)
        sleep(5)
        self.base.acceptAlert(self.driver)
        sleep(5)
        print(self.getCountCustom())


if __name__ == '__main__':
    from common.common_util import CommonUtil

    driver = CommonUtil().login()
    a = CustomHandle(driver)
    a.toCustom()
    print(a.deleteCustom())