appium+allure+pytest

1、环境搭建

    brew install allure

    npm install  appium

    pip3 install pytest

    pip3 install allure-pytest

    pip3 install pytest-allure-adaptor

    sudo pip3 install Appium-Python-Client

 

2、设备信息

(使用yaml格式,多个设备信息放一个yaml文件里)

-
  deviceDesc: Honor_8
  server_url: 127.0.0.1
  server_port: 4723
  desired_caps:
    platformName: Android
    platformVersion: 8.0.0
    deviceName: xxxxxx
    appPackage: xxxxxx
    appActivity: .ui.MainActivity
    noReset: True
    automationName: UiAutomator2
    systemPort: 8200
-
  deviceDesc: Mi_6X
  server_url: 127.0.0.1
  server_port: 4724
  desired_caps:
    platformName: Android
    platformVersion: 9
    deviceName: xxxxxxx
    appPackage: xxxxxxx
    appActivity: .ui.MainActivity
    noReset: True
    automationName: Uiautomator2
    systemPort: 8203

 

3、定义driver和device   

    class BaseDriver:
       def base_driver(self, device, automationName='UiAutomator2', noReset=True):
         path = caps_dir
         with open(path, encoding='utf-8') as fs:
            datas = yaml.load(fs, Loader=yaml.FullLoader)
        for i in datas:
            if device == i['deviceDesc']:
                if noReset == False:
                    i['desired_caps']['noReset'] = False
                desired_caps = i['desired_caps']
                driver = webdriver.Remote('http://{0}:{1}/wd/hub'.format(i['server_url'], i['server_port']), desired_caps)
                return driver, device

4、全局conftest.py文件

    params=[deviceDesc]

    @pytest.fixture(params=params)
    def execute_driver(request):
        driver = BaseDriver().base_driver(device=request.param)
        yield driver
        driver[0].close_app()
        driver[0].quit()

 

5、main.py文件

    curTime = time.strftime('%Y-%m-%d_%H-%M-%S')
    pytest.main([
    '-s', '-q',
    '-p','no:warnings',
    # '--reruns','1',
    '--alluredir', htmlreports_dir + '/app_AutoTest_Reports_{0}'.format(curTime),
    ])

 

6、生成report

    allure generate HtmlTestReports/xxxx_Reports_2019-10-30_19-30-16/ -o report

 


 

你可能感兴趣的:(python)