APP自动化之测试用例的编写

test_login.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/8/14 13:43
# @Author  : shisuiyi
# @File    : test_login.py
# @Software: win10 Tensorflow1.13.1 python3.7
import pytest
from pages.nav_page import NavPage
from pages.user_page import UserPage


class TestLogin(object):
    data_error = [('188****66', '12334', '密码格式不正确')]

    @pytest.mark.parametrize('username,password,expect', data_error, ids=['登录失败'])
    def test_login_error(self, username, password, expect, driver):
        login_page = NavPage(driver)
        login_page.click_my()

        user_page = UserPage(driver)
        user_page.login(username, password)

        assert user_page.get_login_msg() == expect

test_swich_h5.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2022/2/20 16:28
# @Author  : shisuiyi
# @File    : test_swich_h5.py
# @Software: win10 Tensorflow1.13.1 python3.9

from pages.h5_page import H5
from pages.home_page import HomePage
from pages.nav_page import NavPage


class Testh5(object):
    def test_switch(self, driver):
        nav_page = NavPage(driver)
        nav_page.click_homepage()

        home_page = HomePage(driver)
        home_page.click_quanchengban()

        switch = H5(driver)
        switch.switch_h5()
        switch.click_pingjia()

test_tiku.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2022/2/24 19:57
# @Author  : shisuiyi
# @File    : test_tiku.py
# @Software: win10 Tensorflow1.13.1 python3.9
import pytest

from pages.tiku_page import TikuPage
from pages.user_page import UserPage


@pytest.mark.tiku
def test_tiku(login_driver):
    """
    1, 登录, conftest
    2,选择题库, xpath  //android.widget.TextView[@text='Linux']
    3, 选择难度初级   id  com.lemon.lemonban:id/first_level
    4, 选择题库编号   id  android.widget.RelativeLayout
    5, 滑动 2 次,向左边滑动
    6, 断言 显示的题号是不是 3: 定位元素 id  com.lemon.lemonban:id/toolbar_textview
    7, 获取 text 文本, string.split('/')[0]
    :return:
    """
    swipe_time = 2
    tiku_page = TikuPage(login_driver)
    tiku_page.click_tiku()
    number = tiku_page.show_tiku(swipe_time)
    # assert number == str(swipe_time + 1)
    # 这里每次运行的时候偶尔会出现只向左滑动一次的情况。??
    answer = tiku_page.accept_answer()
    assert answer
    # 断言是否可以查看到答案

    tiku_page.collect()
    tiku_page.click_my()
    user_page = UserPage(login_driver)
    assert user_page.cat_collect_list() == "Linux"
    # 断言收藏的内容是否正确