Exemplo n.º 1
0
    def setUp(self):

        self.baseurl = base_url()
        self.loginpage = LoginPage()
        self.testcaseinfo = TestCaseInfo(id=5, name="不填写密码时的提示信息是否正确 ")

        config = configparser.ConfigParser()
        config.read(r"./common/data.ini")
        filepath = config.get("logfile", "logfile")
        self.log = logger(filepath)
        self.reportfile = config.get("report", "xlsfile")
        self.row = config.get("report", "line")
        self.teststarttime = config.get("teststarttime", "teststarttime")
        config.set("report", "line", str(int(self.row) + 1))
        config.write(open("./common/data.ini", "w"))
Exemplo n.º 2
0
class Logout(unittest.TestCase):
    def setUp(self):
        self.baseurl = base_url()

        self.loginpage = LoginPage()

        config = configparser.ConfigParser()
        config.read(r"./common/data.ini")
        self.filepath = config.get("logfile", "logfile")
        self.reportfile = config.get("report", "xlsfile")
        self.row = config.get("report", "line")
        self.teststarttime = config.get("teststarttime", "teststarttime")
        config.set("report", "line", str(int(self.row) + 1))
        config.write(open("./common/data.ini", "w"))
        print(self.filepath)
        self.log = logger(self.filepath)
        self.testcaseinfo = TestCaseInfo(id=43, name="退出系统 ")
    def test_logout(self):
        try:
            self.starttime = time.strftime("%Y-%m-%d %H:%M:%S")
            self.testcaseinfo.starttime = self.starttime
            self.loginpage.open(self.baseurl)
            time.sleep(5)
            password = right_password()
            self.loginpage.input_password(password)
            time.sleep(2)
            self.loginpage.click_login()
            time.sleep(2)
            self.loginpage.maximizeWindow()
            logoutbutton = ('id', 'logoutword')
            logout=self.loginpage.findElement(logoutbutton)
            self.loginpage.click(logout)
            time.sleep(3)
            try:
                self.assertEqual(self.loginpage.getCurrentUrl(), "http://192.168.0.1/Login.html")
            except Exception as e:
                self.log.error(traceback.format_exc())
                self.testcaseinfo.result = "Fail"
                self.testcaseinfo.errorinfo = str(e)
            else:
                self.testcaseinfo.result = "Pass"

        except Exception as err:
            self.testcaseinfo.errorinfo = str(err)
            self.testcaseinfo.result = "error"
            self.log.error(traceback.format_exc())

    def tearDown(self):
        endtime = time.strftime("%Y-%m-%d %H:%M:%S")
        self.testcaseinfo.endtime = endtime

        self.testcaseinfo.secondsDuration = str(datetime.strptime(endtime, "%Y-%m-%d %H:%M:%S") \
                                                - datetime.strptime(self.starttime, "%Y-%m-%d %H:%M:%S"))
        self.log.info([self.testcaseinfo.get_case_info()])
        self.loginpage.quit()
        repr = xlrd.open_workbook(self.reportfile, formatting_info=True)
        self.log.info(repr)
        newrepr = copy(repr)
        self.log.info(newrepr)
        newreprs = newrepr.get_sheet(0)
        tr.write_data(newreprs,self.teststarttime, int(self.row), *list(self.testcaseinfo.get_case_info()))
        newrepr.save(self.reportfile)
