環境配置

  1. 下載最新的Appium , . 我用的是appium-desktop-setup-1.8.0.exe;
  2. 下載Android Studio
  3. 安裝java jdk 1.8
  4. 安裝Python client library ,我使用的是python2.7
  5. 開啟Android Virtual Device(AVD)Manager,創建一個虛擬器;
  6. 啟動Appium Server console

第一個測試實例

  1. 獲取要測試的.apk ,將apk 放在某個文件夾下,e.g.($Directory_Of_My_Choice\apps\Chess Free.apk );
  2. 獲取AndroidManifest.xml的信息 ,用Android Studio/Build/Analyze APK 選擇你要測試的apk,查看AndroidManifest.xml的內容;** 獲取AndroidManifest.xml的信息**,用Android Studio/Build/Analyze APK 選擇你要測試的apk,查看AndroidManifest.xml的內容;
    Appium+Windows+Android+Python 第一個自動化測試實例
  3. 編寫.py測試腳本,腳本文件放在apk的上級目錄 ,e.g.(e.g.($Directory_Of_My_Choice\apps)
"""
Qxf2: Example script to run one test against the Chess Free app using Appium
The test will:
- launch the app
- click the 'PLAY!' button
"""
 
import os
import unittest
from appium import webdriver
from time import sleep
 
class ChessAndroidTests(unittest.TestCase):
    "Class to run tests against the Chess Free app"
    def setUp(self):
        "Setup for the test"
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '8.0'
        desired_caps['deviceName'] = 'Pixel'
        # Returns abs path relative to this file and not cwd
        desired_caps['app'] = os.path.abspath(os.path.join(os.path.dirname(__file__),'apps/Chess Free.apk'))
        desired_caps['appPackage'] = 'uk.co.aifactory.chessfree'
        desired_caps['appActivity'] = '.ChessFreeActivity'
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
 
    def tearDown(self):
        "Tear down the test"
        self.driver.quit()
 
    def test_single_player_mode(self):
        "Test the Chess app launches correctly and click on Play button"
        element = self.driver.find_element_by_id("uk.co.aifactory.chessfree:id/ButtonPlay")
        element.click()
        sleep(5)
 
#---START OF SCRIPT
if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(ChessAndroidTests)
    unittest.TextTestRunner(verbosity=2).run(suite)
  1. 執行腳本
  2. 查看測試結果

總結:

在編寫腳本的時候,需要用到元素定位。可以使用appium自帶的inspector
Appium+Windows+Android+Python 第一個自動化測試實例
參數配置如下圖
Appium+Windows+Android+Python 第一個自動化測試實例

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
  • 2021-05-30
  • 2021-05-11
  • 2021-04-22
  • 2022-12-23
  • 2021-10-13
猜你喜欢
  • 2021-04-15
  • 2021-08-07
  • 2021-06-14
  • 2022-01-08
  • 2022-02-16
  • 2022-12-23
  • 2021-07-08
相关资源
相似解决方案