Exemple #1
0
class GotoLan(unittest.TestCase):
    def setUp(self):

        self.testcaseinfo = TestCaseInfo(id=13, name="是否能顺利跳转到lan页面 ")

        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"))
        # 读取报告行数和报告名称
        self.lanpage = LanPage()

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

            # L.info("test_login_right: test START")
            self.starttime = time.strftime("%Y-%m-%d %H:%M:%S")
            self.testcaseinfo.starttime = self.starttime
            self.lanpage.goto_lan()
            time.sleep(5)
            expecturl = "http://192.168.0.1/DhcpServer.html"
            try:
                self.assertEqual(expecturl, self.lanpage.getCurrentUrl())
            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.log.error(traceback.format_exc())
            self.testcaseinfo.result = "error"
        finally:
            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"))

    def tearDown(self):

        self.log.info([self.testcaseinfo.get_case_info()])
        self.lanpage.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)
Exemple #2
0
 def setUp(self):
     self.testcaseinfo = TestCaseInfo(id=22, name="DHCP 能否被正确关闭 ")
     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"))
     # 读取报告行数和报告名称
     self.lanpage=LanPage()
Exemple #3
0
class LanDefaultCheck(unittest.TestCase):
    def setUp(self):

        self.testcaseinfo = TestCaseInfo(id=14, name="lan页面默认项检查 ")

        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"))
        # 读取报告行数和报告名称
        self.lanpage = LanPage()

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

            # L.info("test_login_right: test START")
            self.starttime = time.strftime("%Y-%m-%d %H:%M:%S")
            self.testcaseinfo.starttime = self.starttime
            self.lanpage.goto_lan()
            lanipvalue = self.lanpage.get_lanip()
            self.log.info("默认的局域网地址:%s" % lanipvalue)
            dhcpstatus = self.lanpage.get_dhcpstatus()
            self.log.info("默认的dhcp状态是:%s" % dhcpstatus)
            startip = self.lanpage.get_startip()
            self.log.info("默认的初始IP地址池:%s" % startip)
            endip = self.lanpage.get_endip()
            self.log.info("默认的结束IP地址池: %s" % endip)
            self.testcaseinfo.result = "Pass"

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

    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.lanpage.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)
Exemple #4
0
class DhcpClose(unittest.TestCase):
    def setUp(self):
        self.testcaseinfo = TestCaseInfo(id=22, name="DHCP 能否被正确关闭 ")
        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"))
        # 读取报告行数和报告名称
        self.lanpage=LanPage()

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

            self.starttime = time.strftime("%Y-%m-%d %H:%M:%S")
            self.testcaseinfo.starttime = self.starttime
            self.lanpage.goto_lan()
            time.sleep(5)
            self.lanpage.click_dhcp_button()
            time.sleep(5)
            if not self.lanpage.is_dhcp_pool_displayed():
              self.testcaseinfo.result='Pass'
            else:
                self.testcaseinfo.result = "Fail"

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

    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.lanpage.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)
Exemple #5
0
class StartIpIllegal(unittest.TestCase):
    def setUp(self):

        self.testcaseinfo = TestCaseInfo(id=19, name="结束IP地址非法时提示信息检查 ")

        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"))
        # 读取报告行数和报告名称
        self.lanpage=LanPage()

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

            # L.info("test_login_right: test START")
            self.starttime = time.strftime("%Y-%m-%d %H:%M:%S")
            self.testcaseinfo.starttime = self.starttime
            self.lanpage.goto_lan()
            time.sleep(5)
            self.lanpage.clear_startip()
            self.lanpage.set_startip("2")
            self.lanpage.clear_endip()
            self.lanpage.set_endip("255")
            self.lanpage.scroll_window()
            time.sleep(3)
            self.lanpage.click_savebutton()
            time.sleep(5)
            if self.lanpage.is_startip_errorinfo_displayed():
                errorinfo = self.lanpage.get_error_text2()
                self.log.info(errorinfo)
                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.log.error(traceback.format_exc())
            self.testcaseinfo.result = "error"

    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.lanpage.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)
