Exemplo n.º 1
0
 def delete(self, key):
     '''通过关键字进行删除'''
     n = self.get_rows_by_key(key)
     self.click("xpath=>//*[@id='rowcount" + str(n) + "']/td[9]/a[3]")
     self.switch_alert_accept()
     log.info(u' name 为[%s]的设备信息已被删除!>>>' % key)
     self.switch_current_frame()
Exemplo n.º 2
0
 def get_col_info(self, key):
     df = self.df
     try:
         log.info('【%s】列信息显示如下:\n%s' % (key, df[key]))
     except KeyError:
         log.error('【%s】不是列名,请重新查看' % key)
     return df[key]
Exemplo n.º 3
0
 def click(self, selector):
     s =self.presence_of_element_located(selector)
     try:
         s.click ()
         log.info ("The element was clicked." )
     except NameError as e:
         log.error ("Failed to click the element with %s" % e)
Exemplo n.º 4
0
 def get_text(self, selector):
     if self.find_element (selector).text:
         text = self.find_element (selector).text
     else:
         text = self.find_element (selector).get_attribute ('value')
     log.info ("get the element and iteself text:%s" % text)
     return text
Exemplo n.º 5
0
 def test_add(self):
     '''添加卡口设备'''
     self.s.selecting_road()  #默认第三个道路信息
     num0 = int(self.s.get_counts())
     self.s.adding()
     self.s.adds_org()
     self.s.adds_type('闯红灯')
     self.s.type_name('测试设备名称')
     self.s.type_brand('大华')
     self.s.adds_dev_func(['卡口检测', '单点超速'])
     self.s.type_pattern(sj())
     self.s.go_env_setting()
     self.s.type_ip(sjip())
     self.s.type_timeout(60)
     # self.s.select_server()
     time.sleep(1)
     self.s.go_direction()
     self.s.car_direction()
     self.s.car_road('2')
     time.sleep(1)
     self.s.go_build_info()
     self.s.select_factory('西安翔迅')
     self.s.saving()
     num1 = int(self.s.get_counts())
     assert num0 + 1 == num1
     self.assertEqual(num0 + 1, num1)
     log.info('successfully added!设备添加成功!')
Exemplo n.º 6
0
 def clear_text(self, selector):
     el = self.presence_of_element_located(selector)
     try:
         el.clear ()
         log.info ("Clear text in input box before typing.")
     except NameError as e:
         log.error ("Failed to clear in input box with %s" % e)
         self.get_windows_img ()
Exemplo n.º 7
0
 def save(self, df):
     book = load_workbook(self.path)
     writer = pd.ExcelWriter(self.path, engine='openpyxl')
     writer.book = book
     writer.sheets = dict((ws.title, ws) for ws in book.worksheets)
     df.to_excel(writer, self.sheetname, index=False)
     writer.save()
     log.info('保存成功!')
Exemplo n.º 8
0
 def get_selector(self, key):
     df = self.df
     row_info = self.get_row_info(key)
     by = row_info['by']
     bystyle = row_info['by_style']
     xpath = by + '=>' + bystyle
     log.info('【%s】元素的selector信息显示如下:\n%s' % (key, xpath))
     return xpath[0]
Exemplo n.º 9
0
 def enter_key(self, selector):
     e1 = self.find_element (selector)
     try:
         e1.send_keys (Keys.ENTER)
         log.info ("Had touch the Enter keys .")
     except Exception as e:
         log.error ("Failed to touch any keys")
         self.get_windows_img ()
Exemplo n.º 10
0
 def test_search(self):
     '''查询卡口设备'''
     key = '测试设备名称'
     self.s.stype_device_name(key)
     self.s.searching()
     list = self.s.namelist()
     self.assertNotEqual(len([s for s in list if key in s]), 0)
     log.info('查询设备【%s】,确已存在!' % key)
Exemplo n.º 11
0
 def test_xdelete(self):
     '''删除卡口设备'''
     key = '修改后的'
     self.s.stype_device_name(key)
     self.s.searching()
     self.s.delete(key)
     if self.s.get_counts_key(key) == 0:
         log.info('设备名称为【%s】,现在已正确删除!' % key)
Exemplo n.º 12
0
 def adds_type(self, text):
     if text in self.type_dic:
         self.click(self.add_dev_type)
         num = self.type_dic.index(text) + 1
         type = 'xpath=>.//*[@id="dropdown-ul"]/li[%s]' % num
         self.click(type)
         log.info('Enter device type :%s for searching.' % text)
     else:
         log.info('device type has no such items:%s  .' % text)
