Appium+python automated 49-YAML Management positioning elements

Source: Internet
Author: User
Tags button type xpath appium

How to effectively manage the positioning elements, this is a very learned question, but also the interview must ask [the following is purely personal point of view, do not spray! ].

    • Some people use the XML Management page to locate elements, this is slightly higher, but the small part thinks that the study cost is big, thief trouble.
    • Some people refer to the use of Excel to manage the page positioning elements, this slightly force lattice, at least do the data separation, but reading Excel is too slow, not efficient, but also in Excel maintenance, the trouble.
    • Some people say that the positioning of the elements of the database management, in addition to the installation force, do not feel how efficient, of course, a small partner mentioned the interface test data is relatively large, this method can also.
    • Some people use PageObject mode, directly in the page class write positioning method, although this does not directly to the positioning independent out, but this is very intuitive, but also easy to read

So is there a way, both efficient, intuitive, convenient, and can be loaded, but also to cater to the interviewer taste it? The next step is to talk about this Yaml file management
I don't know about yaml. This Python note I sent earlier 14-read the YAML configuration file

Environment:
Python 3.6
Appium 1.8
American Group App
YAML Package Installation: Pip Install Pyyaml

PageObject

1. First review the PageObject pattern positioning elements, such as:

 class   homepage:  "  dec: Home   " #   name: City selection  city_loc = ( " /span>id   ",  " com.sankuai.meituan:id/city_button   " )  #   name: Home search  Home_loc = ( " id  " ,  " com.sankuai.meituan: Id/search_edit  ) 
YAML Management Targeting

1. Put the positioning method in the Yaml file management, the U.S. Group app home page elements are located as follows:

homepage:  Dec: Home    Locators:      -        name: City Select        type:id        Value:com.sankuai.meituan: ID/city_button      -         Name: Home Search         type:id         value:com.sankuai.meituan:id/ Search_edit

2.app on [My] menu page positioning

mypage:  Dec: My  Locators:      -        name: My        type:accessibility_id        value: My-                Name: Please click to login         type:id         value:com.sankuai.meituan:id/user_name

3. Login Page locator, here I merge several process pages that have been logged in

---Loginpage:dec: Login Page Locators:-Name: Login Type:id value:com.sankuai.meituan:id/Passport_button_wechat-Name: Mobile phone number login Type:id value:com.sankuai.meituan:id/Passport_button_meituan-Name: Other login type:id value:com.sankuai.meituan:id/Passport_button_other-name:qq Type:xpath Value:*[@text ='QQ']      -Name: Weibo type:xpath value:*[@text ='Micro Blog']      -Name: Account password Type:xpath value:*[@text ='account Password']      -Name: Enter account Type:id Value:com.sankuai.meituan:id/Edit_account-Name: Enter password type:id value:com.sankuai.meituan:id/Edit_password-Name: Login button Type:id value:com.sankuai.meituan:id/login_button
Traversal read Os.walk ()

1. Place the elements of different pages into the corresponding page. yaml files, placed in the same directory, convenient one-time traversal read

    • In the page total directory, build a pageelement folder (here is the folder, there is no __init__.py file), inside the positioning of the page elements, different pages define different Namepage.yaml.
    • Templetpage put a template that automatically generates a use case (this template is a file with no suffix) and then
    • tools.py automatically generate pages.py scripts after running code
    • pages.py running tools inside the code generated after the

2.os.walk () traversal read file, preceded by an article devoted to Python Note 4-Traverse folder directory Os.walk ()

#Coding:utf-8ImportYamlImportOS#Current Script PathBasePath = Os.path.dirname (Os.path.realpath (__file__))#Yaml folderYamlpagespath = Os.path.join (BasePath,"pageelement")defParseyaml ():" "traversal read Yaml file" "pageelements= {}    #traversal read Yaml file     forFpath, DirName, FnamesinchOs.walk (yamlpagespath): forNameinchFnames:#yaml file Absolute pathYaml_file_path =Os.path.join (Fpath, name)#exclude some files that are not. Yaml            if ". Yaml" inchStr (yaml_file_path): With open (Yaml_file_path,'R', encoding='Utf-8') as F:page=yaml.load (f) pageelements.update (page)returnpageelementsif __name__=="__main__": A=Parseyaml ()Print(a) forIincha["Homepage"]['Locators']:        Print(i)

Operation Result:

Next article on the Templetpage template to automatically generate PageObject mode code (code to write code)

Appium+python automated 49-YAML Management positioning elements

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.