예제 #1
0
    def test_02_password_error(self):
        self.login.login(username=self.exl.get_cell(2, 2),
                         password=self.exl.get_cell(2, 3))

        self.assertEqual(self.exl.get_cell(2, 4),
                         self.login.login_failed_msg())
        AutoLog.set_messge("case02 complete", "info")
예제 #2
0
    def test_01_success(self):
        self.login.login(username=self.exl.get_cell(1, 2),
                         password=self.exl.get_cell(1, 3))

        self.assertEqual(self.exl.get_cell(1, 4),
                         self.login.login_success_msg())
        AutoLog.set_messge("case01 complete", "info")
예제 #3
0
 def alert_info(self):
     try:
         text = self.driver.switch_to.alert.text
         AutoLog.set_messge("Alert:{}".format(text), "info")
         return text
     except Exception as e:
         AutoLog.set_messge(e, "error")
예제 #4
0
 def quit(cls):
     try:
         time.sleep(4)
         UseBrowser.driver.quit()
         AutoLog.set_messge("quit!", "info")
     except Exception as e:
         AutoLog.set_messge(e, "error")
예제 #5
0
 def send_keys_id_js(self, name, value):
     try:
         js = "document.getElementById('{}').value='{}'".format(name, value)
         self.driver.execute_script(js)
         AutoLog.set_messge("send_js:{} 添加:{} 成功".format(name, value),
                            "info")
     except Exception as e:
         AutoLog.set_messge(e, "error")
예제 #6
0
 def swich_frame_default(self):
     try:
         time.sleep(1)
         self.driver.switch_to.default_content()
         AutoLog.set_messge("frame切换到default成功!", "info")
         time.sleep(1)
     except Exception as e:
         AutoLog.set_messge(e, "error")
예제 #7
0
 def swich_frame(self, name):
     try:
         time.sleep(1)
         self.driver.switch_to.frame(name)
         AutoLog.set_messge("frame:{} 切换成功!".format(name), "info")
         time.sleep(1)
     except Exception as e:
         AutoLog.set_messge(e, "error")
예제 #8
0
 def get_title_xpath(self):
     try:
         time.sleep(1)
         title = self.driver.title
         AutoLog.set_messge("title:{}".format(title), "info")
         return title
     except Exception as e:
         AutoLog.set_messge(e, "error")
예제 #9
0
 def select_xpath_visible_text(self, xpath, text):
     try:
         Select(self.driver.find_element_by_xpath(
             xpath)).select_by_visible_text(text)
         AutoLog.set_messge(
             "select_xpth:{} text:{} 选择成功".format(xpath, text), "info")
     except Exception as e:
         AutoLog.set_messge(e, "error")
예제 #10
0
 def get_conn(self):
     try:
         conn = pymysql.Connection(host=self.host,
                                   user=self.user,
                                   password=self.password,
                                   database=self.database,
                                   port=self.port,
                                   charset=self.charset)
         AutoLog.set_messge("database:{} 连接".format(self.database), "info")
         return conn
     except Exception as e:
         AutoLog.set_messge(e, "error")
예제 #11
0
class YamlOperation():
    def __init__(self, locator_file):
        self.log = AutoLog()
        with open(locator_file, encoding="UTF-8") as yaml_file:
            self.data = yaml.load(yaml_file, yaml.FullLoader)

    def get_locatoer(self, page, local):
        try:
            local = self.data[page][local]
            self.log.set_messge("yaml:{} 读取成功".format(local), "info")
            return local
        except Exception as e:
            self.log.set_messge(e, "error")
예제 #12
0
 def findall(self, sql):
     conn = self.get_conn()
     try:
         cur = conn.cursor(cursor=pymysql.cursors.DictCursor)
         cur.execute(sql)
         result = cur.fetchall()
         AutoLog.set_messge("sql:{} 执行".format(sql), "info")
     except Exception as e:
         AutoLog.set_messge(e, "error")
         conn.rollback()
     finally:
         cur.close()
         conn.close()
         return result
