示例#1
0
 def setUp(self, masterqa_mode=False):
     super(TestSettingsCase, self).setUp()
     # super(TestPortalCase, self) 首先找到TestPortalCase 的父类(就是类 BaseCase),然后把类 TestPortalCase  的对象转换为类 BaseCase的对象
     function.open_tmx(self)
     self.dr = self.driver
     try:
         function.login(self, ReadData.Basic_data(self, "TMX用户名"),
                        ReadData.Basic_data(self, "TMX密码"))
         time.sleep(1)
     except:
         print("登录失败")
示例#2
0
    def test_5_screen_group(self):
        '''通过group筛选设备,并关闭筛选'''
        try:
            self.dr.find_element_by_css_selector(
                ReadElement.device_ele(self, "Asset下拉操作")).click()
            time.sleep(0.5)
            # self.dr.find_element_by_partial_link_text("Device").click()
            # print(self.dr.find_element_by_css_selector(ReadElement.device_ele(self, "点击device")).text)
            self.dr.find_element_by_xpath(
                ReadElement.device_ele(self, "点击device")).click()
            self.dr.implicitly_wait(15)
            self.dr.find_element_by_css_selector(
                ReadElement.device_ele(self, "下拉筛选group")).click()
            time.sleep(2)
            self.dr.find_element_by_xpath(
                ReadElement.device_ele(self, "选择group类型")).click()
            time.sleep(2)
            print(
                self.dr.find_element_by_css_selector(
                    ReadElement.device_ele(self, "断言group类型")).text)
            self.assertEqual(
                self.dr.find_element_by_css_selector(
                    ReadElement.device_ele(self, "断言group类型")).text,
                ReadData.Basic_data(self, "断言group类型"))
        except:
            print(
                self.dr.find_element_by_css_selector(
                    ReadElement.device_ele(self, "断言group类型")).text + "fail")
            function.error_png(self, sys._getframe().f_code.co_name)
            self.assertEqual(
                self.dr.find_element_by_css_selector(
                    ReadElement.device_ele(self, "断言group类型")).text,
                ReadData.Basic_data(self, "断言group类型"))
        try:
            self.dr.find_element_by_css_selector(
                ReadElement.device_ele(self, "再次点击筛选group")).click()
            time.sleep(2)
            self.dr.find_element_by_css_selector(
                ReadElement.device_ele(self, "关闭筛选group")).click()
            # self.dr.find_element_by_xpath(ReadElement.device_ele(self, "关闭筛选Model")).click()
            time.sleep(2)
            self.assertEqual(
                self.dr.find_element_by_css_selector(
                    ReadElement.device_ele(self, "下拉筛选group")).text, "Group")
        except:

            print(
                self.dr.find_element_by_css_selector(
                    ReadElement.device_ele(self, "下拉筛选group")).text)
            #函数内部获取当前函数名称,用sys._getframe().f_code.co_name方法获取
            function.error_png(self, sys._getframe().f_code.co_name)
            self.assertEqual(
                self.dr.find_element_by_css_selector(
                    ReadElement.device_ele(self, "下拉筛选group")).text, "Group")
示例#3
0
 def setUp(self, masterqa_mode=False):
     super(TestDevicelistCase, self).setUp()
     # super(TestPortalCase, self) 首先找到TestPortalCase 的父类(就是类 BaseCase),然后把类 TestPortalCase  的对象转换为类 BaseCase的对象
     # print("setup_method(self):在每个方法之前执行")
     function.open_tmx(self)
     self.dr = self.driver
     try:
         function.login(self, ReadData.Basic_data(self, "TMX用户名"),
                        ReadData.Basic_data(self, "TMX密码"))
         time.sleep(1)
         # 断言是否登录成功
         # self.assertEqual(self.dr.find_element_by_xpath(ReadElement.Portal_ele(self, "Asset定位")).text,
         #                  "Asset")
     except:
         print("登录失败")
