首页 > 代码库 > appium基础框架

appium基础框架


 1 #-*-ecoding:utf-8 -*-
 2 from appium import webdriver
 3 from selenium.webdriver.support.wait import WebDriverWait
 4 import unittest
 5 from time import sleep
 6 import time
 7 import HTMLTestRunner
 8 import io
 9 
10 class WebCat_Open(unittest.TestCase):
11     def setUp(self):
12         desired_caps={"platformName":"Android",
13                 "platformVersion":"6.0",
14                 "deviceName":"ZTEBV0710",
15                 "appPackage":"com.tencent.mm",
16                 "appActivity":"com.tencent.mm.ui.LauncherUI ",
17                 "unicodeKeyboard":"true"}
18         self.driver=webdriver.Remote("http://192.168.2.226:4723/wd/hub",desired_caps)
19     def tearDown(self):
20         self.driver.quit()
21 
22     def test_open(self):
23         dr=self.driver
24         qh=WebDriverWait(dr,10).until(lambda dr:dr.find_element_by_name(u""))
25         qh.click()
26         dr.find_element_by_name(u"设置").click()
27         print(dr.current_context)
28         print(dr.current_activity)
29         sleep(10)
30     def test_xy(self):
31         pass
32     def test_wc(self):
33         pass
34 
35 unitsuits=unittest.defaultTestLoader.discover(start_dir=r"C:\Users\syf1225\PycharmProjects\appium",
36                                              pattern="web*.py",
37                                              top_level_dir=None)
38 unitsuit=unittest.TestSuite()
39 for suits in unitsuits:
40     print(suits)
41     for suit in suits:
42         unitsuit.addTests(suit)
43         print(suit)
44 
45 if __name__=="__main__":
46     now = time.strftime("%y%m%d%H%M%S", time.localtime())
47     filename = "C:\\Users\\syf1225\\PycharmProjects\\appium\\htmereport\\" + now+"result.html"
48     file = open(filename, "wb")
49     runner=HTMLTestRunner.HTMLTestRunner(stream=file,
50                                          title=u"微信测试",
51                                          verbosity=1,
52                                          description=u"python脚本,安卓6.0,windows10")
53     runner.run(unitsuit)

 

以上代码是做一些测试时用的,照着此代码基本可以完成大部分基于UI的测试

appium基础框架