Appium公用方法封裝

來源:互聯網
上載者:User

標籤:python   使用   tis   自動   頁面   user   調用   csdn   partial   

 

     最近在研究Appium+python寫Android自動化測試指令碼,之前用過selenium+python寫web的自動化測試指令碼,在此基礎上修改。

      還是使用POM,一個page頁面對應一個test_case,base頁面封裝一些公用方法。封裝的一個尋找元素的公用方法:

    def find_element(self, *loc):
        try:
            WebDriverWait(self.driver,10,0.5).until(EC.visibility_of_element_located(loc))
            return self.driver.find_element(*loc)
        except AssertionError as e:
            self.driver.close()

   *loc表示這是一個元組對象。

   之前使用selenium寫page頁面調用該方法尋找元素,例如:

   login_username_loc = (By.XPATH, ‘XXX‘)

   el = self.find_element(*self.login_button_loc)

    Appium的webdriver中新增了一些尋找元素方法,我要通過accessibility_id尋找元素,find_element_by_accessibility_id方法。但是selenium的selenium.webdriver.common.by中沒有accessibility_id,如下所示,只有:ID、XPATH、LINK_TEXT、PARTIAL_LINK_TEXT、NAME、TAG_NAME、CLASS_NAME、CSS_SELECTOR。

     class By(object):
    """
    Set of supported locator strategies.
    """

    ID = "id"
    XPATH = "xpath"
    LINK_TEXT = "link text"
    PARTIAL_LINK_TEXT = "partial link text"
    NAME = "name"
    TAG_NAME = "tag name"
    CLASS_NAME = "class name"
    CSS_SELECTOR = "css selector"

    尋找appium中的webdriver發現,新增的appium.webdriver.common.mobileby有個MobileBy對象,這是對by對象的一個擴充。

     所以可以通過MobileBy來定位對象:

    login_button_loc = (MobileBy.ACCESSIBILITY_ID, ‘登入‘)

    el = self.find_element(*self.login_button_loc)

    這樣就避免了重新封裝公用方法,還可以通過之前的公用方法來定位元素。

Appium公用方法封裝

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.