示例#4
0
 def test_010_General_setting_Only_user_active(self):
     '''user用户设置GeneralSetting时仅该用户生效该设置'''
     try:
         function.by_ccs(self, ReadElement.setting(self,
                                                   "settings图标")).click()
         time.sleep(1)
         self.dr.execute_script(ReadElement.setting(
             self, "Generalsettings")).click()
         time.sleep(0.5)
         print(self.dr.execute_script(ReadElement.setting(self, "断言当前地图")))
         time.sleep(0.5)
         self.assertEqual(
             self.dr.execute_script(ReadElement.setting(self, "断言当前地图")),
             "Google Map")
         time.sleep(0.5)
         self.click(ReadElement.setting(self, "用户登陆标识"))
         self.click(ReadElement.setting(self, "退出登陆"))
         function.login(self, ReadData.Basic_data(self, "TMXuser用户"),
                        ReadData.Basic_data(self, "TMXuser密码"))
         time.sleep(1)
         print(self.execute_script(ReadElement.setting(self, "用户登陆标识TEXT")))
         self.assertEqual(
             self.execute_script(ReadElement.setting(self, "用户登陆标识TEXT")),
             "CW")
         time.sleep(1)
         function.by_ccs(self, ReadElement.setting(self,
                                                   "settings图标")).click()
         time.sleep(1)
         self.click(ReadElement.setting(self, "user用户Edit按钮"))
         time.sleep(0.5)
         self.dr.execute_script(ReadElement.setting(self,
                                                    "下拉选择MAP")).click()
         time.sleep(0.5)
         self.dr.implicitly_wait(10)
         function.by_ccs(self, ReadElement.setting(self, "选择百度地图")).click()
         self.dr.execute_script(ReadElement.setting(self, "save按钮")).click()
         time.sleep(0.5)
         print(self.dr.execute_script(ReadElement.setting(self, "断言当前地图")))
         time.sleep(0.5)
         self.assertEqual(
             self.dr.execute_script(ReadElement.setting(self, "断言当前地图")),
             "Baidu Map")
     except:
         function.save_img(self, sys._getframe().f_code.co_name)
         self.assertEqual(
             self.dr.execute_script(ReadElement.setting(self, "断言当前地图")),
             "Baidu Map")
示例#5
0
 def test_009_General_setting_Only_admin_active(self):
     '''admin用户设置GeneralSetting时仅该用户生效该设置'''
     try:
         function.by_ccs(self, ReadElement.setting(self,
                                                   "settings图标")).click()
         time.sleep(1)
         self.dr.execute_script(ReadElement.setting(
             self, "Generalsettings")).click()
         time.sleep(0.5)
         self.dr.execute_script(ReadElement.setting(self, "Edit按钮")).click()
         time.sleep(0.5)
         self.dr.execute_script(ReadElement.setting(
             self, "WeightImperial")).click()
         self.dr.implicitly_wait(10)
         time.sleep(2)
         self.dr.execute_script(ReadElement.setting(self, "save按钮")).click()
         time.sleep(0.5)
         print(
             self.dr.execute_script(
                 ReadElement.setting(self, "Weightunit单位")))
         assert self.dr.execute_script(
             ReadElement.setting(self, "Weightunit单位")) == "Imperial"
         time.sleep(0.5)
         self.click(ReadElement.setting(self, "用户登陆标识"))
         self.click(ReadElement.setting(self, "退出登陆"))
         function.login(self, ReadData.Basic_data(self, "TMXuser用户"),
                        ReadData.Basic_data(self, "TMXuser密码"))
         time.sleep(1)
         print(self.execute_script(ReadElement.setting(self, "用户登陆标识TEXT")))
         self.assertEqual(
             self.execute_script(ReadElement.setting(self, "用户登陆标识TEXT")),
             "CW")
         function.by_ccs(self, ReadElement.setting(self,
                                                   "settings图标")).click()
         time.sleep(1)
         self.dr.execute_script(ReadElement.setting(
             self, "Generalsettings")).click()
         assert self.dr.execute_script(
             ReadElement.setting(self, "Weightunit单位")) == "Metric"
     except:
         function.save_img(self, sys._getframe().f_code.co_name)
         assert self.dr.execute_script(
             ReadElement.setting(self, "Weightunit单位")) == "Metric"
