appium多設(shè)備并行測試

appium服務(wù)端默認(rèn)監(jiān)聽8100端口,一個(gè)appiun服務(wù)端只能監(jiān)聽一臺(tái)設(shè)置,想要并行測試多臺(tái)設(shè)備,需要啟動(dòng)多個(gè)appium服務(wù),監(jiān)聽不同的端口,每臺(tái)設(shè)備指定一個(gè)唯一端口

配置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'   (還需要修改對(duì)應(yīng)的端口號(hào),詳情見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、啟動(dòng)appium服務(wù)
# 參數(shù)說明:-p指定監(jiān)聽端口
# -bp:指定adb端口,Android真機(jī)測試使用
# --webdriveragent-port 指定wda端口,ios真機(jī)測試使用
appium -p 5000 -bp 2250 --webdriveragent-port 8100 

2、執(zhí)行測試腳本
cucumber IDEVICENAME='iPhone_5s' -p iPhone_5s -f json -o ./reports/"iPhone_5s.json"

以上是一臺(tái)設(shè)備測試的例子,如果要同時(shí)在多臺(tái)設(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即可實(shí)現(xiàn)并行測試

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容