Author: Dreamer (Missy)
Provenance:/chongyou/
python reads the yaml file to use, in two ways:
1. Use ddt to read
2,Use the method to read the contents of the ddt, in the use of the method to call the
1. Use ddt to read
@ class loginTestPage(): @ddt.file_data(path) @ def testlogin(self,**kwargs): u''' "Enter email account, username, password to meet requirements Check the box to agree to the agreement" 1、Successful registration,跳转到Successful registration页面 " 1、Verify the URL, /site/ 2、Registration success email received by mailbox 3, the user table in the database has successfully added the registered account data " :return: ''' = CBLogin() (kwargs) = Page(,('login_url')) .send_text(.login_sendkes_username(),('username')) .send_text(.login_sendkes_password(),('password')) (.login_click_btn()) # Assertion of successful login (.is_success(),"Element not found, login failed.")
2. Use existing methods to make calls
class HandleYmal: """ Getting the configuration of the test environment """ def __init__(self,file_path=None): if file_path: self.file_path=file_path else: # Get path root_dir=(('.')) print(root_dir) self.file_path=root_dir+"/config/" def get_data(self): fp=open(self.file_path,encoding="utf-8") data=(fp) return data @ class loginTestPage(): @classmethod def setUpClass(cls): """The front end is supposed to read everything.""" yaml=HandleYmal() =yaml.get_data()['testenvironment'] = () def testlogin(self): u''' "Enter email account, username, password to meet requirements Check the box to agree to the agreement" 1、Successful registration,跳转到Successful registration页面 " 1、Verify the URL, /site/ 2、Registration success email received by mailbox 3, the user table in the database has successfully added the registered account data " :return: ''' = CBLogin() () = Page(,('login_url')) .send_text(.login_sendkes_username(),('username')) .send_text(.login_sendkes_password(),('password')) (.login_click_btn()) # Assertion of successful login (.is_success(),"Element not found, login failed.")
The above is python read yaml file two methods (used in unittest) of the details, more about python read yaml file information please pay attention to my other related articles!