Exemplo n.º 3
0
class GotoLogin(unittest.TestCase):
    """登录首页测试用例"""
    def setUp(self):

        self.baseurl = base_url()

        self.loginpage = LoginPage()

        config = configparser.ConfigParser()
        config.read(r"./common/data.ini")
        self.filepath = config.get("logfile", "logfile")
        self.reportfile = config.get("report", "xlsfile")
        self.teststarttime = config.get("teststarttime", "teststarttime")
        self.row = config.get("report", "line")
        config.set("report", "line", str(int(self.row) + 1))
        config.write(open("./common/data.ini", "w"))
        print(self.filepath)
        self.log = logger(self.filepath)
        self.testcaseinfo = TestCaseInfo(id=1, name="登录页面跳转测试 ")

    def test_goto_login(self):
        """登录页跳转测试"""
        format = "%a %b %d %H:%M:%S %Y"
        try:
            self.log.info("test_goto_login: test START ")
            # starttime=time.time()
            # self.testcaseinfo.starttime=time.ctime(starttime)
            self.starttime = time.strftime("%Y-%m-%d %H:%M:%S")
            self.testcaseinfo.starttime = self.starttime
            baseurl = self.baseurl
            loginpage = self.loginpage
            loginpage.open(self.baseurl)
            time.sleep(2)
            title = loginpage.getTitle()
            try:
                self.assertEqual('DIR-823Pro', title)
            except Exception as e:
                self.log.error(traceback.format_exc())
                self.testcaseinfo.result = "Fail"
                self.testcaseinfo.errorinfo = str(e)
                # raise AssertionError(traceback.format_exc())
            else:

                self.testcaseinfo.result = "Pass"

            # endtime=time.time()
            # self.testcaseinfo.endtime =time.ctime(endtime)
            endtime = time.strftime("%Y-%m-%d %H:%M:%S")
            self.testcaseinfo.endtime = endtime

            self.testcaseinfo.secondsDuration= str(datetime.strptime(endtime,"%Y-%m-%d %H:%M:%S")\
                                                   -datetime.strptime(self.starttime,"%Y-%m-%d %H:%M:%S"))
        except Exception as err:
            self.testcaseinfo.errorinfo = str(err)
            self.testcaseinfo.result = "error"
            self.log.error(traceback.format_exc())

    def tearDown(self):
        endtime = time.strftime("%Y-%m-%d %H:%M:%S")
        self.testcaseinfo.endtime = endtime

        self.testcaseinfo.secondsDuration = str(datetime.strptime(endtime, "%Y-%m-%d %H:%M:%S") \
                                                - datetime.strptime(self.starttime, "%Y-%m-%d %H:%M:%S"))
        self.log.info([self.testcaseinfo.get_case_info()])
        self.loginpage.quit()

        repr = xlrd.open_workbook(self.reportfile, formatting_info=True)

        self.log.info(repr)
        newrepr = copy(repr)
        self.log.info(newrepr)
        newreprs = newrepr.get_sheet(0)
        tr.write_data(newreprs, self.teststarttime, int(self.row),
                      *list(self.testcaseinfo.get_case_info()))
        newrepr.save(self.reportfile)


# if __name__ == '__main__':
#     unittest.main()
Exemplo n.º 4
0
class NoPwEnter(unittest.TestCase):
    """登录首页测试用例"""
    def setUp(self):

        self.baseurl = base_url()
        self.loginpage = LoginPage()
        self.testcaseinfo = TestCaseInfo(id=5, name="不填写密码时的提示信息是否正确 ")

        config = configparser.ConfigParser()
        config.read(r"./common/data.ini")
        filepath = config.get("logfile", "logfile")
        self.log = logger(filepath)
        self.reportfile = config.get("report", "xlsfile")
        self.row = config.get("report", "line")
        self.teststarttime = config.get("teststarttime", "teststarttime")
        config.set("report", "line", str(int(self.row) + 1))
        config.write(open("./common/data.ini", "w"))
        #读取报告行数和报告名称

    def test_nopwenter(self):
        """正确的密码登录是否能登录成功"""
        try:

            # L.info("test_login_right: test START")
            self.starttime = time.strftime("%Y-%m-%d %H:%M:%S")
            self.testcaseinfo.starttime = self.starttime

            baseurl = self.baseurl
            loginpage = self.loginpage
            loginpage.open(self.baseurl)
            time.sleep(3)
            loginpage.click_login()
            time.sleep(5)
            if self.loginpage.error_info_displayed():
                errorinfo = self.loginpage.error_info_text()
                try:
                    self.assertEqual(errorinfo, "请输入登录密码。")
                except Exception as e:
                    self.log.error(traceback.format_exc())
                    self.testcaseinfo.result = "Fail"
                    self.testcaseinfo.errorinfo = str(e)
                else:
                    self.testcaseinfo.result = "Pass"
            else:
                self.testcaseinfo.result = "error"

        except Exception as err:
            self.testcaseinfo.errorinfo = str(err)
            self.testcaseinfo.result = "error"
            self.log.error(traceback.format_exc())

    def tearDown(self):
        endtime = time.strftime("%Y-%m-%d %H:%M:%S")
        self.testcaseinfo.endtime = endtime

        self.testcaseinfo.secondsDuration = str(datetime.strptime(endtime, "%Y-%m-%d %H:%M:%S") \
                                                - datetime.strptime(self.starttime, "%Y-%m-%d %H:%M:%S"))
        self.log.info([self.testcaseinfo.get_case_info()])
        self.loginpage.quit()
        repr = xlrd.open_workbook(self.reportfile, formatting_info=True)
        self.log.info(repr)
        newrepr = copy(repr)
        self.log.info(newrepr)
        newreprs = newrepr.get_sheet(0)
        tr.write_data(newreprs, self.teststarttime, int(self.row),
                      *list(self.testcaseinfo.get_case_info()))
        newrepr.save(self.reportfile)
