appium-4:测试小米手机自带的计算器

#coding=utf-8
from appium import webdriver
import unittest

class TesXiaomiCalc(unittest.TestCase):

    def setUp(self):
        desired_caps = {
            'platformName':'Android',
            'platformVersion':'5.0.2',
            'deviceName':'b082512'
        }
        desired_caps["unicodeKeyboard"]="True"
        desired_caps["resetKeyboard"]="True"
        desired_caps['appPackage'] = 'com.miui.calculator'
        desired_caps['appActivity'] = '.cal.CalculatorActivity'
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)

    def testDown(self):
        self.driver.quit()

    def test_plus(self):

        calc='159+95+5=259'
        ca,res=calc.split('=')
        for c in ca:
            if c=='+':c='plus'
            self.driver.find_element_by_id("btn_%s" %c).click()
        self.driver.find_element_by_id("btn_equal").click()
        realStr=self.driver.find_elements_by_class_name("android.widget.TextView")[-2].text
        self.assertEqual(res,realStr)
if __name__=='__main__':
    si =unittest.TestLoader().loadTestsFromTestCase(TesXiaomiCalc)
    unittest.TextTestRunner(verbosity=2).run(si)

 http://www.up123.cc/22.html

相关推荐