Appium Test Case-Python篇
作者:Guanghe 发布时间:[ 2016/12/29 11:33:49 ] 推荐标签:自动化测试 Appium 软件测试工具
完整用例
# coding=utf-8
import os
import unittest, sys, time, re, datetime
import HTMLTestRunner
from appium import webdriver
from time import sleep
import sys
from appium.webdriver.common.touch_action import TouchAction
from appium.webdriver.common.multi_action import MultiAction
reload(sys)
sys.setdefaultencoding('utf-8')
cwd = os.getcwd()
phone_student = 'erwa@qq.com'
class SimpleAndroidTests(unittest.TestCase):
def setUp(self):
desired_caps = {}
desired_caps['appium-version'] = '1.0'
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.0.1'
desired_caps['deviceName'] = '192.168.56.101'
desired_caps['app'] = os.path.abspath(cwd + '/YCMath_Android_V2.7.0_guanghetv.apk')
desired_caps['appPackage'] = 'com.yangcong345.android.phone'
desired_caps['appActivity'] = 'com.yangcong345.android.phone.presentation.activity.SplashActivity'
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
self.driver.implicitly_wait(60)
def tearDown(self):
# end the session
self.driver.quit()
def input_name_pwd(self, name, pwd):
self.driver.find_element_by_id('com.yangcong345.android.phone:id/etUserName').send_keys(name)
self.driver.find_element_by_id('com.yangcong345.android.phone:id/etPwd').send_keys(pwd)
def login(self):
self.driver.find_element_by_id('com.yangcong345.android.phone:id/btn_login').click()
self.input_name_pwd(phone_student, '123456')
self.driver.find_element_by_id('com.yangcong345.android.phone:id/btnLogin').click()
sleep(3)
def open_chapter(self):
self.driver.find_element_by_id('com.yangcong345.android.phone:id/mask_bottom').click()
el = self.driver.find_element_by_id('com.yangcong345.android.phone:id/tabs')
self.assertIsNotNone(el)
els = el.find_elements_by_class_name('android.widget.TextView')
self.driver.scroll(els[len(els) - 1], els[0])
sleep(1)
el = self.driver.find_element_by_name(u'不等式与不等式组')
self.assertIsNotNone(el)
el.click()
sleep(3)
def open_theme(self):
el = self.driver.find_element_by_id('com.yangcong345.android.phone:id/exp_lv')
self.assertIsNotNone(el)
el = self.driver.find_element_by_name(u'不等式的基本概念')
self.assertIsNotNone(el)
el.click()
sleep(3)
def open_topic(self, name):
el = self.driver.find_element_by_id('com.yangcong345.android.phone:id/recycler_view')
self.assertIsNotNone(el)
el = self.driver.find_element_by_name(name)
self.assertIsNotNone(el)
el.click()
sleep(3)
def close_small_video(self):
el = self.driver.find_element_by_id('com.yangcong345.android.phone:id/btn_close')
self.assertIsNotNone(el)
el.click()
def seek_to_end(self):
self.close_small_video()
el = self.driver.find_element_by_id('com.yangcong345.android.phone:id/mediacontroller_progress')
self.assertIsNotNone(el)
end = el.size.get('width')
y = el.location.get('y')
action = TouchAction(self.driver)
action.tap(None, end + 95, y).perform()
sleep(3)
self.close_small_video()
def click_rest(self):
el = self.driver.find_element_by_name(u'先休息一下')
self.assertIsNotNone(el)
el.click()
def module_has_video(self):
el = self.driver.find_element_by_id('com.yangcong345.android.phone:id/recycler_view')
self.assertIsNotNone(el)
el = el.find_element_by_name(u'视频讲解')
self.assertIsNotNone(el)
def open_module_video(self):
el = self.driver.find_element_by_id('com.yangcong345.android.phone:id/recycler_view')
self.assertIsNotNone(el)
el = el.find_element_by_name(u'视频讲解')
self.assertIsNotNone(el)
el.click()
def is_at_theme(self):
el = self.driver.find_element_by_name(u'完成度')
self.assertIsNotNone(el)
def test_3_1_3(self):
self.login()
self.open_chapter()
self.open_theme()
self.open_topic(u'不等式引入')
self.module_has_video()
self.open_module_video()
self.seek_to_end()
self.click_rest()
self.is_at_theme()
if __name__ == '__main__':
suite = unittest.TestSuite()
suite.addTest(
unittest.defaultTestLoader.loadTestsFromTestCase(SimpleAndroidTests)
)
timestr = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
filename = os.path.abspath(cwd + '/result') + "/result_" + timestr + ".html"
print (filename)
fp = open(filename, 'wb')
runner = HTMLTestRunner.HTMLTestRunner(
stream=fp,
title='测试结果',
description='测试报告'
)
runner.run(suite)
fp.close() # 测试报告关闭
本文内容不用于商业目的,如涉及知识产权问题,请权利人联系SPASVO小编(021-61079698-8054),我们将立即处理,马上删除。
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11热门文章
常见的移动App Bug??崩溃的测试用例设计如何用Jmeter做压力测试QC使用说明APP压力测试入门教程移动app测试中的主要问题jenkins+testng+ant+webdriver持续集成测试使用JMeter进行HTTP负载测试Selenium 2.0 WebDriver 使用指南