appiumDemo(茄子医生)

          apputil.py:  (封装)


#-*- coding:utf-8 -*-
# 导入appium
from appium import webdriver
# 导入time包
import time
# 导入枚举
from enum import Enum
# 倒包
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# 声明类
class Apputil(object):


    # 类被实例化的时候init
    def __init__(self):


        # pep8 规范
        # 将配置参数封装进来
        self.qiezi = {}

    # 打开客户端的方法
    def app_start(self):

        # 设置属性 设置手机类型
        self.qiezi['platformName'] = "Android"
        # 设置自动化测试工具
        self.qiezi['automationName'] = "Appium"
        # 设置手机唯一识别码
        self.qiezi['deviceName'] = "6O5506A01196"
        # 设置本地app加载的路径
        self.qiezi['app'] = "/Users/apple/Desktop/keystore/com.qiezzi.eggplant.apk"
        # 是不是需要重写安装, True 不需要重新安装 False 需要重新安装
        self.qiezi['noReset'] = "false"
        # 设置启动的包名
        self.qiezi['appPackage'] = "com.qiezzi.eggplant"
        # 设置需要运行的手机的版本号
        self.qiezi['platformVersion'] = "4.4"
        # 设置启动页面的activity
        self.qiezi['appActivity'] = "com.qiezzi.eggplant.base.WelcomeActivity"
        # 设置等待启动的页面的包名
        self.qiezi['appWaitPackage'] = "com.qiezzi.eggplant"
        # 设置等待启动的页面的activity
        self.qiezi['appWaitActivity'] = "com.qiezzi.eggplant.base.WelcomeActivity"

        # 禁用软件盘
        # 使用 unicode 输入法
        self.qiezi['unicodeKeyboard'] = True
        # 禁用软件盘
        self.qiezi['resetKeyboard'] = True

        # # 设置关闭键盘
        # self.qiezzi['resetKeyboard'] = True
        # # 设置使用unicode 输入法
        # self.qiezzi['unicodeKeyboard'] = True

        # 将手机启动起来
        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",self.qiezi)
        #设置休眠五秒
        self.TimeSleep(ENUMS.FIVE_TIME)

        pass

    # 关闭客户端的方法
    def app_quit(self):

        # 关闭方法
        self.driver.quit()

        pass

    # 关闭当前窗口
    def app_close(self):

        # 关闭当前窗口
        self.driver.close()

        pass

    # 使用休眠方法 强制休眠
    def TimeSleep(self,number):

        time.sleep(number)

        pass

    # 隐式休眠
    def TimeImplay(self,number):

        self.driver.implicitly_wait(number)

    # 通过id查找
    # 查找控件
    def FindID(self,ID):

        # 通过id
        ids = (By.ID,ID)

        # 休眠检查元素
        WebDriverWait(self.driver,ENUMS.TWENTY_TIME,ENUMS.ONE_HALF).until(EC.presence_of_element_located(ids))

        # 开始查找
        return self.driver.find_element_by_id(ID)

    # 设置点击事件
    def ClickID(self,ID):

        self.FindID(ID).click()

    # 输入内容
    def SendkeysID(self,ID,message):

        self.FindID(ID).send_keys(message)

    # 通过xpath查找
    def FindXpath(self,xpath):

        xpaths = (By.XPATH,xpath)

        WebDriverWait(self.driver,ENUMS.TWENTY_TIME,ENUMS.ONE_HALF).until(EC.presence_of_element_located(xpaths))

        return self.driver.find_element_by_xpath(xpath)

    # xpath点击事件
    def ClickXpath(self,xpath):

        self.FindXpath(xpath).click()

        # 设置休眠 以防止在跳转的时候代码运行的速度超过页面跳转的速度
        self.TimeSleep(ENUMS.TWO_TIME)

    # 输入内容
    def SendkeysXpath(self,xpath,message):

        self.FindXpath(xpath).send_keys(message)

    # 根据内容查找
    def FindLink(self,link):

        links = (By.LINK_TEXT,link)

        WebDriverWait(self.driver,ENUMS.TWENTY_TIME,ENUMS.ONE_HALF).until(EC.presence_of_element_located(links))

        return self.driver.find_element_by_link_text(link)

    # 设置点击事件
    def ClickLink(self,link):

        self.FindLink(link).click()
        # 设置休眠 以防止在跳转的时候代码运行的速度超过页面跳转的速度
        self.TimeSleep(ENUMS.TWO_TIME)

    # 输入内容
    def SendkesLink(self,link,message):

        self.FindLink(link).send_keys(message)
        # 设置休眠 以防止在跳转的时候代码运行的速度超过页面跳转的速度
        self.TimeSleep(ENUMS.TWO_TIME)




    # 查询一组控件
    def FindIDs(self,ID):

        # 通过id
        ids = (By.ID, ID)

        # 休眠检查元素
        WebDriverWait(self.driver, ENUMS.TWENTY_TIME, ENUMS.ONE_HALF).until(EC.presence_of_element_located(ids))

        # 开始查找
        return self.driver.find_elements_by_id(ID)

    # 通过下标点击第一个
    def ClickIDS(self,ID,index):

        self.FindIDs(ID)[index].click()


    # 从一个滑动到另外一个
    def swith_to_element(self,e1,e2):

        # 从 e1 滑动到 e2
        self.driver.scroll(e1,e2)

        pass




    # 切换H5
    def SwitchH5(self):

        # 设置休眠
        self.TimeSleep(ENUMS.FIVE_TIME)

        self.driver.switch_to.context("")

    # 获取宽度和高度
    def getWidth(self):

        return self.driver.get_window_size()['width']

    # 获取高度发
    def getHeight(self):

        return self.driver.get_window_size()['height']

    # 滑动的方法
    def swipe(self):

        # 设置休眠
        self.TimeSleep(ENUMS.TWO_TIME)

        # 滑动
        self.driver.swipe(self.getWidth()-50,self.getHeight()/2,50,self.getHeight()/2,1000)

        # 设置休眠
        self.TimeSleep(ENUMS.TWO_TIME)

    # 获取当前activity的方法
    def getCurrentActivity(self):

        return self.driver.current_activity

    # 断言页面的方法
    def AssertAcitity(self,self1,expect):

        # 设置休眠时间
        self.TimeSleep(ENUMS.TWO_TIME)
        # 进行断言
        self1.assertEqual(self.getCurrentActivity(),expect)

        pass

    def AssertCount(self, self1,count, expect):
        # 设置休眠时间
        self.TimeSleep(ENUMS.TWO_TIME)
        # 进行断言
        self1.assertEqual(count, expect)

        pass