예제 #13
0
    def update(self, sql):
        conn = self.get_conn()
        try:
            # sql的执行
            cur = conn.cursor(cursor=pymysql.cursors.DictCursor)
            cur.execute(sql)
            conn.commit()
            AutoLog.set_messge("sql:{} 执行".format(sql), "info")
        except Exception as e:
            conn.rollback()
            AutoLog.set_messge(e, "error")

        finally:
            cur.close()
            conn.close()
예제 #14
0
 def click_xpath(self, xpath):
     try:
         self.driver.find_element_by_xpath(xpath).click()
         AutoLog.set_messge("xpth:{} 点击成功".format(xpath), "info")
     except Exception as e:
         AutoLog.set_messge(e, "error")
예제 #15
0
 def send_keys_xpath(self, xpath, value):
     try:
         self.driver.find_element_by_xpath(xpath).send_keys(value)
         AutoLog.set_messge("xpth:{} 添加:{} 成功".format(xpath, value), "info")
     except Exception as e:
         AutoLog.set_messge(e, "error")
예제 #16
0
 def __init__(self, dr):
     self.dr = dr
     self.log = AutoLog()
예제 #17
0
 def tearDown(self) -> None:
     self.login.ub.quit()
     AutoLog.set_messge("crm quite", "info")
예제 #18
0
 def __init__(self, locator_file):
     self.log = AutoLog()
     with open(locator_file, encoding="UTF-8") as yaml_file:
         self.data = yaml.load(yaml_file, yaml.FullLoader)
예제 #19
0
 def open_url(self, url):
     try:
         self.driver.get(url)
         AutoLog.set_messge("url:{} 打开!".format(url), "info")
     except Exception as e:
         AutoLog.set_messge(e, "error")
예제 #20
0
class AutoDef():
    def __init__(self, dr):
        self.dr = dr
        self.log = AutoLog()

    def swich_frame(self, name):
        try:
            time.sleep(1)
            self.dr.switch_to.frame(name)
            self.log.set_messge("frame:{} 切换成功!".format(name), "info")
            time.sleep(1)
        except Exception as e:
            self.log.set_messge(e, "error")

    def get_title_xpath(self):
        try:
            time.sleep(1)
            title = self.dr.title
            self.log.set_messge("title:{}".format(title), "info")
            return title
        except Exception as e:
            self.log.set_messge(e, "error")

    def swich_frame_default(self):
        try:
            time.sleep(1)
            self.dr.switch_to.default_content()
            self.log.set_messge("frame切换到default成功!", "info")
            time.sleep(1)
        except Exception as e:
            self.log.set_messge(e, "error")

    def send_keys_xpath(self, xpath, value):
        try:
            self.dr.find_element_by_xpath(xpath).send_keys(value)
            self.log.set_messge("xpth:{} 添加:{} 成功".format(xpath, value),
                                "info")
        except Exception as e:
            self.log.set_messge(e, "error")

    def send_keys_id_js(self, name, value):
        try:
            js = "document.getElementById('{}').value='{}'".format(name, value)
            self.dr.execute_script(js)
            self.log.set_messge("send_js:{} 添加:{} 成功".format(name, value),
                                "info")
        except Exception as e:
            self.log.set_messge(e, "error")

    def click_xpath(self, xpath):
        try:
            self.dr.find_element_by_xpath(xpath).click()
            self.log.set_messge("xpth:{} 点击成功".format(xpath), "info")
        except Exception as e:
            self.log.set_messge(e, "error")

    def select_xpath_visible_text(self, xpath, text):
        try:
            Select(self.dr.find_element_by_xpath(
                xpath)).select_by_visible_text(text)
            self.log.set_messge(
                "select_xpth:{} text:{} 选择成功".format(xpath, text), "info")
        except Exception as e:
            self.log.set_messge(e, "error")

    def alert_info(self):
        try:
            text = self.dr.switch_to.alert.text
            self.log.set_messge("Alert:{}".format(text), "info")
            return text
        except Exception as e:
            self.log.set_messge(e, "error")
예제 #21
0
 def test_05_username_password_null(self):
     self.login.login(username=self.exl.get_cell(5, 2),
                      password=self.exl.get_cell(5, 3))
     self.assertEqual(self.exl.get_cell(5, 4),
                      self.login.login_failed_msg())
     AutoLog.set_messge("case05 complete", "info")