Esempio n. 1
0
    def assert_element_not_exists(self,
                                  element,
                                  describe,
                                  sleep=0,
                                  timeout=10):
        """
        Asserts that the text exists on the current page

        Args:
            sleep(int): sleep time
            element: element
            describe(str): Assertion description information
            timeout(int): Maximum waiting time
        """
        time.sleep(sleep)
        logging.info("预期结果: " + describe + " 元素不存在")
        for i in range(timeout):
            element_exists = element.exists()
            if element_exists is True:
                insert_assert(describe, False)
                logging.warn("实际结果: " + describe + " 元素存在")
                break
            else:
                time.sleep(1)
                continue
        else:
            insert_assert(describe, True)
            logging.info("实际结果: " + describe + " 元素不存在")
        self.screenshots(describe="断言")
Esempio n. 2
0
    def __find_element(self, elem):
        """
        Find if the element exists.
        """
        for i in range(self.timeout):
            try:
                elems = self.__elements(elem[0], elem[1])
            except FunctionTimedOut:
                elems = []

            if len(elems) == 1:
                logging.info("✅ Find element: {by}={value} ".format(
                    by=elem[0], value=elem[1]))
                break
            elif len(elems) > 1:
                logging.info(
                    "❓ Find {n} elements through: {by}={value}".format(
                        n=len(elems), by=elem[0], value=elem[1]))
                break
            else:
                sleep(1)
        else:
            error_msg = "❌ Find 0 elements through: {by}={value}".format(
                by=elem[0], value=elem[1])
            logging.error(error_msg)
            raise NoSuchElementException(error_msg)
Esempio n. 3
0
    def assert_text_not_exists(self, text: str, describe, sleep=0, timeout=10):
        """
        Asserts that the text exists on the current page

        Args:
            sleep(int): sleep time
            text(str): text
            describe(str): Assertion description information
            timeout(int): Maximum waiting time
        """
        time.sleep(sleep)
        logging.info("预期结果: " + describe + " 文案不存在")
        for i in range(timeout):
            text_exists = self.driver(text=text).exists
            if text_exists is True:
                insert_assert(describe, False)
                logging.warn("实际结果: " + describe + " 文案存在")
                break
            else:
                time.sleep(1)
                continue
        else:
            insert_assert(describe, True)
            logging.info("实际结果: " + describe + " 文案不存在")
        self.screenshots(describe="断言")
Esempio n. 4
0
 def send_keys(self, value):
     """
     Simulates typing into the element.
     """
     elem = self.__get_element(self.k, self.v)
     logging.info("🖋 input element: {}".format(self.desc))
     elem.send_keys(value)
Esempio n. 5
0
def connect():
    """
    链接iOS设备
    """
    driver = wda.Client(Setting.device_id)
    logging.info("📱📱📱 info ===> {}!".format(driver.status()))

    return driver
Esempio n. 6
0
 def find(self, context):
     for i in range(1, self.time_out):
         if self.log is True:
             logging.info("{desc}, {n} times search, {elm} ".format(desc=self.describe, n=i, elm=self.locator))
         if self.get_element(context) is not None:
             return self.get_element(context)
     else:
         return self.get_element(context)
Esempio n. 7
0
 def value(self) -> str:
     """
     JavaScript API
     Gets the value of the element.
     """
     logging.info(f"get element value. {self.desc}")
     js = f"""return document.querySelectorAll("{self.css}")[{self.index}].value;"""
     return self._execute_javascript(js)
Esempio n. 8
0
 def find(self, context):
     try:
         elems = context.find_elements(*self.locator)
     except NoSuchElementException:
         elems = []
     logging.info("✨ Find {n} elements through: {by}={value}, describe:{desc}".format(
         n=len(elems), by=self.k, value=self.v, desc=self.describe))
     return elems
