#coding=utf-8
#!/usr/bin/env monkeyrunner
# Copyright 2010, The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from com.android.monkeyrunner import MonkeyRunner as MR
from com.android.monkeyrunner import MonkeyDevice as MD
from com.android.monkeyrunner import MonkeyImage as MI
from com.android.monkeyrunner.easy import EasyMonkeyDevice,By
device=MR.waitForConnection(10)
if device:
print("Connect device successful!")
else:
print("Connect device failed!")
a=0
b=0
for j in range(1,100):
Package = 'baoming'
Activity ='Activity'
runComponent = Package + '/' + Activity
device.startActivity(component=runComponent)
MR.sleep(5.0)
# i=j%10
# for x in xrange(0,i):
# device.drag((951,595),(951,0,),1.0,1)
# MR.sleep(2.0)
# print 'dragtime:'+str(x)
# else:
# print 'enddrag'
# MR.sleep(3.0)
image = device.takeSnapshot()
image.writeToFile('/Users/Downloads/LIST.png','png')
device.touch(121,1843,'DOWN_AND_UP')
MR.sleep(2.0)
image = device.takeSnapshot()
image.writeToFile('/Users/Downloads/detail.png','png')
result = MR.loadImageFromFile('/Users/Downloads/LIST.png')
MR.sleep(2.0)
if image.sameAs(result,0.9):
pass
else:
device.touch(548,1813,'DOWN_AND_UP')
MR.sleep(15.0)
image = device.takeSnapshot()
image.writeToFile('/Users/Downloads/play.png','png')
result = MR.loadImageFromFile('/Users/Downloads/detail.png')
MR.sleep(2.0)
if image.sameAs(result,0.9):
a=a+1
anum='第'+str(a)+'次连接失败'
image.writeToFile(anum+'.png','png')
print anum
MR.sleep(2.0)
else:
MR.sleep(2.0)
b=b+1
bnum ='第'+str(b)+'次连接成功'
print bnum
MR.sleep(2.0)
device.press('KEYCODE_BACK')
device.press('KEYCODE_BACK')
MR.sleep(2.0)
device.press('KEYCODE_BACK')
device.press('KEYCODE_BACK')
MR.sleep(5.0)
print '第'+str(j)+'次连接'
else:
print ' end' ;
#!/usr/bin/env monkeyrunner
# Copyright 2010, The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from com.android.monkeyrunner import MonkeyRunner as MR
from com.android.monkeyrunner import MonkeyDevice as MD
from com.android.monkeyrunner import MonkeyImage as MI
from com.android.monkeyrunner.easy import EasyMonkeyDevice,By
device=MR.waitForConnection(10)
if device:
print("Connect device successful!")
else:
print("Connect device failed!")
a=0
b=0
for j in range(1,100):
Package = 'baoming'
Activity ='Activity'
runComponent = Package + '/' + Activity
device.startActivity(component=runComponent)
MR.sleep(5.0)
# i=j%10
# for x in xrange(0,i):
# device.drag((951,595),(951,0,),1.0,1)
# MR.sleep(2.0)
# print 'dragtime:'+str(x)
# else:
# print 'enddrag'
# MR.sleep(3.0)
image = device.takeSnapshot()
image.writeToFile('/Users/Downloads/LIST.png','png')
device.touch(121,1843,'DOWN_AND_UP')
MR.sleep(2.0)
image = device.takeSnapshot()
image.writeToFile('/Users/Downloads/detail.png','png')
result = MR.loadImageFromFile('/Users/Downloads/LIST.png')
MR.sleep(2.0)
if image.sameAs(result,0.9):
pass
else:
device.touch(548,1813,'DOWN_AND_UP')
MR.sleep(15.0)
image = device.takeSnapshot()
image.writeToFile('/Users/Downloads/play.png','png')
result = MR.loadImageFromFile('/Users/Downloads/detail.png')
MR.sleep(2.0)
if image.sameAs(result,0.9):
a=a+1
anum='第'+str(a)+'次连接失败'
image.writeToFile(anum+'.png','png')
print anum
MR.sleep(2.0)
else:
MR.sleep(2.0)
b=b+1
bnum ='第'+str(b)+'次连接成功'
print bnum
MR.sleep(2.0)
device.press('KEYCODE_BACK')
device.press('KEYCODE_BACK')
MR.sleep(2.0)
device.press('KEYCODE_BACK')
device.press('KEYCODE_BACK')
MR.sleep(5.0)
print '第'+str(j)+'次连接'
else:
print ' end' ;