appium服務(wù)端默認監(jiān)聽8100端口他匪,一個appiun服務(wù)端只能監(jiān)聽一臺設(shè)置末荐,想要并行測試多臺設(shè)備嚎卫,需要啟動多個appium服務(wù)栅干,監(jiān)聽不同的端口迈套,每臺設(shè)備指定一個唯一端口
配置appium服務(wù)初始化參數(shù),打開appium.txt碱鳞,在[appium_lib]添加參數(shù)port=5000桑李,可指定appium監(jiān)聽的端口
例子:
iphone 5s appium.txt:
[caps]
# 模擬器
platformName = "ios"
deviceName = "iPhone 5s"
platformVersion = "11.4"
app = "/Users/developer/Library/Developer/Xcode/DerivedData/BeiJiaFund-eesewjkcukxsbfcerpcnjtyholnv/Build/Products/Debug-iphonesimulator/BeiJiaFund.app"
automationName = "XCUITest"
[appium_lib]
port = "5000"
env.rb
equire 'rspec/expectations'
require 'appium_lib'
require 'cucumber/ast'
# Create a custom World class so we don't pollute `Object` with Appium methods
class AppiumWorld
end
# Load the desired configuration from appium.txt, create a driver then
# Add the methods to the world
# 示例一:cucumber --tags @homepage IDEVICENAME='iPhone_6' (還需要修改對應(yīng)的端口號,詳情見runsimulator文件窿给。)
# 示例二:cucumber --tags @homepage
if ENV['IDEVICENAME']=='iPhone_6'
caps = Appium.load_appium_txt file: File.expand_path("./../iPhone_6/appium.txt", __FILE__), verbose: true
elsif ENV['IDEVICENAME']=='iPhone_8'
caps = Appium.load_appium_txt file: File.expand_path("./../iPhone_8/appium.txt", __FILE__), verbose: true
elsif ENV['IDEVICENAME']=='iPhone_5s'
caps = Appium.load_appium_txt file: File.expand_path("./../iPhone_5s/appium.txt", __FILE__), verbose: true
elsif ENV['IDEVICENAME']=='iPhone_6s_Plus'
caps = Appium.load_appium_txt file: File.expand_path("./../iPhone_6s_Plus/appium.txt", __FILE__), verbose: true
else
caps = Appium.load_appium_txt file: File.expand_path('./../appium.txt', __FILE__), verbose: true
end
Appium::Driver.new(caps, true)
Appium.promote_appium_methods AppiumWorld
World do
AppiumWorld.new
end
Before { $driver.start_driver }
After { $driver.driver_quit }
執(zhí)行腳本:
1芙扎、啟動appium服務(wù)
# 參數(shù)說明:-p指定監(jiān)聽端口
# -bp:指定adb端口,Android真機測試使用
# --webdriveragent-port 指定wda端口填大,ios真機測試使用
appium -p 5000 -bp 2250 --webdriveragent-port 8100
2戒洼、執(zhí)行測試腳本
cucumber IDEVICENAME='iPhone_5s' -p iPhone_5s -f json -o ./reports/"iPhone_5s.json"
以上是一臺設(shè)備測試的例子,如果要同時在多臺設(shè)備并行測試允华,可以通過shell腳本執(zhí)行圈浇,創(chuàng)建runsimulator shell文件,編寫如下的shell腳本:
#!/usr/bin/env bash
# 并行測試腳本
# -bp:指定adb端口靴寂,Android多設(shè)備測試使用
# --webdriveragent-port 指定wda端口磷蜀,ios多設(shè)備測試使用
appium -p 5000 -bp 2250 --webdriveragent-port 8100 &
appium -p 5001 -bp 2251 --webdriveragent-port 8101 &
appium -p 5002 -bp 2252 --webdriveragent-port 8102 &
appium -p 5003 -bp 2253 --webdriveragent-port 8103 &
sleep 20
echo
if [ ! -d "reports/" ]; then
mkdir "reports/";
fi
cucumber IDEVICENAME='iPhone_8' -p iPhone_8 -f json -o ./reports/"iPhone_8.json" &
cucumber IDEVICENAME='iPhone_6' -p iPhone_6 -f json -o ./reports/"iPhone_6.json" &
cucumber IDEVICENAME='iPhone_5s' -p iPhone_5s -f json -o ./reports/"iPhone_5s.json" &
cucumber IDEVICENAME='iPhone_6s_Plus' -p iPhone_6s_Plus -f json -o ./reports/"iPhone_6s_Plus.json" &
wait %5
wait %6
wait %7
wait %8
kill -9 %1
kill -9 %2
kill -9 %3
kill -9 %4
打開終端輸入./runsimulator即可實現(xiàn)并行測試