Exemplo n.º 13
0
 def stype_device_type(self, text):
     '''查询输入'''
     self.switch_frame('content-frame')
     if text in self.type_dic:
         self.select(self.dev_type, text)
         log.info('Enter device type :%s for searching.' % text)
     else:
         log.info('device type has no such items:%s  .' % text)
     self.switch_current_frame()
Exemplo n.º 14
0
 def switch_window(self, to_handle):
     now_handle = self.get_current_window_handle
     old_handle = to_handle
     handles = self.driver.window_handles
     log.info ("current handles number is:%s" % len (handles))
     for handle in handles:
         if handle != now_handle:
             log.info ('now to switch another window:%s' % handle)
             self.driver.close ()  # 关闭当前焦点所在的窗口
             self.driver.switch_to.window (to_handle)  # 切换到第二个窗口
Exemplo n.º 15
0
 def get_col_index(self, key):
     column = [
         list(df.columns).index(v) for v in list(df.columns) if key in v
     ]
     try:
         print(column)
         print('根据key【%s】获取列号为:%s' % (key, column[0]))
     except Exception as e:
         log.error('列中无该值存在!%s' % e)
     return column[0]
Exemplo n.º 16
0
 def test_check(self):
     '''查看卡口设备'''
     key = '测试设备名称'
     self.s.stype_device_name(key)
     self.s.searching()
     num = self.s.get_counts()
     self.s.view(key)
     name = self.s.get_view_name()
     self.assertEqual(name, key)
     log.info('name 为【%s】的卡口设备信息查看successfullly!<<<' % key)
Exemplo n.º 17
0
 def set_value(self, element, col_value, value):
     df = self.df
     row = self.get_row_index(element)
     print(row)
     col = int(self.get_col_index(col_value))
     log.info('【%s】的[%s]属性从【%s】改为[%s]' %
              (element, col_value, df.iloc[row, col], value))
     df.iloc[row:row + 1, col:col + 1] = value
     print(df.iloc[row:row + 1, col:col + 1])
     # df.iloc[row]['by_style'] = 'username'
     self.save(df)
Exemplo n.º 18
0
 def get_row_index(self, key):
     row = [
         i for i in range(len(list(df.values))) for v in list(df.values)[i]
         if key in str(v)
     ]
     try:
         print(row)
         print('根据key【%s】获取行号为:%s' % (key, row[0]))
     except Exception as e:
         log.error('行中无该值存在!')
     return row[0]
Exemplo n.º 19
0
 def page_messages(self):
     self.get_text(self.delete_dev)
     current_page_num = self.get_text(self.current_page)
     allpages = self.get_text(self.pages)
     numbers = self.get_text(self.numbers)
     page_number = self.get_text(
         self.page_number).split('条')[0].split('页')[-1]
     log.info(
         'current_page_num, allpages, numbers, page_number' +
         current_page_num, allpages, numbers, page_number)
     return current_page_num, allpages, numbers, page_number
Exemplo n.º 20
0
 def adds_dev_func(self, list1):
     time.sleep(1)
     dic = [v for k, v in self.func_dict.items()]
     num = [dic.index(m) + 2 for m in dic for n in list1 if n == m]
     # print (dic, num[0])
     self.click(self.deviceTypeNames)
     time.sleep(1)
     for i in range(len(num)):
         path = 'xpath=>//*[@id="dtTreeSpace_%s_span"]' % num[i]
         self.click(path)
         log.info('dev_function %s has been selected.' % list1[i])
Exemplo n.º 21
0
 def get_windows_img(self):
     """
     在这里我们把file_path这个参数写死,直接保存到我们项目根目录的一个文件夹.\Screenshots下
     """
     file_path = os.path.dirname (os.path.dirname (__file__)) + '/screenshots/'
     rq = time.strftime ('%Y%m%d%H%M', time.localtime (time.time ()))
     screen_name = file_path + rq + '.png'
     try:
         self.driver.get_screenshot_as_file (screen_name)
         log.info ("Had take screenshot and save to folder : /screenshots")
     except NameError as e:
         log.error ("Failed to take screenshot! %s" % e)
         self.get_windows_img ()
Exemplo n.º 22
0
 def get_element_row_num(self, key):
     df = self.df
     key_pattern = r'^%s$' % key
     row = []
     try:
         column = [i for i in df.columns if '页面元素' in i][0]
         row = [
             k for k, v in df[column].items() if re.findall(key_pattern, v)
         ][0]
         log.info('第【%s】行' % row)
     except IndexError:
         log.error('错误,该行不存在,%s' % df.columns)
     return row
