def __init__(self):
     # self.addmerchantfun = AddMerchantFun()   #实例化
     # self.webfunction = WebFunction()   #实例化
     self.file_name = "../dataconfig/asserttextjiesuan.xls"
     self.sheet_id = 0
     self.data = GetData(self.file_name, self.sheet_id)  #实例化
     self.send_mai = SendEmail()  #实例化
     self.loginurl = "https://bjw.halodigit.com:9090/nereus/manager/index#/login"
     self.loginaccountxpath = "/html/body/div[1]/div[2]/form/div/div[1]/input"
     self.loginaccount = "*****@*****.**"
     self.loginppasswordxpath = "/html/body/div[1]/div[2]/form/div/div[2]/input"
     self.loginpassword = "******"
     self.loginbuttonxpath = "/html/body/div[1]/div[2]/form/div/a[1]/span"
 def __init__(self):
     # self.addmerchantfun = AddMerchantFun()   #实例化
     # self.webfunction = WebFunction()   #实例化
     self.file_name = "../dataconfig/asserttextagent.xls"
     self.sheet_id = 0
     self.data = GetData(self.file_name, self.sheet_id)  #实例化
     self.send_mai = SendEmail()  #实例化
     self.loginurl = "https://bjw.halodigit.com:9090/nereus/agent/index"
     self.loginaccountxpath = "/html/body/div[1]/div[2]/form/div/div[2]/div[1]/input"
     self.loginaccount = "6281122336666"
     self.loginppasswordxpath = "/html/body/div[1]/div[2]/form/div/div[2]/div[2]/input"
     self.loginpassword = "******"
     self.loginbuttonxpath = "/html/body/div[1]/div[2]/form/div/div[2]/a/span"
Exemplo n.º 3
0
    def printLog(self, fun):
        print('---------------------------')
        stdout_backup = sys.stdout
        gettime = GetTimeStr()
        timestr = gettime.getTimeStr()
        # define the log file that receives your log info
        logpath = "../log/%s_message.txt" % timestr
        log_file = open(logpath, "w", encoding="utf-8")
        print("Now all print info will be written to message.log")
        # redirect print output to log file
        sys.stdout = log_file

        print('----------开始打印日志-----------------\n')

        # any command line that you will execute
        fun
        print('\n----------日志打印结束-----------------')
        log_file.close()
        # restore the output to initial pattern
        sys.stdout = stdout_backup
        print("Now this will be presented on screen")
        # 发送log至邮箱
        send_e = SendEmail()
        send_e.send_main([1], [2], logpath)
Exemplo n.º 4
0
    for testpy in alltestnames:
        try:
            suite.addTest(unittest.defaultTestLoader.loadTestsFromName(testpy))    #默认加载所有用例
        except Exception:
            print('ERROR: Skipping tests from "%s".' % testpy)
            try:
                __import__(test)
            except ImportError:
                print('Could not import the "%s" test module.'% testpy)
            else:
                print('Could not load the "%s" test suite.' % testpy)
            from traceback import print_exc
            print_exc()
    print('Running the tests...')
    gettime = GetTimeStr()
    filename ='../report/%s_report.html' % gettime.getTimeStr()
    fp = open(filename, 'wb')

    # 定义测试报告
    runner = HTMLTestRunner.HTMLTestRunner(
        stream=fp,
        title=u'selenium自动化测试_测试报告',
        description=u'用例执行情况:')
    runner.run(suite)
    fp.close()

    #发送report至邮箱
    send_e = SendEmail()
    send_e.send_main([1],[2],filename)

