Write automated test code, the data transfer parameters between drives convenient, but also facilitate post-maintenance, here are two kinds of data driven:
Here is test.yaml file:
start_HRApp: ip: 127.0.0.1 port: 4723 implicitly_wait: 10 caps: android: platformName: Android # Simulator platformVersion: 6.0 deviceName: OPPO appPackage: com.csksc2b.invertory appActivity: com.csks.login.SplashAty # Moresheth: True # unicodeKeyboard: True # resetKeyboard: True # autoGrantPermissions: True automationName: uiautomator2 ios:
① for general data files yaml drive:
from appium import webdriver import yaml import os def des_caps(): # Base path base_dir = os.path.dirname (os.path.dirname ( __FILE__ )) # yaml path yaml_path base_dir + = " /data/ddt_data_file.yaml " # acquired yaml data with Open (yaml_path, ' R & lt ' , encoding = ' UTF-. 8 ' ) AS File: data = yaml.load (file) start = data['start_HRApp'] Cap = start['caps']['android'] driver = webdriver.Remote("http://"+ str(start['ip']) +":"+ str(start['port']) +"/wd/hub",Cap) driver.implicitly_wait(10) return driver
② for yaml data driver (of DDT) in the test:
from ddt import ddt, data, file_data, unpack import unittest @ddt class TestBaiduSearch(unittest.TestCase): # Parametric Example. 3: YAML @file_data ( " ../data/ddt_data_file.yaml " ) @unpack def test_baiduSearch03(self, **kwargs): ip = kwargs['ip'] print(ip) if __name__ == '__main__': unittest.main()