Exemplo n.º 23
0
 def test_update(self):
     '''修改卡口设备'''
     key = '测试设备名称'
     key2 = '修改后的'
     self.s.stype_device_name(key)
     self.s.searching()
     self.s.update(key)
     self.s.type_update_name(key2)
     self.s.saving()
     # 测试是否修改
     # if self.s.compareUpdate(key,key2):
     #     log.info ('修改设备【%s】,现在已正确修改!' % key)
     if self.s.get_counts_key(key2) == 1:
         log.info('设备名称【%s】修改为【%s】,现在已正确修改!' % (key, key2))
Exemplo n.º 24
0
def creatsuitel():
    testunit = unittest.TestSuite()
    #discover 方法定义
    discover = unittest.defaultTestLoader.discover(path,
                                                   pattern='*.py',
                                                   top_level_dir=path)
    #discover 方法筛选出来的用例,循环添加到测试套件中
    for test_suite in discover:
        for test_case in test_suite:
            testunit.addTests(test_case)
    log.info('discover:======> %s' % discover._tests)
    log.info('testunit:======> %s' % testunit)

    return testunit
Exemplo n.º 25
0
 def find_elements(self, selector):
     global elements
     if '=>' not in selector:
         return self.driver.find_elements_by_id(selector)
     selector_by = selector.split('=>')[0]
     selector_value = selector.split('=>')[1]
     if selector_by == "i" or selector_by == 'id':
         try:
             elements = self.driver.find_elements_by_id(selector_value)
             s = element.tag_name
             log.info("Had find the elements %s successful "
                      "by %s via value: %s " %
                      (s, selector_by, selector_value))
         except NoSuchElementException as e:
             log.error("NoSuchElementException: %s" % e)
             self.get_windows_img()
     elif selector_by == "n" or selector_by == 'name':
         elements = self.driver.find_elements_by_name(selector_value)
     elif selector_by == "c" or selector_by == 'class_name':
         elements = self.driver.find_elements_by_class_name(selector_value)
     elif selector_by == "l" or selector_by == 'link_text':
         elements = self.driver.find_elements_by_link_text(selector_value)
     elif selector_by == "p" or selector_by == 'partial_link_text':
         elements = self.driver.find_elements_by_partial_link_text(
             selector_value)
     elif selector_by == "t" or selector_by == 'tag_name':
         elements = self.driver.find_elements_by_tag_name(selector_value)
     elif selector_by == "x" or selector_by == 'xpath':
         try:
             elements = self.driver.find_elements_by_xpath(selector_value)
             s = [
                 kname.text for kname in self.driver.find_elements_by_xpath(
                     selector_value)
             ]
             log.info("Had find the elements [ %s ] successful "
                      "by %s via value: %s " %
                      (s, selector_by, selector_value))
         except NoSuchElementException as e1:
             log.error("NoSuchElementException: %s" % e1)
             self.get_windows_img()
     elif selector_by == "c" or selector_by == 'css':
         elements = self.driver.find_elements_by_css_selector(
             selector_value)
     else:
         raise NameError("Please enter a valid type of targeting elements.")
     return elements
Exemplo n.º 26
0
 def get_sheet(self):
     try:
         if not isinstance(self.sheet_str, str):
             log.error('s_name为字符串,不能为其他信息')
         self.sheetname = [
             s for s in self.workbook.sheet_names() if self.sheet_str in s
         ][0]
         log.info('现在读取的是%s中的%s【sheet】' % (self.path, self.sheetname))
     except Exception as e:
         log.error('s_name[%s]错误或者不存在!!!%s' % (self.sheet_str, e))
     return self.sheetname
Exemplo n.º 27
0
 def type(self, selector, text):
     e1 = self.presence_of_element_located(selector)
     e1.clear ()
     if e1.text:
         text1 = e1.text
     else:
         text1 = e1.get_attribute ('value')
     try:
         e1.send_keys (text)
         log.info ("Had type  [ %s ] in inputBox" % text)
     except NameError as e:
         log.error ("Failed to type in input box with %s" % text1)
         log.error ("Failed  %s" % e)
         self.get_windows_img ()
Exemplo n.º 28
0
 def close(self):
     try:
         self.driver.close ()
         log.info ("Closing and quit the browser.")
     except NameError as e:
         log.error ("Failed to quit the browser with %s" % e)
Exemplo n.º 29
0
 def wait(self, seconds):
     self.driver.implicitly_wait (seconds)
     log.info ("wait for %d seconds." % seconds)
Exemplo n.º 30
0
 def back(self):
     self.driver.back ()
     log.info ("Click back on current page.")