1 Introduction
Today, we continue to share Appium immediately on a comprehensive framework for automated testing practices - code. Because of the time, the macro brother here with a small partner to demonstrate the code of two modules: Registration and login.
2. The service module package
Because now the various layers of the APP group are not, it varied. But most have registered, login. In order not to make the junior partner in the entry of the card, so the macro brother here is just give you a sample, the saying goes: a master-door self-cultivation by individuals. The rest rely on themselves to achieve their shoes and learn
2.1 login page business logic module
Ideas:
1, a view of the package of the first class definitions login
2, then the input box inherited public class positioning method, positioning account and password
3, in the class definition of the method of log APP
4, in the class, method defined login account checks APP
5, in the class, method defined inspection log APP login state
2.1.1loginView.py
2.1.2 Reference Code
# Coding. 8 = UTF- # 1. First set the encoding, utf-8 may support in English, as described above, generally on the first line # 2. Note: a creation time recording, created, the project name. '' ' The Created ON 2019-11-18 @author: Beijing - Hong brother QQ exchange group: 707 699 217 Project: Appium automated testing framework integrated practice - code for ' '' # 3. Import Module Import logging from kyb_testProject.common.common_fun Import the Common, NoSuchElementException from kyb_testProject.common.desired_caps Import appium_desired from selenium.webdriver.common.by Import By class the LoginView (the Common): username_type = (By.ID, 'com.tal.kaoyan:id/login_email_edittext') password_type=(By.ID,'com.tal.kaoyan:id/login_password_edittext') loginBtn=(By.ID,'com.tal.kaoyan:id/login_login_btn') tip_commit=(By.ID,'com.tal.kaoyan:id/tip_commit') button_mysefl=(By.ID,'com.tal.kaoyan:id/mainactivity_button_mysefl') username=(By.ID,'com.tal.kaoyan:id/activity_usercenter_username') RightButton=(By.ID,'com.tal.kaoyan:id/myapptitle_RightButton_textview') logoutBtn=(By.ID,'com.tal.kaoyan:id/setting_logout_text') def login_action(self,username,password): self.check_cancelBtn() self.check_skipBtn() logging.info('============login_action==============') logging.info('username is:%s' %username) self.driver.find_element(*self.username_type).send_keys(username) logging.info('password is:%s'%password) self.driver.find_element(*self.password_type).send_keys(password) logging.info('click loginBtn') self.driver.find_element(*self.loginBtn).click() logging.info('login finished!') def check_account_alert(self): logging.info('=====check_account_alert====') try: element=self.driver.find_element(*self.tip_commit) except NoSuchElementException: pass else: logging.info('close tip_commit') element.click() def check_loginStatus(self): logging.info('====check_loginStatus======') self.check_market_ad() self.check_account_alert() try: self.driver.find_element(*self.button_mysefl).click() self.driver.find_element(*self.username) except NoSuchElementException: logging.error('login Fail!') self.getScreenShot('login fail') return False else: logging.info('login success!') self.logout_action() return True def logout_action(self): logging.info('=====logout_action======') self.driver.find_element(*self.RightButton).click() self.driver.find_element(*self.logoutBtn).click() self.driver.find_element(*self.tip_commit).click() if __name__ == '__main__': driver=appium_desired() l=LoginView(driver) l.login_action('bjhg2019','bjhg2019') # l.login_action('bjhg2018','34454') l.check_loginStatus()
2.2 registration page business logic package
Ideas:
1, a view of the package of the first register class definitions
2, and the other input box inherited public class positioning method, positioning account number and password
3, the method of registration status class, defined in the register of APP
4, in a class, a method of adding the definition information registration APP
2.2.1registerView.py
2.2.2 Reference Code
# Coding. 8 = UTF- # 1. First set the encoding, utf-8 may support in English, as described above, generally on the first line # 2. Note: a creation time recording, created, the project name. '' ' The Created ON 2019-11-18 @author: Beijing - Hong brother QQ exchange group: 707 699 217 Project: Appium automated testing framework integrated practice - code for ' '' # 3. Import Module Import logging, Random from kyb_testProject.common. desired_caps Import appium_desired from kyb_testProject.common.common_fun Import the Common, By, NoSuchElementException class RegisterView (the Common): register_text = (By.ID, ' com.tal.kaoyan: ID / login_register_text ' ) #Related picture elements disposed userheader = (By.ID, ' com.tal.kaoyan: ID / activity_register_userheader ' ) item_image = (By.ID, ' com.tal.kaoyan: ID / item_image ' ) Save = (By.ID, ' com.tal.kaoyan: ID / Save ' ) # username and password associated mailbox element register_username = (By.ID, ' com.tal.kaoyan: ID / activity_register_username_edittext ' ) register_password = (By.ID, ' com.tal.kaoyan : ID / activity_register_password_edittext ' ) register_email = (By.ID, 'com.tal.kaoyan:id/activity_register_email_edittext') register_btn= (By.ID, 'com.tal.kaoyan:id/activity_register_register_btn') #完善资料界面元素 perfectinfomation_school = (By.ID, 'com.tal.kaoyan:id/perfectinfomation_edit_school_name') perfectinfomation_major = (By.ID, 'com.tal.kaoyan:id/activity_perfectinfomation_major') perfectinfomation_goBtn = (By.ID, 'com.tal.kaoyan:id/activity_perfectinfomation_goBtn') #院校相关元素 forum_title = (By.ID, 'com.tal.kaoyan:id/more_forum_title') university = (By.ID, 'com.tal.kaoyan:id/university_search_item_name') #专业相关元素 major_subject_title = (By.ID, 'com.tal.kaoyan:id/major_subject_title') major_group_title = (By.ID, 'com.tal.kaoyan:id/major_group_title') major_search_item_name = (By.ID, 'com.tal.kaoyan:id/major_search_item_name') #用户中心相关元素 button_mysefl = (By.ID, 'com.tal.kaoyan:id/mainactivity_button_mysefl') username = (By.ID, 'com.tal.kaoyan:id/activity_usercenter_username') def register_action(self,register_username,register_password,register_email): self.check_cancelBtn() self.check_skipBtn() logging.info('======register_action======') self.driver.find_element(*self.register_text).click() logging.info('set userhead') self.driver.find_element(*self.userheader).click() self.driver.find_elements(*self.item_image)[10].click() self.driver.find_element(*self.save).click() logging.info('username is %s'%register_username) self.driver.find_element(*self.register_username).send_keys(register_username) logging.info('password is %s' % register_password) self.driver.find_element(*self.register_password).send_keys(register_password) logging.info('email is %s' % register_email) self.driver.find_element(*self.register_email).send_keys(register_email) self.driver.find_element(*self.register_btn).click() try: self.driver.find_element(*self.perfectinfomation_school) except NoSuchElementException: logging.error('register fail !') self.getScreenShot('register fail') return False else: self.add_register_info() if self.check_register_status(): return True else: return False def add_register_info(self): logging.info('======add_register_info=====') logging.info('select school...') self.driver.find_element(*self.perfectinfomation_school).click() self.find_elements(*self.forum_title)[1].click() self.find_elements(*self.university)[1].click() logging.info('select major...') self.driver.find_element(*self.perfectinfomation_major).click() self.driver.find_elements(*self.major_subject_title)[1].click() self.driver.find_elements(*self.major_group_title)[2].click() self.driver.find_elements(*self.major_search_item_name)[1].click() self.driver.find_element(*self.perfectinfomation_goBtn).click() def check_register_status(self): logging.info('=====check_register_status=====') self.check_market_ad() try: self.driver.find_element(*self.button_mysefl).click() self.driver.find_element(*self.username) except NoSuchElementException: logging.error('register fail!') self.getScreenShot('register fail') return False else: logging.info('register success!') return True if __name__ == '__main__': driver=appium_desired() register=RegisterView(driver) username = 'bjhg2019' + 'fly' + str(random.randint(1000, 9000)) password = 'bjhg2019' + str(random.randint(1000, 9000)) email = 'bjhg' + str(random.randint(1000, 9000)) + '@163.com' register.register_action(username,password,email)
3. Summary
Well, today because of time to share it here, here we focused on the macro brother implements two business modules, other business modules you can Zhaomaohuahu can be easily achieved. Thank you for your patience to read!