Appium Public Method Encapsulation

Source: Internet
Author: User
Tags tag name xpath appium

 

Recently in the study Appium+python write Android automated test scripts, before using Selenium+python to write web-based automated test scripts, on this basis to modify.

Or using a Pom, a page page encapsulates some public methods for a test_case,base. Encapsulates a common method for finding elements:

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 indicates that this is a tuple object.

This method is called before using the selenium to write the page to find the element, for example:

Login_username_loc = (By.xpath, ' XXX ')

el = Self.find_element (*self.login_button_loc)

Appium's Webdriver New Find element method, I want to find the element through accessibility_id, find_element_by_accessibility_id method. But there is no accessibility_id in Selenium's selenium.webdriver.common.by, as shown below, only: 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"

Looking for Webdriver found in Appium, the new Appium.webdriver.common.mobileby has a Mobileby object, which is an extension of the by object.

So you can use Mobileby to locate objects:

Login_button_loc = (mobileby.accessibility_id, ' login ')

el = Self.find_element (*self.login_button_loc)

This avoids the re-encapsulation of public methods and the ability to locate elements through previous public methods.

Appium Public Method Encapsulation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.