示例#6
0
 def test_1_login(self):
     '''输入正确的用户名,密码,登陆成功'''
     # function.open_tmx(self)
     # self.dr = self.driver
     try:
         function.login(self, ReadData.Basic_data(self, "TMX用户名"),
                        ReadData.Basic_data(self, "TMX密码"))
         time.sleep(1)
         # 断言是否登录成功
         self.assertEqual(
             self.dr.find_element_by_xpath(
                 ReadElement.Portal_ele(self, "Asset定位")).text, "Asset")
         print("登录成功")
     except:
         print("登录失败")
         # 截图
         function.error_png(self, 'test_1_login')
         self.assertEqual(
             self.dr.find_element_by_xpath(
                 ReadElement.Portal_ele(self, "Asset定位")).text, "Asset")
示例#7
0
    def test_4_screen_model(self):
        '''通过model筛选设备,并关闭筛选'''
        try:
            self.dr.find_element_by_css_selector(
                ReadElement.device_ele(self, "Asset下拉操作")).click()
            time.sleep(0.5)
            # self.dr.find_element_by_partial_link_text("Device").click()
            # print(self.dr.find_element_by_css_selector(ReadElement.device_ele(self, "点击device")).text)
            self.dr.find_element_by_xpath(
                ReadElement.device_ele(self, "点击device")).click()
            self.dr.implicitly_wait(15)
            self.dr.find_element_by_css_selector(
                ReadElement.device_ele(self, "下拉筛选Model")).click()
            time.sleep(1)
            self.dr.find_element_by_xpath(
                ReadElement.device_ele(self, "选择设备类型")).click()
            time.sleep(2)
            print(
                self.dr.find_element_by_css_selector(
                    ReadElement.device_ele(self, "断言设备类型")).text)
            self.assertEqual(
                self.dr.find_element_by_css_selector(
                    ReadElement.device_ele(self, "断言设备类型")).text, "TMX09")
        except:
            print(
                self.dr.find_element_by_css_selector(
                    ReadElement.device_ele(self, "断言设备类型")).text)
            function.error_png(self, 'test_3_screen_model')
            self.assertEqual(
                self.dr.find_element_by_css_selector(
                    ReadElement.device_ele(self, "断言设备类型")).text,
                ReadData.Basic_data(self, "断言设备类型"))
        try:
            self.dr.find_element_by_css_selector(
                ReadElement.device_ele(self, "再次点击筛选Model")).click()
            time.sleep(2)
            self.dr.find_element_by_css_selector(
                ReadElement.device_ele(self, "关闭筛选Model")).click()
            # self.dr.find_element_by_xpath(ReadElement.device_ele(self, "关闭筛选Model")).click()
            time.sleep(2)
            self.assertEqual(
                self.dr.find_element_by_css_selector(
                    ReadElement.device_ele(self, "下拉筛选Model")).text, "Model")
        except:

            print(
                self.dr.find_element_by_css_selector(
                    ReadElement.device_ele(self, "下拉筛选Model")).text)
            function.error_png(self, sys._getframe().f_code.co_name)
            self.assertEqual(
                self.dr.find_element_by_css_selector(
                    ReadElement.device_ele(self, "下拉筛选Model")).text, "Model")
