APP自动化之conftestmainsetting

conftest.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2022/2/19 14:30
# @Author  : shisuiyi
# @File    : conftest.py
# @Software: win10 Tensorflow1.13.1 python3.9
import pytest
from appium import webdriver
import setting
from pages.nav_page import NavPage
from pages.user_page import UserPage


def get_driver():
    """获取driver"""
    desired_caps = {
        "platformName": "Android",
        "automationName": "UiAutomator2",
        "platformVersion": "7.1.2",
        "deviceName": "HUAWEI",
        "appPackage": "com.lemon.lemonban",
        "appActivity": "com.lemon.lemonban.activity.MainActivity",
        "noReset": "False",
        "chromedriverExecutableDir": setting.chromedriver_dir,  # 驱动版本根据系统版本变化。
        # "chromedriverExecutable": r" D:\Lemon\python项目\ChromeDrivers\chromedriver_win32_2\chromedriver.exe",
    }
    driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)

    return driver


@pytest.fixture()
def driver():
    d = get_driver()  # get_driver()中是设备建立连接的配置
    yield d
    d.close_app()
    d.quit()


@pytest.fixture()
def login_driver(driver):
    login_page = NavPage(driver)
    login_page.click_my()

    user_page = UserPage(driver)
    user_page.login('188****463', '*****3')
    return driver

main.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2022/1/12 20:41
# @Author  : shisuiyi
# @File    : main.py
# @Software: win10 Tensorflow1.13.1 python3.9
import pytest

pytest.main(['-m tiku', '--alluredir=report'])

setting.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/11/17 20:27
# @Author  : shisuiyi
# @File    : setting.py
# @Software: win10 Tensorflow1.13.1 python3.9
import os

# 项目根目录
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
print(BASE_DIR)

# 日志配置
LOG_CONFIG = {
    'name': 'app自动化',
    'filename': os.path.join(BASE_DIR, 'logs', 'my.log'),
    'debug': 'true',
    'when': 'S',
    'interval': 10,
}

OUTPUTS_DIR = os.path.join(BASE_DIR, 'outputs')

chromedriver_dir = r"D:\Lemon\python项目\ChromeDrivers\chromedriver_win32_2"
上一篇 下一篇

评论 | 0条评论