import os
import sys
import random
import unittest
from time import sleep
from appium import webdriver
class hh (unittest.TestCase):
def test_addContent(self):
desire_caps={}
desire_caps['platformName']='Android'
desire_caps['platformVersioin']='7.1.1'
desire_caps['appPackage']='com.android.calculator2'
desire_caps['appActivity']='.Calculator'
desire_caps['deviceName']='ZY223MPGDF'
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",desire_caps)
#随机进行n次四则运算
num=[]
num=['0','1','2','3','4','5','6','7','8','9']
numEx='com.android.calculator2:id/digit_'
operator=['com.android.calculator2:id/op_add','com.android.calculator2:id/op_sub',
'com.android.calculator2:id/op_mul','com.android.calculator2:id/op_div']
clearButton='com.android.calculator2:id/clr'
equalButton='com.android.calculator2:id/eq'
i=random.randint(10,15)
while i>=5:
ii=random.randint(3,6)
while ii>=3:
randNum=random.randint(0,9)
numClick=driver.find_element_by_id(numEx+num[randNum]).click()
ii=ii-1
randOP=random.randint(0,3)
operaClick=driver.find_element_by_id(operator[randOP]).click()
ii=random.randint(3,6)
while ii>=3:
randNum=random.randint(0,9)
numClick=driver.find_element_by_id(numEx+num[randNum]).click()
ii=ii-1
equalClick=driver.find_element_by_id(equalButton).click()
clearClick=driver.find_element_by_id(clearButton).click()
sleep(1)
i=i-1
driver.quit()
if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(hh)
unittest.TextTestRunner(verbosity=2).run(suite)
网友评论