示例#8
0
def test_case():
    global l
    case_excel = ReadData.ReadCaseExcel()
    ob = ReadData.ReadStepExcel()
    fist, end = run_list.test_case_list(case_excel.case_num)
    l = ReadData.ReadCaseExcel.result_list(fist, end)
    try:
        f = open(Path.scan_files(prefix='Test_Case'), 'w')
    except Exception as e:
        raise Custom_exception.CreatTestCaseError
    f.write('#! /usr/bin/python\n')
    f.write('# -*- coding:utf-8 -*-\n')
    f.write('import unittest\n')
    f.write('from common import log\n')
    f.write('from common import operation\n')
    f.write('from common import creat_case\n')
    f.write('# 测试用例\n')
    f.write('\n')
    f.write('\n')
    f.write('class ParametrizedTestCase(unittest.TestCase):\n')
    f.write('    """ TestCase classes that want to be parametrized should\n')
    f.write('        inherit from this class.\n')
    f.write('    """\n')
    f.write('    def __init__(self, method_name="runTest", run_time=None):\n')
    f.write(
        '        super(ParametrizedTestCase, self).__init__(method_name)\n')
    f.write('        self.method_name = method_name\n')
    f.write('\n')
    f.write('\n')
    f.write('class Test(ParametrizedTestCase):\n')
    f.write('    def setUp(self):\n')
    f.write('        self.OP = operation.Opera()\n')
    f.write('\n')
    f.write('    def tearDown(self):\n')
    f.write('        self.OP.quit()\n')
    for i in range(fist, end):
        f.write('\n')
        f.write('    @log.deco(u"%s")\n' % ob.get_case_desc(i)[1])
        f.write('    def %s(self):\n' % ob.get_case_desc(i)[2])
        f.write('        try:\n')
        for j in range(3, len(ob.get_case_desc(i))):
            # 等待
            if ob.get_case_desc(i)[j][1] == 'sleep':
                f.write('        time.sleep(%s)\n' % ob.get_case_desc(i)[j][4])
            # 切换 h5
            elif ob.get_case_desc(i)[j][1] == 'sw_h5':
                f.write('            self.OP.sw_h5()\n')
            # 切换app
            elif ob.get_case_desc(i)[j][1] == 'sw_app':
                f.write('            self.OP.sw_app()\n')
            # 输入
            elif ob.get_case_desc(i)[j][1] == 'send_keys':
                f.write('            self.OP.send_keys("%s", "%s", "%s")\n' %
                        (ob.get_case_desc(i)[j][2], ob.get_case_desc(i)[j][3],
                         ob.get_case_desc(i)[j][4]))
            # 点击
            elif ob.get_case_desc(i)[j][1] == 'clicks':
                f.write('            self.OP.clicks("%s", "%s")\n' %
                        (ob.get_case_desc(i)[j][2], ob.get_case_desc(i)[j][3]))
            # 等待
            elif ob.get_case_desc(i)[j][1] == 'wait_element':
                f.write('            self.OP.wait_element("%s", "%s")\n' %
                        (ob.get_case_desc(i)[j][2], ob.get_case_desc(i)[j][3]))
            # 物理键返回
            elif ob.get_case_desc(i)[j][1] == 'go_back':
                f.write('            self.OP.go_back()\n')
            # 向上滑动
            elif ob.get_case_desc(i)[j][1] == 'swipe_up':
                f.write('            self.OP.swipe_up()\n')
            # 向下滑动
            elif ob.get_case_desc(i)[j][1] == 'swipe_to_down':
                f.write('            self.OP.swipe_to_down()\n')
            # 向左滑动
            elif ob.get_case_desc(i)[j][1] == 'swipe_to_left':
                f.write('            self.OP.swipe_to_left()\n')
            # 向右滑动
            elif ob.get_case_desc(i)[j][1] == 'swipe_to_right':
                f.write('            self.OP.swipe_to_right()\n')
            # 判断页面内容是否存在
            elif ob.get_case_desc(i)[j][1] == 'page_element':
                f.write('            self.OP.judge_key("%s", "%s", "%s")\n' %
                        (ob.get_case_desc(i)[j][2], ob.get_case_desc(i)[j][3],
                         ob.get_case_desc(i)[j][4]))
            elif ob.get_case_desc(i)[j][1] == 'set_keys':
                f.write('            self.OP.set_keys("%s", "%s", "%s")\n' %
                        (ob.get_case_desc(i)[j][2], ob.get_case_desc(i)[j][3],
                         ob.get_case_desc(i)[j][4]))
            elif ob.get_case_desc(i)[j][1] == 'shake':
                f.write('            self.OP.shake()\n')
        f.write('        except Exception as e:\n')
        f.write(
            '            creat_case.exception_handling(e, index=%s, test_name="%s", method_name=self.method_name,'
            ' op=self.OP)' % (ob.get_case_desc(i)[0], ob.get_case_desc(i)[1]))
        f.write('\n')
    try:
        f.close()
    except Exception as e:
        logging.error(e)
        raise Custom_exception.CloseFileError