class RunTest:
    def __init__(self):
        # self.addmerchantfun = AddMerchantFun()   #实例化
        # self.webfunction = WebFunction()   #实例化
        self.file_name = "../dataconfig/asserttextjiesuan.xls"
        self.sheet_id = 0
        self.data = GetData(self.file_name, self.sheet_id)  #实例化
        self.send_mai = SendEmail()  #实例化
        self.loginurl = "https://bjw.halodigit.com:9090/nereus/manager/index#/login"
        self.loginaccountxpath = "/html/body/div[1]/div[2]/form/div/div[1]/input"
        self.loginaccount = "*****@*****.**"
        self.loginppasswordxpath = "/html/body/div[1]/div[2]/form/div/div[2]/input"
        self.loginpassword = "******"
        self.loginbuttonxpath = "/html/body/div[1]/div[2]/form/div/a[1]/span"

    def getcookie(self):
        self.webfunction = WebFunction()  # 实例化
        # 登录
        self.webfunction.activeweb.getUrl(self.loginurl)  # 打开网址
        self.webfunction.activeweb.findElementByXpathAndInput(
            self.loginaccountxpath, self.loginaccount)
        self.webfunction.activeweb.findElementByXpathAndInput(
            self.loginppasswordxpath, self.loginpassword)
        self.webfunction.activeweb.findElementByXpathAndClick(
            self.loginbuttonxpath)
        self.webfunction.activeweb.delayTime(3)
        # 获取cookie
        cookie = self.webfunction.activeweb.getCookies()
        self.webfunction.activeweb.closeBrowse()
        return cookie

    #程序执行
    def go_on_run(self):
        global cookie
        cookie = self.getcookie()

        res = None
        pass_count = []
        fail_count = []
        # global assertresult
        assertresult = [0, 0]
        rows_count = self.data.get_case_lines()

        print("需要执行%d个用例:" % (rows_count - 1))
        for i in range(1, rows_count):  #循环,但去掉第一个

            try:
                print("\n执行第%d个用例\n" % i)
                url = self.data.get_url(i)
                testxpath = self.data.get_testxpath(i)
                preresult = self.data.get_preresult(i)
                self.webfunction = WebFunction()  # 实例化

                if self.data.is_cookie(i):
                    self.webfunction.activeweb.writerCookies(
                        cookie, self.loginurl, url)
                else:
                    self.webfunction.activeweb.getUrl(url)

                assertresult = self.webfunction.assertText(
                    i, testxpath, preresult)

            except Exception as e:
                print('\n异常现象打印:\n', e)
            finally:
                # print('第%d次循环执行完毕'%i)
                if assertresult[0] == 'pass':
                    self.data.write_testresult(i, 'pass')
                    pass_count.append(i + 1)  # 通过的加到集合里
                    self.data.write_testdescription(i, str(assertresult[1]))
                else:
                    self.data.write_testresult(i, 'fail')
                    fail_count.append(i + 1)  # 失败的加到集合里
                    self.data.write_testdescription(i, str(assertresult[1]))
                self.webfunction.activeweb.closeBrowse()
                assertresult = [0, 0]
            i = i + 1
        print("\n成功的行数:", pass_count)
        print("\n失败的行数:", fail_count)
        self.send_mai.send_main(pass_count, fail_count,
                                self.file_name)  # 调用发送邮件
                assertresult = [0, 0]
            i = i + 1
        print("\n成功的行数:", pass_count)
        print("\n失败的行数:", fail_count)
        self.send_mai.send_main(pass_count, fail_count,
                                self.file_name)  # 调用发送邮件


if __name__ == '__main__':
    run = RunTest()  #实例化
    print('---------------------------')
    stdout_backup = sys.stdout
    gettime = GetTimeStr()
    timestr = gettime.getTimeStr()
    logpath = "../log/%s_message.txt" % timestr
    print("Now all print info will be written to log文件:", logpath)
    # define the log file that receives your log info
    log_file = open(logpath, "w", encoding="utf-8")
    # redirect print output to log file
    sys.stdout = log_file
    print('----------开始打印日志-----------------\n')
    run.go_on_run()
    print('\n----------日志打印结束-----------------')
    log_file.close()
    # restore the output to initial pattern
    sys.stdout = stdout_backup
    print("Now this will be presented on screen")

    #发送log至邮箱
    send_e = SendEmail()
    send_e.send_main([1], [2], logpath)