zoukankan      html  css  js  c++  java
  • appium 判断app是否安装

     1 #coding:utf-8
     2 #Import the common package
     3 import os
     4 import unittest
     5 from appium import webdriver
     6 from time import sleep
     7 
     8 #设置路径信息
     9 PATH = lambda p: os.path.abspath(
    10     os.path.join(os.path.dirname(__file__), p)
    11 )
    12 
    13 class LoginAndroidTests(unittest.TestCase):
    14     def setUp(self):
    15         #初始化测试平台
    16         desired_caps = {}
    17         desired_caps['platformName'] = 'Android'
    18         desired_caps['platformVersion'] = '4.4.2'
    19         desired_caps['deviceName'] = '127.0.0.1:62001'
    20         #desired_caps['app'] = 'D:apkxx.apk'
    21         desired_caps['appPackage'] = 'com.lovebizhi.wallpaper'
    22         desired_caps['appActivity'] = 'com.lovebizhi.wallpaper.WelcomeActivity'
    23         self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
    24 
    25         
    26       
    27     def tearDown(self):
    28        
    29         self.driver.quit()
    30         
    31     def test_1(self):
    32         #测试导航页
    33         print("start test1...")
    34 
    35         #判断是否安装爱壁纸APP
    36         wallpaper = self.driver.is_app_installed("com.lovebizhi.wallpaper")
    37         if wallpaper:
    38             #self.driver.remove_app("com.lovebizhi.wallpaper")
    39             sleep(8)
    40             # 点击某一壁纸图片
    41             self.driver.find_elements_by_id("com.lovebizhi.wallpaper:id/image1")[4].click()
    42             sleep(4)
    43             # 点击设置壁纸
    44             self.driver.find_element_by_id("com.lovebizhi.wallpaper:id/btSetup").click()
    45             sleep(5)
    46         else:
    47             self.driver.install_app("D:apkxx.apk")
    48             sleep(30)
    49 
    50     def test_2(self):
    51         #测试导航页
    52         print("start test2")
    53 
    54         #判断是否安装爱壁纸APP
    55         wallpaper = self.driver.is_app_installed("com.lovebizhi.wallpaper")
    56         #
    57         if wallpaper:
    58             sleep(8)
    59             # 点击某一壁纸图片
    60             self.driver.find_elements_by_id("com.lovebizhi.wallpaper:id/image1")[5].click()
    61             sleep(4)
    62             # 点击设置壁纸
    63             self.driver.find_element_by_id("com.lovebizhi.wallpaper:id/btSetup").click()
    64             sleep(5)
    65         #否,安装
    66         else:
    67             self.driver.install_app("D:apkxx.apk")
    68             sleep(30)
    69         
    70                   
    71 
    72 if __name__ == '__main__':
    73     suite =unittest.TestLoader().loadTestsFromTestCase(LoginAndroidTests)
    74     unittest.TextTestRunner(verbosity=2).run(suite)
  • 相关阅读:
    How to fix the error; 'Error: Bootstrap tooltips require Tether (http://github.hubspot.com/tether/)'
    CentOS 7.2安装教程
    webpack打包生成多个vendor的配置方法
    webpack务虚扫盲
    Webpack引入jquery及其插件的几种方法
    多线程Lock版生产者和消费者模式
    多线程共享全局变量以及锁机制
    多线程Thread类
    多线程threading模块
    Python正则表达式(二)
  • 原文地址:https://www.cnblogs.com/lxs1314/p/7126064.html
Copyright © 2011-2022 走看看