Exemple #6
0
class ChangeLanIp(unittest.TestCase):
    def setUp(self):

        self.testcaseinfo = TestCaseInfo(id=17, name="lan页面修改局域网地址是否可以成功 ")

        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"))
        # 读取报告行数和报告名称
        self.lanpage = LanPage()

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

            # L.info("test_login_right: test START")
            self.starttime = time.strftime("%Y-%m-%d %H:%M:%S")
            self.testcaseinfo.starttime = self.starttime
            self.lanpage.goto_lan()
            time.sleep(5)
            self.lanpage.clear_lanip()
            time.sleep(2)
            self.lanpage.set_lanip(new_lan_ip())
            self.lanpage.scroll_window()

            self.lanpage.click_savebutton()
            self.lanpage.wait_alert_invisibale()

            time.sleep(5)
            try:
                self.assertEqual(self.lanpage.getCurrentUrl(),
                                 "http://" + str(new_lan_ip()) + "/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.log.error(traceback.format_exc())
            self.testcaseinfo.result = "error"

    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.log.info("测试完成后修改到原来的IP")
        self.lanpage.second_goto_lan()
        time.sleep(3)
        self.lanpage.clear_lanip()
        self.lanpage.set_lanip(re.split("//", base_url())[1])
        self.lanpage.scroll_window()
        self.lanpage.click_savebutton()
        self.lanpage.wait_alert_invisibale()

        self.lanpage.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)
Exemple #7
0
class StartEndIpLegal(unittest.TestCase):
    def setUp(self):

        self.testcaseinfo = TestCaseInfo(id=21,
                                         name="开始ip地址和结束IP地址都合法时,是否可以成功保存 ")

        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"))
        # 读取报告行数和报告名称
        self.lanpage = LanPage()

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

            # L.info("test_login_right: test START")
            self.starttime = time.strftime("%Y-%m-%d %H:%M:%S")
            self.testcaseinfo.starttime = self.starttime
            self.lanpage.goto_lan()
            time.sleep(5)
            self.lanpage.clear_startip()
            self.lanpage.set_startip("100")
            self.lanpage.clear_endip()
            self.lanpage.set_endip("150")
            self.lanpage.scroll_window()
            time.sleep(8)
            self.lanpage.click_savebutton()
            self.lanpage.wait_alert_invisibale()

            time.sleep(5)
            try:
                self.assertEqual('100', self.lanpage.get_startip())
            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.log.error(traceback.format_exc())
            self.testcaseinfo.result = "error"

    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.lanpage.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)
Exemple #8
0
class IllegalLanipEnter(unittest.TestCase):
    def setUp(self):

        self.testcaseinfo = TestCaseInfo(id=16,
                                         name="lan页面输入格式错误的局域网地址时的提示语检查 ")

        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"))
        # 读取报告行数和报告名称
        self.lanpage = LanPage()

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

            # L.info("test_login_right: test START")
            self.starttime = time.strftime("%Y-%m-%d %H:%M:%S")
            self.testcaseinfo.starttime = self.starttime
            self.lanpage.goto_lan()
            time.sleep(5)
            self.lanpage.clear_lanip()
            result = 0
            wrongip = [
                '192.168.www.4', '192.!23.tt.com', '192.168.%$.#',
                '1 92.168.  34', '192.168.344.2', '192.-168.3.2'
            ]
            for ip in wrongip:
                self.lanpage.clear_lanip()
                self.lanpage.set_lanip(ip)
                self.lanpage.scroll_window()
                time.sleep(2)
                self.lanpage.click_savebutton()
                if self.lanpage.is_ip_errorinfo_displayed():
                    errorinfo = self.lanpage.get_error_text()
                    self.log.info(errorinfo)
                    if errorinfo == "IP地址含非法字符,请重新输入。" or errorinfo == "IP地址格式错误,请重新输入。":
                        result += 1
                    else:
                        self.testcaseinfo.result = 'Fail'
            try:
                self.assertEqual(len(wrongip), result)
                self.testcaseinfo.result = "Pass"
            except Exception as e:
                self.log.error(traceback.format_exc())
                self.testcaseinfo.result = "Fail"
                self.testcaseinfo.errorinfo = str(e)
                self.testcaseinfo.result = "Fail"
            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.log.error(traceback.format_exc())
            self.testcaseinfo.result = "error"

    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.lanpage.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)