# 定义枚举类型
class ENUMS(Enum):

    # 10 秒
    TEN_TIME = 10
    # 20秒
    TWENTY_TIME = 20
    # 0.5秒
    ONE_HALF = 0.5
    # 5秒
    FIVE_TIME = 5
    # 两秒
    TWO_TIME = 2

                 welcomecontrol.py:
#-*- coding:utf-8 -*-
from util import apputil

# 声明类
class WelcomeControl(object):


    def __init__(self,app):

        # 实例化工具类
        # self.app = apputil.Apputil()

        self.app = app

        pass

    # 点击新手引导页
    def welcome_next(self):

        # 使用for循环实现滑动
        for index in range(0,4):

            if index< 3:

                self.app.swipe()

            else:

                self.app.ClickXpath("//android.widget.Button[@resource-id='com.qiezzi.eggplant:id/btn_feel_right_now']")


        pass

    # 点击新手引导页
    def welcome_next_hide(self):

        # 使用for循环实现滑动
        for index in range(0, 4):

            if index < 3:

                self.app.swipe()

            else:

                # 使用try 方法
                try:

                    # 查找跳过按钮
                    self.app.FindID("com.qiezzi.eggplant:id/btn_firstinstall_intent")

                    pass

                except:

                    self.app.ClickXpath(
                        "//android.widget.Button[@resource-id='com.qiezzi.eggplant:id/btn_feel_right_now']")

        pass

    # 滑动到第四个页面,在往回滑动验证按钮能不能使用


    # 点击跳过按钮
    # index 1 2 3 在这三个页面分别点击跳过按钮,
    def welcome_jumnp(self,index):

        # 使用for循环的目的就是为了帮助我们滑动页面
        for i in range(0,index):

            # 滑到我指定的页面去点击按钮
            if i == index - 1:
                #查找控件,点击跳过按钮
                self.app.ClickID("com.qiezzi.eggplant:id/btn_firstinstall_intent")

                # 跳出for循环的方法
                break
                pass

            if i <3:

                self.app.swipe()

        pass

                 logincontron.py:
#-*- coding:utf-8 -*-

# 倒包
from util import apputil


