Exemplo n.º 1
0
class MyTest(unittest.TestCase):
    """短信验证码"""
    def setUp(self):
        pass

    def testSms(self):
        """短信验证码"""
        self.readConfig = ReadConfig()
        self.imgcodeid = self.readConfig.getReslConfig("imgCodeId")
        self.cls = common.getXls("testCase.xlsx", "test1")
        self.log = log.get_log()
        self.logger = self.log.getLogger()
        self.Http = configHttp.ConfigHttp()
        self.HttpUrl = self.Http.setUrl(self.cls.get(1).get("url"))
        self.logger.info(self.HttpUrl)
        TempParams = json.loads(self.cls.get(1).get("params"))
        TempParams["imgCodeId"] = self.imgcodeid
        TempParams["mobile"] = self.readConfig.getReslConfig("mobile")
        self.params = json.dumps(TempParams)
        self.Http.setParams(self.params)
        self.r = self.Http.get()
        self.r.status_code
        self.r.encoding = 'utf-8'
        self.logger.info("result-----------", self.r.json().get("errorCode"))
        self.logger.info(self.r.status_code)
        assert self.r.status_code == 200, "请求失败"
        assert self.r.json().get("errorCode") == "0000000", "响应失败"

    def tearDown(self):
        print("tearDown")
Exemplo n.º 2
0
class CreateMobile:
    def __init__(self):
        self.mobile_num = ""
        self.readConfig = ReadConfig()
        pass

    def getRandomDigit(self):
        return choice(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])

    def create(self):
        #130-133号段是联通的,134-139号段是移动的。移动现在还获得了159号段。
        mobile_3 = choice([
            "130", "131", "132", "133", "134", "135", "136", "137", "138",
            "138", "159"
        ])
        self.mobile_num += mobile_3
        while (len(self.mobile_num) < 11):
            self.mobile_num += self.getRandomDigit()
        self.readConfig.setReslConfig("mobile", self.mobile_num)
        return self.mobile_num
Exemplo n.º 3
0
def BaseDriver():
    """准备对外依赖的driver"""
    #实例化启动浏览器参数
    opt = webdriver.ChromeOptions()
    #读取ini文件中gui的值(是否有界面运行)
    rc = ReadConfig()
    gui = rc.get_driver('gui')
    if gui.lower() == 'yes':
        logger.info('chrome 有界面运行')

        # 关掉密码弹窗
        prefs = {"": ""}
        prefs["credentials_enable_service"] = False
        prefs["profile.password_manager_enabled"] = False
        opt.add_experimental_option("prefs", prefs)

        # 关掉自动化控制提示
        opt.add_experimental_option('useAutomationExtension', False)
        opt.add_experimental_option('excludeSwitches', ['enable-automation'])

        #隐身(无痕)模式
        opt.add_argument('--incognito')

        # 最大化运行(全屏窗口)
        opt.add_argument('--start-maximized')

        #启动浏览器
        driver = webdriver.Chrome(options=opt)
    else:
        logger.info('chrome 无界面运行')
        opt.add_argument('--headless')
        opt.add_experimental_option('useAutomationExtension', False)
        opt.add_experimental_option('excludeSwitches', ['enable-automation'])
        opt.add_argument('--start-maximized')  #最大化运行(全屏窗口)
        driver = webdriver.Chrome(options=opt)
    return driver
Exemplo n.º 4
0
class MyTest(unittest.TestCase):
    """获取图形验证码"""
    def setUp(self):
        self.confige = ReadConfig()

    def testImg(self):
        """获取图形验证码"""
        self.cls = common.getXls("testCase.xlsx", "test1")
        self.log = log.get_log()
        self.logger = self.log.getLogger()
        self.Http = configHttp.ConfigHttp()
        self.HttpUrl = self.Http.setUrl(self.cls.get(0).get("url"))
        self.logger.info(self.HttpUrl)
        self.Http.setParams(self.cls.get(0).get("params"))
        self.r = self.Http.get()
        self.r.status_code
        self.r.encoding = 'utf-8'
        self.logger.info("result-----------", self.r.json().get("errorCode"))
        assert self.r.status_code == 200, "请求失败"
        assert self.r.json().get("errorCode") == "0000000", "响应失败"
        self.imgCodeId = self.r.json().get("data").get("imgCodeId")
        self.confige.setReslConfig("imgCodeId", self.imgCodeId)

    def testImg1(self):
        """获取图形验证码"""
        self.cls = common.getXls("testCase.xlsx", "test1")
        self.log = log.get_log()
        self.logger = self.log.getLogger()
        self.Http = configHttp.ConfigHttp()
        self.HttpUrl = self.Http.setUrl(self.cls.get(0).get("url"))
        self.logger.info(self.HttpUrl)
        self.Http.setParams(self.cls.get(0).get("params"))
        self.r = self.Http.get()
        self.r.status_code
        self.r.encoding = 'utf-8'
        self.r.text
        self.logger.info(self.r.text)
        self.logger.info(self.r.status_code)
        self.imgCodeId = self.r.json().get("data").get("imgCodeId")
        self.confige.setReslConfig("imgCodeId", self.imgCodeId)

    def tearDown(self):
        self.confige.setReslConfig("imgCodeId", self.imgCodeId)
        print("tearDown")
Exemplo n.º 5
0
import os
import logging
from datetime import datetime
from Common.ReadConfig import ReadConfig

localReadConfig = ReadConfig()


class Log:
    def __init__(self):
        global logPath, resultPath, proDir
        proDir = os.getcwd()
        resultPath = os.path.join(proDir, "Result")
        if not os.path.exists(resultPath):
            os.mkdir(resultPath)
        logPath = os.path.join(resultPath,
                               str(datetime.now().strftime("%Y-%m-%d")))
        if not os.path.exists(logPath):
            os.mkdir(logPath)
        self.logger = logging.getLogger()
        self.logger.setLevel(logging.INFO)
        # 增加判断,不会出现重复记录日志的问题
        if not self.logger.handlers:
            # 定义handler
            handler = logging.FileHandler(os.path.join(logPath, "log.log"))
            # 设置日志的输出格式
            formatter = logging.Formatter(
                '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
            handler.setFormatter(formatter)
            self.logger.addHandler(handler)
Exemplo n.º 6
0
        prefs["credentials_enable_service"] = False
        prefs["profile.password_manager_enabled"] = False
        opt.add_experimental_option("prefs", prefs)

        # 关掉自动化控制提示
        opt.add_experimental_option('useAutomationExtension', False)
        opt.add_experimental_option('excludeSwitches', ['enable-automation'])

        #隐身(无痕)模式
        opt.add_argument('--incognito')

        # 最大化运行(全屏窗口)
        opt.add_argument('--start-maximized')

        #启动浏览器
        driver = webdriver.Chrome(options=opt)
    else:
        logger.info('chrome 无界面运行')
        opt.add_argument('--headless')
        opt.add_experimental_option('useAutomationExtension', False)
        opt.add_experimental_option('excludeSwitches', ['enable-automation'])
        opt.add_argument('--start-maximized')  #最大化运行(全屏窗口)
        driver = webdriver.Chrome(options=opt)
    return driver


if __name__ == '__main__':
    url = ReadConfig().get_driver('url')
    driver = BaseDriver()
    driver.get(url)
    # driver.get('http://101.129.1.87/CMSMOBILE')
Exemplo n.º 7
0
 def setUp(self):
     self.confige = ReadConfig()
Exemplo n.º 8
0
 def __init__(self):
     self.mobile_num = ""
     self.readConfig = ReadConfig()
     pass