Esempio n. 9
0
 def click_display(self) -> None:
     """
     JavaScript API
     Click on the displayed element, otherwise skip it.
     """
     logging.info(f"Click on the displayed element. {self.desc}")
     js = 'var elm = document.querySelector("' + self.css + '");' \
          ' if(elm != null){elm.style.border="2px solid red";elm.click();}'
     self._execute_javascript(js)
Esempio n. 10
0
 def move_to(self) -> None:
     """
     JavaScript API
     Move the mouse over the element
     """
     logging.info(f"Move the mouse over the element. {self.desc}")
     js = f"""var elm = document.querySelectorAll("{self.css}")[{self.index}];
                 elm.dispatchEvent(new Event("mouseover"));"""
     self._execute_javascript(js)
Esempio n. 11
0
 def display(self) -> None:
     """
     JavaScript API
     Display hidden elements
     """
     logging.info(f"display hidden element. {self.desc}")
     js = f"""var elm = document.querySelectorAll("{self.css}")[{self.index}];
                 elm.style.display = "block";"""
     self._execute_javascript(js)
Esempio n. 12
0
 def clear_class(self) -> None:
     """
     JavaScript API
     Clear element class
     """
     logging.info(f"clear element class. {self.desc}")
     js = f"""var elm = document.querySelectorAll("{self.css}")[{self.index}];
                  elm.removeAttribute("class");"""
     self._execute_javascript(js)
Esempio n. 13
0
 def clear_style(self) -> None:
     """
     JavaScript API
     Clear element styles.
     """
     logging.info(f"clear element styles. {self.desc}")
     js = f"""var elm = document.querySelectorAll("{self.css}")[{self.index}];
                 elm.style="";"""
     self._execute_javascript(js)
Esempio n. 14
0
 def click_parent(self) -> None:
     """
     JavaScript API
     Click the parent element of the element
     """
     logging.info(f"click the parent element of the element. {self.desc}")
     js = f"""var elm = document.querySelectorAll("{self.css}")[{self.index}];
                 elm.parentElement.click();"""
     self._execute_javascript(js)
Esempio n. 15
0
 def click_display(self):
     """
     JavaScript API, Only support css positioning
     Click on the displayed element, otherwise skip it.
     """
     logging.info(
         "Element of the current operation: {desc}".format(desc=self.desc))
     js = 'var elm = document.querySelector("' + self.css + '");' \
          ' if(elm != null){elm.style.border="2px solid red";elm.click();}'
     self._execute_javascript(js)
Esempio n. 16
0
 def remove_child(self, child: int = 0) -> None:
     """
     JavaScript API
     Remove a node from the child node list
     :param child: child of the child node
     """
     logging.info(f"Remove a node from the child node list. {self.desc}")
     js = f"""var elm = document.querySelectorAll("{self.css}")[{self.index}];
                 elm.removeChild(elm.childNodes[{child}]);"""
     self._execute_javascript(js)
Esempio n. 17
0
 def inner_text(self, text) -> None:
     """
     JavaScript API
     The innerText property sets the text content of the specified element, Only support css positioning
     :param text: Inserted text
     """
     logging.info(f"inner text. {self.desc}")
     js = f"""var elm = document.querySelectorAll("{self.css}")[{self.index}];
                  elm.innerText="{text}";"""
     self._execute_javascript(js)
Esempio n. 18
0
 def remove_attribute(self, attribute) -> None:
     """
     JavaScript API
     Remove element attribute
     :param attribute:
     """
     logging.info(f"remove element attribute. {self.desc}")
     js = f"""var elm = document.querySelectorAll("{self.css}")[{self.index}];
                 elm.removeAttribute("{attribute}");"""
     self._execute_javascript(js)
Esempio n. 19
0
 def send_keys(self, value, clear_before=False):
     """
     Simulates typing into the element.
     If clear_before is True, it will clear the content before typing.
     """
     elem = self.__get_element(self.k, self.v)
     logging.info("🖋 input element: {}".format(self.desc))
     if clear_before:
         elem.clear()
     elem.send_keys(value)
