软件测试职业探索

Appium:Python 学习 demo

2019-10-02  本文已影响0人  R_zb

使用环境:

  Python :3.7.2

  Appium:1.13.0

  设备:魅族 Pro5    (Android 5.1)    win 7 

  IDE:PyCharm

Python Demo

import unittest
from appium import webdriver
import time


class AppiumTest(unittest.TestCase):

    def setUp(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'  # 使用哪种移动平台:iOS, Android, orFirefoxOS
        desired_caps['platformVersion'] = '5.1'  # 指定平台的系统版本
        desired_caps['deviceName'] = '860BCMP22H29'  # 设备名(如:真机、模拟器等)
        desired_caps['appPackage'] = 'com.android.settings'  # 待测app的Java package(如:com.android.settings.Settings)
        desired_caps['appActivity'] = 'com.android.settings.Settings'  # 待测试的app的Activity名字
        desired_caps['noReset'] = 'True'  # 在当前session前不重置app状态
        # 配置后可输入中文
        desired_caps['unicodeKeyboard'] = 'True'  # 启用unicode输入,默认False
        desired_caps['resetKeyboard'] = 'True'  # 在运行具有unicodeKeyboard功能的Unicode测试后,将键盘重置为初始状态,如果单独使用则忽略。默认Fasle

        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

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

    def test_search(self):
        key = "无线网络"
        # 点击搜索按钮
        self.driver.find_element_by_id("com.android.settings:id/search").click()

        # 输入搜索内容
        self.driver.find_element_by_id('com.android.settings:id/mc_search_edit').send_keys(key)
        time.sleep(2)

        test = self.driver.find_element_by_id("com.android.settings:id/title").text

        self.assertEqual(test, key,msg="搜索结果检查")



if __name__ == '__main__':
    test = unittest.TestLoader().loadTestsFromTestCase(AppiumTest)
    unittest.TextTestRunner(verbosity=2).run(test)

运行结果

Python Demo运行结果

Blog:

上一篇下一篇

猜你喜欢

热点阅读