# 声明类
class LoginControl(object):


    def __init__(self,app):

        # self.app = apputil.Apputil()
        #
        self.app = app

        pass


    def login_us_pw(self):

        # 输入账号和密码
        self.app.SendkeysID("com.qiezzi.eggplant:id/edt_frist_login_accout","18301585363")
        self.app.SendkeysID("com.qiezzi.eggplant:id/edt_frist_login_password","123456")

        # 点击登录
        self.app.ClickID("com.qiezzi.eggplant:id/btn_frist_login_immediately")

        # 设置休眠时间 因为反应时间
        self.app.TimeSleep(apputil.ENUMS.FIVE_TIME)



        pass
                 meetcontrol.py:(点击今天)
#-*- coding:utf-8 -*-

from util import apputil


class MeetControl(object):

    def __init__(self,app):

        # 实例化
        # self.app = apputil.Apputil()
        #
        self.app = app

        pass

    # 点击我的
    def meet_click_tody(self,click_day):

        # 通过内容查找
        self.app.ClickXpath(click_day)

        # 因为有网络请求时间所有在这里设休眠
        self.app.TimeSleep(apputil.ENUMS.FIVE_TIME)

        # 查找listview 控件
        items = self.app.FindIDs("com.qiezzi.eggplant:id/tv_adapter_appoint_data")

        for item in items:

            print item.text

        return len(items)
                   (unit)login.py:
#-*- coding:utf-8 -*-

import unittest

# 倒包
from util import apputil
from welcomec.control import welcomecontrol
from loginc.clogin import logincontron


# 定义类继承
class Login(unittest.TestCase):

    @classmethod
    def setUpClass(self):

        # 实例化工具类 和 控制类
        self.app = apputil.Apputil()
        # 实例化welcome类
        self.welcome = welcomecontrol.WelcomeControl(self.app)
        # 实例化登陆
        self.login = logincontron.LoginControl(self.app)

        pass

    # 打开浏览器
    def setUp(self):

        # 打开浏览器
        self.app.app_start()
        # 点击跳过
        self.welcome.welcome_jumnp(1)

        pass

    # 关闭浏览器
    def tearDown(self):

        self.app.app_quit()

        pass

    def test_login_us_pw(self):

        u"""属于正确的用户名和密码"""

        self.login.login_us_pw()

        # 进行断言
        self.app.AssertAcitity(self,'.main.activity.MainActivity')


        pass


if __name__ == '__main__':
    unittest.main()

                 (unit)welcome.py:
#-*- coding:utf-8 -*-

# 导入单元测试
import unittest
# 倒包
from util import apputil
# 导入控制类
from welcomec.control import welcomecontrol

# 声明类
class Welcome(unittest.TestCase):


    # 实例化对象 只执行一次
    @classmethod
    def setUpClass(self):

        # 实例化工具类
        self.app = apputil.Apputil()
        # 实例化控制类
        self.welcome = welcomecontrol.WelcomeControl(self.app)

        pass


    def setUp(self):

        # 打开客户端
        self.app.app_start()

        pass


    def tearDown(self):

        # 关闭客户端
        self.app.app_quit()

        pass


    def test_welcome_next(self):


        u"""点击第四个页面的立即体验按钮"""


        # 进行滑动,同时点击下一步
        self.welcome.welcome_next()

        # 进行断言
        self.app.AssertAcitity(self,".login.activity.LoginActivity")

        pass

    def test_welcome_jump_first(self):

        u"""点击第一个页面的跳过按钮"""


        # 点击跳过按钮的封装,点击第一个页面
        self.welcome.welcome_jumnp(1)
        # 进行断言
        self.app.AssertAcitity(self, ".login.activity.LoginActivity")

        pass

    def test_welcome_jump_second(self):

        u"""点击第二个页面的跳过按钮"""

        # 点击跳过按钮的封装,点击第一个页面
        self.welcome.welcome_jumnp(2)
        # 进行断言
        self.app.AssertAcitity(self, ".login.activity.LoginActivity")

        pass

    def test_welcome_jump_thrid(self):

        u"""点击第三个页面的跳过按钮"""

        # 点击跳过按钮的封装,点击第一个页面
        self.welcome.welcome_jumnp(3)
        # 进行断言
        self.app.AssertAcitity(self, ".login.activity.LoginActivity")

        pass

    # 在第四个页面,验证跳过按钮有没有隐藏掉,同时立即体验按钮是不是显示出来了
    def test_welcome_jump_hide(self):

        u"验证在第四个页面,跳过按钮是不是已经隐藏掉,同时立即体验按钮是不是能够点击"

        self.welcome.welcome_next_hide()

        # 断言
        self.app.AssertAcitity(self, ".login.activity.LoginActivity")

        pass

    # 滑动到第四个页面,在往会滑动一个页面,验证立即体验按钮又没有隐藏掉
    # 跳过按钮又没有显示出来
    def test_welcome_four_three(self):


        # 断言
        self.app.AssertAcitity(self, ".login.activity.LoginActivity")

        pass


                   (unit)meet.py:

#-*- coding:utf-8 -*-

# 导入单元测试
import unittest
# 倒包
from util import apputil
from welcomec.control import welcomecontrol
from loginc.clogin import logincontron
from meets.meetc import meetcontrol

# 定义类
class Meet(unittest.TestCase):

    @classmethod
    def setUpClass(self):

        # 实例化工具类
        self.app = apputil.Apputil()
        # 实例化welcome类
        self.welcome = welcomecontrol.WelcomeControl(self.app)
        # 实例化登陆
        self.login = logincontron.LoginControl(self.app)
        # 实例化预约控制类
        self.meet = meetcontrol.MeetControl(self.app)

        pass

    def setUp(self):

        # 打开app
        self.app.app_start()
        # 点击跳过
        self.welcome.welcome_jumnp(1)
        # 点击登陆
        self.login.login_us_pw()


        pass

    def tearDown(self):

        # 关闭 app
        self.app.app_quit()


        pass

    # def test_click_clander(self):
    #
    #     u"""点击今天,看看数量能不能对上"""
    #
    #     count = self.meet.meet_click_tody("//android.widget.FrameLayout[@resource-id='com.qiezzi.eggplant:id/fl_mian_frag']/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.view.View[3]/android.widget.TextView[6]");
    #
    #     # 点击今天进行断言
    #     self.app.AssertCount(self,count,1)
    #
    #
    #     pass


    # 新建预约测试用例
    def test_new_add_patient(self):

        u"""新建患者功能"""

        tv_current_mouth = self.app.ClickID("com.qiezzi.eggplant:id/tv_current_mouth")

        # 设置休眠 因为这里需要调整页面,加载数据
        self.app.TimeSleep(apputil.ENUMS.FIVE_TIME)

        # 查询一组控件,点击第一个元素
        self.app.ClickIDS("com.qiezzi.eggplant:id/ll_adapter_group",0)

        #  设置患者为1: 复诊  2:设置预约事项为: 根管预备 3: 设置日期为当天 4: 设置时间为当前实际多半个小时 5:

        # 设置休眠
        self.app.TimeSleep(apputil.ENUMS.FIVE_TIME)

        # 点击复诊
        self.app.ClickID("com.qiezzi.eggplant:id/btn_add_new_appoint_sencod")

        # 点击预约事项为根管预备
        self.app.ClickID("com.qiezzi.eggplant:id/ll_activity_add_new_appoint_times")

        # 设置休眠,用来做网络加载
        self.app.TimeSleep(apputil.ENUMS.FIVE_TIME)

        # 查询一组,点击第一个根管预备
        self.app.ClickIDS("com.qiezzi.eggplant:id/rl_adapter_see_doctor",0)

        # 点击保存按钮
        self.app.ClickID("com.qiezzi.eggplant:id/tv_main_title_setting")

        # 点击预约日期,选择今天
        self.app.ClickID("com.qiezzi.eggplant:id/ll_activity_add_new_appoint_data")

        # 直接点击完成
        self.app.ClickID("android:id/button1")

        # 点击预约时间
        self.app.ClickID("com.qiezzi.eggplant:id/ll_activity_add_new_appoint_time")

        e2 = self.app.FindXpath("//android.widget.EditText[@resource-id='android:id/numberpicker_input' and @text='14']")
        e1 = self.app.FindXpath("//android.widget.Button[@text='15']")

        # 点击日期选择
        self.app.swith_to_element(e1,e2)

        # 点击 完成按钮
        self.app.ClickID("android:id/button1")

        # 点击保存
        tv_main_title_setting = self.app.ClickID("com.qiezzi.eggplant:id/tv_main_title_setting")

        # 加入休眠
        self.app.TimeSleep(apputil.ENUMS.FIVE_TIME)

        # 点击返回按钮
        self.app.driver.keyevent(4)

        # 休眠 在这里activity执行onResume 方法加载数据,这样才能确保数据的准确行
        self.app.TimeSleep(apputil.ENUMS.FIVE_TIME)

        # 查找控件,断言
       count = self.meet.meet_click_tody("//android.widget.FrameLayout[@resource-id='com.qiezzi.eggplant:id/fl_mian_frag']/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.view.View[4]/android.widget.TextView[1]");

        # 点击今天进行断言
        self.app.AssertCount(self, count/2, 2)


        pass



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值