예제 #1
0
 def test_001(self):
     """搜索"""
     self.search.input_search("selenium")
     self.search.click_search()
     result = re.search(r'selenium', self.search.getSource)
     log.info(result)
     assert result
예제 #2
0
 def input_text(self, locator, txt):
     """输入(输入前先清空)"""
     sleep(0.5)
     ele = self.find_element(locator)
     ele.clear()
     ele.send_keys(txt)
     log.info("输入文本:{}".format(txt))
예제 #3
0
 def Switch_iframe(self, selector):
     el = self.find_element(selector)
     try:
         self.driver.switch_to.frame(el)
         log.info("切换iframe,successfully")
     except NameError as e:
         log.info("切换iframe,fail")
예제 #4
0
 def test_003(self, drivers):
     """搜索"""
     search = SearchPage(drivers)
     search.input_srarch_str("测试")
     search.click_search()
     result = re.search(r'12213123123', search.get_source)
     log.info(result)
     assert result
예제 #5
0
 def test_001(self, drivers):
     """test"""
     search = SearchPage(drivers)
     search.input_search("selenium")
     search.click_search()
     result = re.search(r'selenium', search.get_source)
     log.info(result)
     assert result
예제 #6
0
 def test_checkpage(self, drivers):
     """搜索"""
     search = AboutPage(drivers)
     search.input_search("selenium")
     search.click_search()
     result = re.search(r'selenium', search.get_source)
     log.info(result)
     assert result
예제 #7
0
 def get_url(self, url):
     # self.driver.maximize_window()
     self.driver.set_page_load_timeout(60)
     try:
         self.driver.get(url)
         self.driver.implicitly_wait(10)
         log.info("打开网页:%s" % url)
     except TimeoutException:
         raise TimeoutException("打开%s超时,请检查网络或网络服务器" % url)
예제 #8
0
 def input_text_slow(self, locator, txt):
     """输入(输入前先清空)"""
     sleep(1)
     ele = self.find_element(locator)
     ele.clear()
     for i in list(txt):
         ele.send_keys(i)
         sleep(1)
     log.info("输入文本:{}".format(txt))
예제 #9
0
 def exec(self, sql):
     try:
         log.debug(sql)
         self.cure.execute(sql)
         self.conn.commit()
     except Exception as e:
         log.info("回滚")
         self.conn.rollback()
         print(str(e))
예제 #10
0
 def do_click(self, locator,by='xpath',num=0):
     """点击
        @locator 元素定位字符
        @by 定位方法可选格式 xpath/css/class/id/name
        @num 选择第几个元素进行点击
     """
     self.find_elements_test(locator,by)[num].click()
     # wait()
     log.info("点击元素:{}".format(locator))
예제 #11
0
파일: webpage.py 프로젝트: wxhou/web-zentao
 def alert_exists(self):
     """判断弹框是否出现,并返回弹框的文字"""
     alert = EC.alert_is_present()(self.driver)
     if alert:
         text = alert.text
         log.info("Alert弹窗提示为:%s" % text)
         alert.accept()
         return text
     else:
         log.info("没有Alert弹窗提示!")
예제 #12
0
    def test_login(self, drivers):
        """登录"""
        search = SearchPage(drivers)

        search.input_search("admin")
        search.input_pass("admin")

        search.input_code("123")
        result = re.search(r'项目管理', search.get_source)
        log.info(result)
        assert result
예제 #13
0
 def scroll_bar(self, locator):
     js = "return document.body.scrollHeight"
     # 获取滚动条的高度
     new_height = self.driver.execute_script(js)
     for i in range(0, new_height, 100):
         try:
             self.is_click(locator, timeout=3)
             return True
         except Exception as e:
             log.info('未找到该元素,继续滑动', e)
             self.driver.execute_script('window.scrollTo(0, %s)' % i)
             continue
예제 #14
0
 def input_text(self, txt, locator,by='xpath',nedclear=True,num=0):
     """输入文本
        @txt 输入文本
        @locator 元素定位字符
        @by 定位方法可选格式 xpath/css/class/id/name
        @nedclear 输入前是否需要清空
        @num 选择第几个元素进行点击
     """
     
     ele = self.find_elements_test(locator,by)[num]
     sleep()
     if nedclear:
         ele.clear()
     ele.send_keys(txt)
     log.info("输入文本:{}".format(txt))
예제 #15
0
 def is_click(self, locator, timeout=time):
     """点击"""
     self.find_element(locator, timeout).click()
     sleep(1)
     log.info("点击元素:{}".format(locator))
예제 #16
0
 def element_text(self, locator):
     """获取当前的text"""
     _text = self.find_element(locator).text
     log.info("获取文本:{}".format(_text))
     return _text
예제 #17
0
 def is_click(self, locator):
     """点击"""
     self.find_element(locator).click()
     sleep()
     log.info("点击元素:{}".format(locator))
예제 #18
0
 def elements_num(self, locator):
     """获取相同元素的个数"""
     number = len(self.find_elements(locator))
     log.info("相同元素:{}".format((locator, number)))
     return number
예제 #19
0
 def test_002(self, drivers):
     """test2"""
     search = SearchPage(drivers)
     search.input_search("selenium")
     log.info(list(search.imagine))
     assert all(["selenium" in i for i in search.imagine])
예제 #20
0
 def input_text(self, locator, txt):
     """在指定元素处输入字符串"""
     el = self.find_element(locator)
     el.clear()
     el.send_keys(txt)
     log.info("输入文本:{}".format(txt))
예제 #21
0
 def element_text(self, locator,by='xpath'):
     """获取当前元素的text"""
     
     _text = self.find_element_test(locator,by).text
     log.info("获取文本:{}".format(_text))
     return _text
예제 #22
0
 def click_action(self, locator):
     """点击元素"""
     self.find_element(locator).click()
     sleep(0.5)
     log.info("点击元素:{}".format(locator))
예제 #23
0
 def get_element_text(self, locator):
     """获取当前的text"""
     ele_text = self.find_one_element(locator).text
     log.info("获取文本:{}".format(ele_text))
     return ele_text
예제 #24
0
 def test_002(self):
     """测试搜索候选"""
     self.search.input_search("selenium")
     log.info(list(self.search.imagine))
     assert all(["selenium" in i for i in self.search.imagine])
예제 #25
0
 def query(self, sql):
     log.info(sql)
     self.cure.execute(sql)
     return self.cure.fetchall()