Exemplo n.º 5
0
class LoginRight(unittest.TestCase):
    """登录首页测试用例"""
    def setUp(self):

        self.baseurl = base_url()
        self.loginpage = LoginPage()
        self.testcaseinfo = TestCaseInfo(id=2, name="正确密码是否可成功登录测试 ")

        config = configparser.ConfigParser()
        config.read(r"./common/data.ini")
        filepath = config.get("logfile", "logfile")
        self.log = logger(filepath)
        self.reportfile = config.get("report", "xlsfile")
        self.row = config.get("report", "line")
        self.teststarttime = config.get("teststarttime", "teststarttime")
        config.set("report", "line", str(int(self.row) + 1))
        config.write(open("./common/data.ini", "w"))
        #读取报告行数和报告名称

    def test_login_right(self):
        """正确的密码登录是否能登录成功"""
        try:

            # L.info("test_login_right: test START")
            # starttime=time.time()
            # self.testcaseinfo.starttime=time.ctime(starttime)
            self.starttime = time.strftime("%Y-%m-%d %H:%M:%S")
            self.testcaseinfo.starttime = self.starttime

            baseurl = self.baseurl
            loginpage = self.loginpage
            loginpage.open(self.baseurl)
            time.sleep(5)
            password = right_password()
            loginpage.input_password(password)
            time.sleep(2)
            loginpage.click_login()
            time.sleep(5)
            expecturl = 'http://192.168.0.1/Home.html'
            currenturl = loginpage.getCurrentUrl()
            try:
                self.assertEqual(expecturl, currenturl)
            except Exception as e:
                self.log.error(traceback.format_exc())
                self.testcaseinfo.result = "Fail"
                self.testcaseinfo.errorinfo = str(e)
            else:
                self.testcaseinfo.result = "Pass"

            # endtime = time.time()
            # self.testcaseinfo.endtime = time.ctime(endtime)
            #
            # self.testcaseinfo.secondsDuration= endtime - starttime
            # # L.info([self.testcaseinfo.getcaseinfo()])
            endtime = time.strftime("%Y-%m-%d %H:%M:%S")
            self.testcaseinfo.endtime = endtime

            self.testcaseinfo.secondsDuration = str(datetime.strptime(endtime, "%Y-%m-%d %H:%M:%S") \
                                                    - datetime.strptime(self.starttime, "%Y-%m-%d %H:%M:%S"))
        except Exception as err:
            self.testcaseinfo.errorinfo = str(err)
            self.testcaseinfo.result = "error"
            self.log.error(traceback.format_exc())

    def tearDown(self):
        endtime = time.strftime("%Y-%m-%d %H:%M:%S")
        self.testcaseinfo.endtime = endtime

        self.testcaseinfo.secondsDuration = str(datetime.strptime(endtime, "%Y-%m-%d %H:%M:%S") \
                                                - datetime.strptime(self.starttime, "%Y-%m-%d %H:%M:%S"))
        self.log.info([self.testcaseinfo.get_case_info()])
        self.loginpage.quit()
        repr = xlrd.open_workbook(self.reportfile, formatting_info=True)
        self.log.info(repr)
        newrepr = copy(repr)
        self.log.info(newrepr)
        newreprs = newrepr.get_sheet(0)
        tr.write_data(newreprs, self.teststarttime, int(self.row),
                      *list(self.testcaseinfo.get_case_info()))
        newrepr.save(self.reportfile)