美文网首页AppiumAppium自动化测试Appium
Appium-Python随机进行n次i位数字四则运算

Appium-Python随机进行n次i位数字四则运算

作者: Johnerrrr | 来源:发表于2017-11-05 23:15 被阅读11次
    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)
    

    相关文章

      网友评论

        本文标题:Appium-Python随机进行n次i位数字四则运算

        本文链接:https://www.haomeiwen.com/subject/hfckmxtx.html