Esempio n. 20
0
 def click(self) -> None:
     """
     JavaScript API
     Click element.
     """
     logging.info(f"click element. {self.desc}")
     js = f"""var elm = document.querySelectorAll("{self.css}")[{self.index}];
                elm.style.border="2px solid red";
                elm.click();"""
     self._execute_javascript(js)
Esempio n. 21
0
 def clear(self) -> None:
     """
     JavaScript API
     Clears the text if it's a text entry element, Only support css positioning
     """
     logging.info(f"Clear input field. {self.desc}")
     js = f"""var elm = document.querySelectorAll("{self.css}")[{self.index}];
                 elm.style.border="2px solid red";
                 elm.value = "";"""
     self._execute_javascript(js)
Esempio n. 22
0
    def set_text(self, text):
        """
        input text
        :param text:
        """
        global driver

        print("\n")
        logging.info(msg=" 键盘输入 ==> " + text)
        driver(**self.kwargs).set_text(text=text)
Esempio n. 23
0
 def clear_style(self):
     """
     JavaScript API, Only support css positioning
     Clear element styles.
     """
     logging.info(
         "Element of the current operation: {desc}".format(desc=self.desc))
     js = """var elm = document.querySelectorAll("{css}")[{index}];
                 elm.style="";""".format(css=self.css, index=self.index)
     self._execute_javascript(js)
Esempio n. 24
0
 def click(self):
     """
     JavaScript API, Only support css positioning
     Click element.
     """
     logging.info(
         "Element of the current operation: {desc}".format(desc=self.desc))
     js = """var elm = document.querySelectorAll("{css}")[{index}];
                elm.style.border="2px solid red";
                elm.click();""".format(css=self.css, index=self.index)
     self._execute_javascript(js)
Esempio n. 25
0
 def display(self):
     """
     JavaScript API, Only support css positioning
     Display hidden elements
     """
     logging.info(
         "Element of the current operation: {desc}".format(desc=self.desc))
     js = """var elm = document.querySelectorAll("{css}")[{index}];
                 elm.style.display = "block";""".format(css=self.css,
                                                        index=self.index)
     self._execute_javascript(js)
Esempio n. 26
0
 def set_text(self, text):
     """
     输入文本内容
     Args:
         text(str): 输入栏输入的文本
     """
     global driver
     text = str(text)
     self.clear_text()
     logging.info(msg=" 键盘输入 ==> " + text)
     driver(**self.kwargs).set_text(text)
Esempio n. 27
0
 def click_parent(self):
     """
     JavaScript API, Only support css positioning
     Click the parent element of the element
     """
     logging.info(
         "Element of the current operation: {desc}".format(desc=self.desc))
     js = """var elm = document.querySelectorAll("{css}")[{i}];
                 elm.parentElement.click();""".format(css=self.css,
                                                      i=self.index)
     self._execute_javascript(js)
Esempio n. 28
0
 def move_to(self):
     """
     JavaScript API, Only support css positioning
     Move the mouse over the element
     """
     logging.info(
         "Element of the current operation: {desc}".format(desc=self.desc))
     js = """var elm = document.querySelectorAll("{css}")[{i}];
                 elm.dispatchEvent(new Event("mouseover"));""".format(
         css=self.css, i=self.index)
     self._execute_javascript(js)
Esempio n. 29
0
 def clear_class(self):
     """
     JavaScript API, Only support css positioning
     Clear element class
     """
     logging.info(
         "Element of the current operation: {desc}".format(desc=self.desc))
     js = """var elm = document.querySelectorAll("{css}")[{index}];
                  elm.removeAttribute("class");""".format(css=self.css,
                                                          index=self.index)
     driver.execute_script(js)
Esempio n. 30
0
 def set_text(self, value: str) -> None:
     """
     JavaScript API
     Simulates typing into the element.
     :param value: input text
     """
     logging.info(f"set text. {self.desc}")
     js = f"""var elm = document.querySelectorAll("{self.css}")[{self.index}];
                 elm.style.border="2px solid red";
                 elm.value = "{value}";"""
     self._execute_javascript(js)