android_test.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # coding:utf-8
  2. import os
  3. import unittest
  4. from selenium import webdriver
  5. # Returns abs path relative to this file and not cwd
  6. PATH = lambda p: os.path.abspath(
  7. os.path.join(os.path.dirname(__file__), p)
  8. )
  9. class elementA(unittest.TestCase):
  10. def test_(self):
  11. desired_caps = {}
  12. desired_caps['deviceName'] = '4d00b6a5bee8a047' # adb devices查到的设备名
  13. desired_caps['platformName'] = 'Android'
  14. desired_caps['platformVersion'] = '4.2'
  15. desired_caps['appPackage'] = 'com.duowan.mobile' # 被测App的包名
  16. desired_caps['appActivity'] = 'com.yy.mobile.ui.splash.SplashActivity' # 启动时的Activity
  17. driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
  18. el = driver.find_element_by_name(u"神曲")
  19. self.assertIsNotNone(el)
  20. el.click()
  21. yueBang = driver.find_element_by_name(u"月榜")
  22. self.assertIsNotNone(yueBang)
  23. yueBang.click()
  24. driver.quit()
  25. if __name__ == '__main__':
  26. testunit = unittest.TestSuite() # 定义一个单元测试容器
  27. testunit.addTest(elementA("test_")) # 将测试用例加入到测试容器中
  28. filename = "./myAppiumLog.html" # 定义个报告存放路径,支持相对路径。
  29. fp = file(filename, 'wb')
  30. runner = Demo.HTMLTestRunner(stream=fp, title='Report_title',
  31. description='Report_description') # 使用HTMLTestRunner配置参数,输出报告路径、报告标题、描述
  32. runner.run(testunit) # 自动进行测试