Skip to content

Commit c7bf8b5

Browse files
committed
Native App和Hybrid App自动测试脚本
1 parent bc2ca56 commit c7bf8b5

File tree

9 files changed

+657
-219
lines changed

9 files changed

+657
-219
lines changed

.idea/encodings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 144 additions & 88 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

HybridTest.apk

1.34 MB
Binary file not shown.
File renamed without changes.

README.md

Lines changed: 413 additions & 129 deletions
Large diffs are not rendered by default.

httptestdemo.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# coding=utf-8
2+
3+
import unittest
4+
import requests
5+
from ddt import ddt, data, unpack
6+
import sys
7+
8+
reload(sys)
9+
sys.setdefaultencoding('utf-8')
10+
11+
@ddt
12+
class HttpTestCase(unittest.TestCase):
13+
def setUp(self):
14+
print "开始"
15+
16+
def tearDown(self):
17+
print "结束"
18+
19+
@data('101010100', '101250101', '101250301', '101250603', '101251003')
20+
def testGet(self, city_id):
21+
# headers = {
22+
# "User-Agent": "test"
23+
# }
24+
# cookies = {}
25+
26+
result = requests.get("http://www.weather.com.cn/data/sk/" + city_id + ".html")
27+
result.encoding = 'utf-8'
28+
print result.text
29+
30+
self.assertTrue(city_id in result.text)
31+
32+
33+
if __name__ == '__main__':
34+
unittest.main()
35+

hybrid_app/HybridScript.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# encoding=utf-8
2+
3+
import unittest
4+
import time
5+
from appium import webdriver
6+
7+
8+
class MyTestCase(unittest.TestCase):
9+
10+
def setUp(self):
11+
# 定义初始化的属性信息
12+
self.desired_caps = {}
13+
self.desired_caps['platformName'] = 'Android'
14+
self.desired_caps['platformVersion'] = '6.0'
15+
self.desired_caps['deviceName'] = '192.168.115.101:5555'
16+
self.desired_caps['appPackage'] = 'com.hyd.miniwebbrowser'
17+
self.desired_caps['appActivity'] = '.MainActivity'
18+
self.desired_caps["unicodeKeyboard"] = "True"
19+
self.desired_caps["resetKeyboard"] = "True"
20+
self.desired_caps["automationName"] = "Selendroid"
21+
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', self.desired_caps)
22+
23+
def testSearch(self):
24+
# Locate 定位输入框
25+
input_url = self.driver.find_element_by_id("et_url")
26+
# Operate 操作
27+
input_url.send_keys("https://wap.sogou.com")
28+
29+
btn_search = self.driver.find_element_by_id("btn_search")
30+
btn_search.click()
31+
32+
time.sleep(5)
33+
34+
# Switch 切换当前的上下文
35+
print self.driver.contexts
36+
self.driver.switch_to.context('WEBVIEW_0')
37+
print self.driver.current_context
38+
time.sleep(5)
39+
40+
# 定位web输入框
41+
web_input = self.driver.find_element_by_xpath('//*[@id="keyword"]')
42+
web_input.click()
43+
web_input.send_keys("2020")
44+
web_search_button = self.driver.find_element_by_xpath('//*[@id="searchform"]/div/div/div[1]/div[2]/input')
45+
web_search_button.click()
46+
time.sleep(5)
47+
48+
# 检验查询结果
49+
first_result = self.driver.find_element_by_xpath('//*[@id="sogou_vr_30010212_1"]/div/div[1]/a[1]')
50+
self.assertTrue("2020" in first_result.text)
51+
52+
def tearDown(self):
53+
self.driver.quit()
54+
55+
56+
if __name__ == '__main__':
57+
unittest.main()

hybrid_app/__init__.py

Whitespace-only changes.

mytestrunner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# encoding=utf-8
22

3-
import unittestdemo
3+
import NativeScript
44
import unittest
55

66

77
# 以一个类的维度去执行
8-
cases = unittest.TestLoader.loadTestsFromTestCase(unittestdemo.MyTestCase)
8+
cases = unittest.TestLoader.loadTestsFromTestCase(NativeScript.MyTestCase)
99
# 可以一次添加多个cases
1010
my_suite = unittest.TestSuite([cases])
1111

0 commit comments

Comments
 (0)