
博客文件走為學習中心申法申法申辦
Appium是自動化iOS,Android和Windows平台上的本機,移動Web和混合應用程序的工具。它支持用Objective-C或Java或Kotlin編寫的Swift和Android本機應用程序編寫的iOS本機應用程序。它還支持使用移動瀏覽器訪問的移動Web應用程序(Appium支持iOS和Chrome上的Safari或Android上的內置“瀏覽器”應用程序)。在Lambdatest的在線雲上執行Appium自動化測試。
提示:如果您沒有任何.APK或.IPA文件,則可以使用我們的示例在Lambdatest上運行樣本測試? Android應用程序還是樣本? iOS應用。
這是Lambdatest支持的語言和框架列表,以在Lambdatest真實設備雲平台上運行Appium Automation測試。
| 爪哇 | php | 紅寶石 | C# | Python | JavaScript |
|---|---|---|---|---|---|
| 朱尼特 | php | 黃瓜 | C# | 表現 | WebDriverio |
| 機器人 |
我們支持與Appium兼容的所有語言和框架,因此,如果您的最愛不在表中。不用擔心,您仍然可以進行測試。請與我們聯繫以尋求任何幫助。
注意:我們正在為更多框架準備文檔。如果您希望我們優先考慮您首選框架的文檔,請隨時向我們大喊大叫。
使用REST API上傳您的iOS應用程序(.IPA文件)或Android應用程序(.APK文件)。您需要以格式用戶名提供用戶名和AccessKey Username:AccessKey供身份驗證的curl命令中的AccessKey。確保在捲曲請求中添加AppFile的路徑。這是使用我們的REST API上傳您的應用程序的示例curl請求:
對於MacOS/Linux:
curl - u "{username}:{accesskey}"
-- location -- request POST 'https: //manual-api.lambdatest.com/app/upload/realDevice'
-- form 'name="Android_App"'
-- form 'appFile=@"/Users/{desktop_username}/Desktop/LT_Java_Appium/proverbial_android.apk"'對於Windows:
curl - u "{username}:{accesskey}" - X POST "https://manual-api.lambdatest.com/app/upload/realDevice" - F "appFile=@" / Users / Desktop_username / Desktop / LT_Java_Appium / proverbial_android . apk ""使用應用程序:
對於MacOS/Linux:
curl - u "${ YOUR_LAMBDATEST_USERNAME()}:${ YOUR_LAMBDATEST_ACCESS_KEY()}"
-- location -- request POST 'https: //manual-api.lambdatest.com/app/upload/realDevice'
-- form 'name="Android_App"'
-- form 'url="https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk"'對於Windows:
curl - u "${ YOUR_LAMBDATEST_USERNAME()}:${ YOUR_LAMBDATEST_ACCESS_KEY()}"
- X POST "https://manual-api.lambdatest.com/app/upload/realDevice"
- d "{"url":"https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk",
"name":"sample.apk"'信息注意:
上述捲曲的響應將是一個JSON對象,其中包含格式-LT的App URL -LT:// APP123456789123456789,將在下一步中使用。
這是Java中下載的示例應用程序的示例自動化腳本。確保在以下代碼中更新app_url , username和accesskey 。
import io . appium . java_client . AppiumDriver ;
import io . appium . java_client . MobileBy ;
import io . appium . java_client . MobileElement ;
import io . appium . java_client . android . AndroidElement ;
import org . openqa . selenium . remote . DesiredCapabilities ;
import org . openqa . selenium . support . ui . ExpectedConditions ;
import org . openqa . selenium . support . ui . WebDriverWait ;
import java . net . URL ;
import java . util . List ;
public class AndroidApp {
public static String userName = "username" ; //Enter your LT Username here
public static String accessKey = "accesskey" ; //Enter your LT AccessKey here
public String gridURL = "@mobile-hub.lambdatest.com/wd/hub" ;
String DeviceValue ;
String versionValue ;
String PlatformValue ;
@ org . testng . annotations . Parameters ( value = { "device" , "version" , "platform" })
public AndroidApp ( String device , String version , String platform ) {
try {
DeviceValue = device ;
versionValue = version ;
PlatformValue = platform ;
DesiredCapabilities capabilities = new DesiredCapabilities ();
capabilities . setCapability ( "build" , "ParallelSample Android" );
capabilities . setCapability ( "name" , platform + " " + device + " " + version );
capabilities . setCapability ( "deviceName" , device );
capabilities . setCapability ( "platformVersion" , version );
capabilities . setCapability ( "platformName" , platform );
capabilities . setCapability ( "isRealMobile" , true );
//AppURL (Create from Wikipedia.apk sample in project)
capabilities . setCapability ( "app" , "app url" ); //Enter your app URL from previous step here
capabilities . setCapability ( "deviceOrientation" , "PORTRAIT" );
capabilities . setCapability ( "console" , true );
capabilities . setCapability ( "network" , true );
capabilities . setCapability ( "visual" , true );
capabilities . setCapability ( "devicelog" , true );
String hub = "https://" + userName + ":" + accessKey + gridURL ;
AppiumDriver driver = new AppiumDriver ( new URL ( hub ), capabilities );
MobileElement color = ( MobileElement ) driver . findElementById ( "com.lambdatest.proverbial:id/color" );
//Changes color
color . click ();
//Back to black color
color . click ();
MobileElement text = ( MobileElement ) driver . findElementById ( "com.lambdatest.proverbial:id/Text" );
//Changes the text to proverbial
text . click ();
//toast is visible
MobileElement toast = ( MobileElement ) driver . findElementById ( "com.lambdatest.proverbial:id/toast" );
toast . click ();
//notification is visible
MobileElement notification = ( MobileElement ) driver . findElementById ( "com.lambdatest.proverbial:id/notification" );
notification . click ();
//Open the geolocation page
MobileElement geo = ( MobileElement ) driver . findElementById ( "com.lambdatest.proverbial:id/geoLocation" );
geo . click ();
Thread . sleep ( 5000 );
//takes back to home page
MobileElement home = ( MobileElement ) driver . findElementByAccessibilityId ( "Home" );
home . click ();
//Takes to speed test page
MobileElement speedtest = ( MobileElement ) driver . findElementById ( "com.lambdatest.proverbial:id/speedTest" );
speedtest . click ();
Thread . sleep ( 5000 );
MobileElement el10 = ( MobileElement ) driver . findElementByXPath ( "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.view.ViewGroup/android.widget.RelativeLayout/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.RelativeLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[1]/android.view.View[3]/android.view.View[1]/android.view.View/android.widget.Button" );
el10 . click ();
Thread . sleep ( 25000 );
MobileElement el11 = ( MobileElement ) driver . findElementByXPath ( "//android.widget.FrameLayout[@content-desc= " Home " ]/android.widget.FrameLayout/android.widget.ImageView" );
el11 . click ();
//Opens the browser
MobileElement browser = ( MobileElement ) driver . findElementByAccessibilityId ( "Browser" );
browser . click ();
MobileElement el13 = ( MobileElement ) driver . findElementById ( "com.lambdatest.proverbial:id/url" );
el13 . sendKeys ( "www.lambdatest.com" );
MobileElement el14 = ( MobileElement ) driver . findElementById ( "com.lambdatest.proverbial:id/find" );
el14 . click ();
driver . quit ();
} catch ( Exception t ) {
System . out . println ();
}
}
} import io . appium . java_client . AppiumDriver ;
import io . appium . java_client . MobileElement ;
import org . openqa . selenium . JavascriptExecutor ;
import org . openqa . selenium . remote . DesiredCapabilities ;
import java . net . URL ;
public class iOSApp {
public static String userName = "username" ; //Enter your LT Username here
public static String accessKey = "accesskey" ; //Enter your LT AccessKey here
public String gridURL = "@mobile-hub.lambdatest.com/wd/hub" ;
String DeviceValue ;
String versionValue ;
String PlatformValue ;
AppiumDriver driver ;
@ org . testng . annotations . Parameters ( value = { "device" , "version" , "platform" })
public iOSApp ( String device , String version , String platform ) {
try {
DeviceValue = device ;
versionValue = version ;
PlatformValue = platform ;
DesiredCapabilities capabilities = new DesiredCapabilities ();
capabilities . setCapability ( "build" , "ParallelSample iOS" );
capabilities . setCapability ( "name" , platform + " " + device + " " + version );
capabilities . setCapability ( "deviceName" , device );
capabilities . setCapability ( "platformVersion" , version );
capabilities . setCapability ( "platformName" , platform );
capabilities . setCapability ( "isRealMobile" , true );
//AppURL (Create from proverbial.ipa sample in project)
capabilities . setCapability ( "app" , "app url" ); //Enter your app URL from previous step here
capabilities . setCapability ( "deviceOrientation" , "PORTRAIT" );
capabilities . setCapability ( "console" , true );
capabilities . setCapability ( "network" , true );
capabilities . setCapability ( "visual" , true );
capabilities . setCapability ( "devicelog" , true );
//capabilities.setCapability("geoLocation", "HK");
String hub = "https://" + userName + ":" + accessKey + gridURL ;
driver = new AppiumDriver ( new URL ( hub ), capabilities );
MobileElement color = ( MobileElement ) driver . findElementByAccessibilityId ( "Colour" );
//Changes color
color . click ();
//Back to black color
color . click ();
MobileElement text = ( MobileElement ) driver . findElementByAccessibilityId ( "Text" );
//Changes the text to proverbial
text . click ();
//toast is visible
MobileElement toast = ( MobileElement ) driver . findElementByAccessibilityId ( "Toast" );
toast . click ();
//notification is visible
MobileElement notification = ( MobileElement ) driver . findElementByAccessibilityId ( "Notification" );
notification . click ();
//Open the geolocation page
MobileElement geo = ( MobileElement ) driver . findElementByAccessibilityId ( "GeoLocation" );
geo . click ();
Thread . sleep ( 5000 );
//Takes back
driver . navigate (). back ();
//Takes to speed test page
MobileElement speedtest = ( MobileElement ) driver . findElementByAccessibilityId ( "Speed Test" );
speedtest . click ();
Thread . sleep ( 5000 );
MobileElement el10 = ( MobileElement ) driver . findElementByAccessibilityId ( "start speed test - connection type multi" );
el10 . click ();
Thread . sleep ( 25000 );
driver . navigate (). back ();
//Opens the browser
MobileElement browser = ( MobileElement ) driver . findElementByAccessibilityId ( "Browser" );
browser . click ();
Thread . sleep ( 3000 );
MobileElement el4 = ( MobileElement ) driver . findElementByAccessibilityId ( "Search" );
el4 . click ();
el4 . sendKeys ( "Lambdatest" );
(( JavascriptExecutor ) driver ). executeScript ( "lambda-status=passed" );
driver . quit ();
} catch ( Exception t ) {
System . out . println ();
(( JavascriptExecutor ) driver ). executeScript ( "lambda-status=failed" );
driver . quit ();
}
}
}.XML文件以運行測試並定義設備功能。請在下面找到示例代碼。 <? xml version = " 1.0 " encoding = " UTF-8 " ?>
<! DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
< suite thread-count = " 100 " name = " Mobile " parallel = " tests " >
< test name = " AppTest 1 " >
< parameter name = " version " value = " 11 " />
< parameter name = " platform " value = " Android " />
< parameter name = " device " value = " Galaxy S21 Ultra 5G " />
< classes >
< class name = " AndroidApp " />
</ classes >
</ test >
< test name = " AppTest 2 " >
< parameter name = " version " value = " 11 " />
< parameter name = " platform " value = " Android " />
< parameter name = " device " value = " Galaxy S21 " />
< classes >
< class name = " AndroidApp " />
</ classes >
</ test >
</ suite ><? xml version = " 1.0 " encoding = " UTF-8 " ?>
<! DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
< suite thread-count = " 100 " name = " Mobile " parallel = " tests " >
< test name = " iOSApp 1 " >
< parameter name = " version " value = " 14 " />
< parameter name = " platform " value = " iOS " />
< parameter name = " device " value = " iPhone 11 " />
< classes >
< class name = " iOSApp " />
</ classes >
</ test >
< test name = " iOSApp 2 " >
< parameter name = " version " value = " 14 " />
< parameter name = " platform " value = " iOS " />
< parameter name = " device " value = " iPhone 12 Pro " />
< classes >
< class name = " iOSApp " />
</ classes >
</ test >
</ suite >調試並運行您的代碼。在編輯器中運行iOSApp.java或AndroidApp.java 。
運行測試後,您可以與日誌一起查看測試執行。您將能夠看到通過或失敗的測試用例。您可以在Lambdatest自動化上查看相同的內容。
下面提到了Android和iOS的樣本功能 -
{
"deviceName" : "Galaxy Tab S4" ,
"platformName" : "android" ,
"platformVersion" : "10" ,
"app" : "App_url" ,
"visual" : True ,
"console" : True ,
"deviceOrientation" : "PORTRAIT" ,
"build" : "new-12" ,
"isRealMobile" : True ,
} {
"deviceName": "iPhone 12 Mini",
"platformName": "ios",
"platformVersion": "14",
"app": "App_url",
"isRealMobile": True,
"visual": True,
"console": True,
"build": "lt-web-4",
"network": True,
}
注意:強制性字段用星號標記 *
| 鑰匙 | 值 | 能力描述 |
|---|---|---|
| *用戶 | 類型:字符串 | 您的LT用戶名。 |
| *AccessKey | 類型:字符串 | 您的LT訪問密鑰。 |
| 建造 | 類型:字符串 默認值:無標題 build=iOS Small Run | 您可以像包含多個測試的作業一樣對測試進行分組。 |
| 姓名 | 類型:字符串 默認值:測試的測試。如果名稱未傳遞。 name=iphone 6 Small Run | 測試名稱。 |
| 專案 | 如果“項目”不通過功能,將保持空白。project=Small Run | 您可以像包含多個作業的項目一樣對構建進行分組。 |
| *devicename | 類型:字符串iPhone 13 | 設備的名稱。 |
| *PlatformName | 類型:字符串ios | 操作系統的名稱。 |
| *PlatformVersion | 類型:字符串14 | OS版本。 |
| *應用程式 | 類型:字符串app=lt://APP100201061631704657918380 | 在將應用程序上傳到lambdatest服務器上後,接受應用程序URL。 |
| queueTimeout | 類型:字符串 默認值:600 queueTimeout=300 | 該功能可用於修改範圍內的隊列超時值。 QueUtimeOut範圍:300-900。 |
| idletimeout | 類型:字符串 默認值:120 idleTimeout=120 | 此功能可用於修改超時值。 |
| 視覺的 | 類型:布爾值 默認值:false visual=TRUE或者 visual=FALSE | 命令屏幕截圖將在每個測試步驟中記錄。默認情況下,將標誌設置為關閉。注意:如果將其設置為“ true”,則測試執行時間將增加。 |
| 影片 | 類型:布爾值 默認值:true video=TRUE或者 video=FALSE | 完整屏幕的視頻錄製。 |
| Devicelog | 類型:布爾值 默認值:true devicelog=TRUE或者 devicelog=FALSE | 啟用設備日誌。 |
| 網絡 | 類型:布爾值 默認值:true network=TRUE或者 network=FALSE | 啟用網絡日誌。 |
| 設備方向 | 類型:字符串deviceOrientation=portrait或者 deviceOrientation=landscape | 更改設備的屏幕方向。 |
| 隧道 | 類型:布爾值tunnel=TRUE或者 tunnel=FALSE | 用lambdatest測試本地應用。 |
| 隧道名稱 | 類型:布爾值tunnelName=RabbitHole | 隧道的名稱。 |
| 專用二氧化碳 | 類型:布爾值dedicatedProxy=TRUE或者 dedicatedProxy=FALSE | 專用代理。 |
| 自動競爭 | 類型:布爾值autoGrantPermissions=TRUE或者 autoGrantPermissions=FALSE | 讓Appium自動確定您的應用程序所需的權限,並在安裝時授予應用程序。默認為false。如果Noreset是正確的,則此功能不起作用。 |
| AutoDismissAlerts | 類型:布爾值autoDismissAlerts=TRUE或者 autoDismissAlerts=FALSE | [僅iOS] Appium功能可以駁斥iOS設備上的警報/彈出窗口。 |
| AutoAcceptAlerts | 類型:布爾值autoAcceptAlerts=TRUE或者 autoAcceptAlerts=FALSE | [僅iOS] Appium功能可以接受iOS設備上的警報/彈出窗口。 |
| newCommandTimeOut | 類型:字符串60 | 在假設客戶端退出並結束會話之前,(幾秒鐘內)Appium將等待客戶的新命令。 |
| 語言 | 類型:字符串fr | 為iOS設置的語言(僅Xcuitest驅動程序)和Android。 |
| 語言環境 | 類型:字符串fr_CA, CA | 為iOS設置的區域(僅Xcuitest驅動程序)和Android。 iOS的FR_CA格式。 CA格式(國家名稱縮寫)。 |
| 諾雷斯 | 類型:布爾值true | 在此會話之前請勿重置應用程序狀態。有關更多詳細信息,請參見此處。 |
| AutomationName | 類型:布爾值 默認值:appium automationName = Appium | 要使用哪種自動化引擎。注意:在應用程序自動化代碼中設置為false,因此無法更改。 appium(默認)或uiautomator2,濃縮咖啡或uiautomator1 for android,Xcuitest或iOS儀器,或用YouIengine構建的應用程序。 |
| 事件激烈 | 類型:布爾值 默認值:false true | 啟用或禁用各種appium內部事件的時間安排報告(例如,每個命令的開始和結尾等)。為了啟用,請使用true。然後,將這些定時報告為響應查詢當前會話時的事件屬性。有關此響應的結構,請參見事件正時文檔。 |
| 地理位置 | 類型:字符串fr | 允許您通過選擇在全球多個國家 /地區託管的IP地址來模擬不同位置的移動行為。 |
| 其他應用 | 類型:字符串數組 默認值:[]或空數組 "otherApps":["lt://APP1002211081648217405891389","lt://APP1002211081648217429465823"] | “接受在Lambdatest服務器上上傳應用程序後返回的應用URL列表。 要滿足的條件: 1。如果通過“其他應用程序”,也應通過應用程序。 2。應用程序的長度 數組<= 3。 3。在最大3個其他應用程序中可以安裝。 4。不應在“其他應用程序”數組中存在應用程序。 5。在“其他應用程序”陣列中沒有重複。 ” |
有任何問題嗎?請在我們的24x7聊天支持下與您聯繫,也可以通過[email protected]寄給我們。
使用Lambdatest隧道,您可以在Lambdatest Appium Test Automation平台上進行本地和私有託管應用程序測試。 Lambdatest Tunnel使用Web套接字,HTTPS,SSH(安全殼)等協議,以便您在本地系統和Lambdatest Cloud Server之間構建安全且獨特的隧道連接。
在本文檔中,學習如何在執行移動應用自動化時配置Lambdatest隧道以測試本地或私有託管應用程序。
要在本地測試應用程序,您需要配置:
與Lambdatest隧道的連接。
測試腳本通過Lambdatest隧道運行。
下面顯示的是將連接與Lambdatest隧道配置的步驟。
提取下載的二進製文件。
導航到命令提示符,並指向您提取二進製文件的目錄/文件夾。
在終端中運行以下命令。
. / LT -- user { user 's login email} --key {user' s access key } -- tunnelName { user 's tunnel name}與Lambdatest隧道配置連接後,您需要將功能tunnel設置為True 。
| 鑰匙 | 值 | 描述 | 所需的能力 |
|---|---|---|---|
| 隧道 | 是/錯誤 | 配置隧道 | "tunnel" : True, |
您還可以使用lambdatest功能生成器添加tunnel功能。
如果您有任何疑問或需要任何其他信息,請通過我們的24x7聊天支持或直接通過[email protected]寄給我們。
GUI檢查員用於移動應用程序,以及更多由(單獨安裝) Appium服務器提供支持的GUI檢查員。 Appium Inspector是Appium客戶端(例如WebDriverio,Appium的Java客戶端,Appium的Python客戶端等)。我們可以使用該接口來指定Appium Server版本,設置功能。 Appium Server啟動並使用該應用程序運行後,我們可以與元素進行交互並運行其他Appium命令。
到本主題結束時,您將能夠:
使用REST API上傳您的iOS應用程序(.IPA文件)或Android應用程序(.APK文件)。您需要以格式用戶名提供用戶名和AccessKey Username:AccessKey供身份驗證的curl命令中的AccessKey。確保在捲曲請求中添加AppFile的路徑。這是使用我們的REST API上傳您的應用程序的示例curl請求:
使用應用程序:
對於iOS:
curl - u "{usename}:{accesskey}"
-- location -- request POST 'https: //manual-api.lambdatest.com/app/upload/realDevice'
-- form 'name="Android_App"'
-- form 'url="https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk"'對於Windows:
curl - u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" - X POST "https://manual-api.lambdatest.com/app/upload/realDevice" - F "appFile=@" / Users / macuser / Downloads / proverbial_android . apk "'使用應用程序:
對於MacOS/Linux:
curl - u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY"
-- location -- request POST 'https: //manual-api.lambdatest.com/app/upload/realDevice'
-- form 'name="Android_App"'
-- form 'url="https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk"'對於Windows:
curl - u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" - X POST "https://manual-api.lambdatest.com/app/upload/realDevice" - d "url":"https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk","name":"sample.apk"'提示:
App URL -LT:// APP123456789123456789,將在下一步中使用。從雲測試提供商列表中啟動Appium Inspector並選擇Lambdatest。
輸入您的用戶名和訪問密鑰。您可能會在lambdatest儀表板上找到可用的憑據
在Appium Inspector上的“所需功能”選項卡中配置Lambdatest功能。使用步驟1中獲得的唯一應用URL來設置應用程序功能值。 Lambdatest支持的所有功能的列表可在此處獲得
另外,我們也可以轉到我們的功能生成器並使用GUI生成功能表示。

完成此操作後,您現在可以通過單擊“開始”會話來運行測試。開始會話後,將在lambdatest儀表板上提供視頻錄製以及測試運行的詳細信息和日誌。

有任何問題嗎?
請在我們的24x7聊天支持下與您聯繫,也可以通過[email protected]寄給我們。
在此文檔中,我們查看一些API,可以幫助您優化移動應用測試工作流程。如果要執行實時或自動化應用測試,則可以使用這些API來獲取和刪除應用程序。
要獲取上傳應用程序的列表以及其應用ID,請運行以下curl命令。
curl -- location -- request GET 'https://YOUR_LAMBDATEST_USERNAME:[email protected]/app/data?type=ios&level=user'下面顯示的是對上述捲曲請求的響應。
{ "metaData" : { "type" : "ios" , "total" : 1 } ,
"data" : [ {
"app_id" : "APP100245789181570497850" ,
"name" : "proverbial_ios.ipa" ,
"type" : "ios" ,
"updated_at" : "2022-05-10T11:19:30.000Z" ,
"shared" : false ,
"source" : "web-client"
} ] 要刪除您的升壓應用程序,請運行以下curl命令。
curl -- location -- request DELETE 'https: //YOUR_LAMBDATEST_USERNAME:[email protected]/app/delete'
-- header 'Content-Type: application/json'
-- data - raw ' {
"appIds" : "APPID1,APPID2"
} '下面顯示的是對上述捲曲請求的響應。
{ "message" : "Deleted successfully." }就這樣!如果您有任何疑問或需要任何其他信息,則可以通過我們的24x7聊天支持與我們聯繫,或直接通過[email protected]郵寄我們。
Lambdatest提供了在線Appium自動化網格,以執行應用程序自動化。在線Appium Grid可在本地網格,瀏覽,碟形舞會和Lambdatest上找到。因此,您可以輕鬆地將當前的Appium自動化腳本(或套件)從本地網格,醬汁實驗室或Browserstack遷移到Lambdatest。
在本文檔中,我們查看如何利用lambdatest雲進行應用自動化,並從當地網格,醬汁實驗室或瀏覽器中遷移測試腳本(或測試套件)。您可以在測試中使用Lambdatest的所需功能,對測試會話進行身份驗證,並在雲上執行測試。
將您當前的本地網格,Browesestack或Sauce Labs測試遷移到Lambdatest,需要在您的代碼中進行一些調整。在本指南中,我們將查看如何在測試中利用Lambdatest所需的功能,對您的測試會話進行身份驗證並在我們的雲瀏覽器上執行測試。
要從當地的網格,Browesestack或Sauce Labs轉移到Lambdatest,您需要對測試套件進行一些更改,例如身份驗證,所需功能等。
首先,您需要在測試套件的配置設置中更改身份驗證。要在Lambdatest Appium網格上運行測試,您需要具有有效的user_name和access_key來在我們的云網格上執行測試。如果您在Lambdatest上沒有帳戶,請訪問Lambdatest註冊頁面並創建一個新帳戶。
以下是參數的變化:
您可以在自動化儀表板的“ lambdatest”部分中找到Username和Access Key 。

當從瀏覽巨星或索環遷移到lambdatest時,您需要在現有代碼中進行以下更改:
這是我們上面突出顯示的每個字段的並排比較:
| 財產 | 類型 | Browserstack | 索環 | lambdatest |
|---|---|---|---|---|
| 使用者名稱 | 細繩 | 訪問browserstack上appium網格的用戶名 | 用戶名訪問醬汁實驗室的appium網格 | 用戶名訪問lambdatest上的appium網格 |
| AccessKey | 細繩 | AccessKey在Browserstack上訪問Appium Grid | 訪問在醬汁實驗室上訪問Appium網格的訪問關節 | 在lambdatest上訪問appium網格的訪問關鍵 |
| 集線器URL | 細繩 | @hub-cloud.browserstack.com/wd/hub | ondemand.us-west-1.saucelabs.com/wd/hub | @hub.lambdatest.com/wd/hub |
對於基於Python的實現,以下是身份驗證過程的腳本中的更改。
Browserstack
userName = "BrowserStack_UserName"
accessKey = "BrowserStack_AccessKey"索環
userName = "SAUCE_USERNAME"
accessKey = "SAUCE_ACCESS_KEY"lambdatest
userName = "LambdaTest_UserName"
accessKey = "LambdaTest_AccessKey"現在,您必須在測試套件的配置設置中修改輪轂URL。輪轂URL是字符串類型的,並指定了將為Appium測試路由執行的集線器位置。
對於基於Python的實現,以下是Hub URL腳本的更改。
Browserstack
@hub-cloud.browserstack.com/wd/hub
索環
@ondemand.us-west-1.saucelabs.com/wd/hub
lambdatest
@mobile-hub.lambdatest.com/wd/hub
功能生成器允許您指定所需的功能(或功能),這些功能是配置選項,允許您指定以下內容:
您還可以選擇Lambdatest功能生成器中可用的其他高級選項。
對於遷移,我們進行了基於Java的Appium測試。以下是Browserstack和Lambdatest的功能生成器的屏幕截圖。



Browserstack和Lambdatest功能生成器生成的功能的比較:
| 功能 | Browserstack | 索環 | lambdatest |
|---|---|---|---|
| 裝置 | 裝置 | Devicename | Devicename |
| 作業系統 | OS_Version | 平台Version | 平台Version |
以下是概述Java語言所需功能的比較:
Browserstack
//demo.java
DesiredCapabilities capabilities = new DesiredCapabilities ( ) ;
capabilities . setCapability ( "os_version" , "9.0" ) ;
capabilities . setCapability ( "device" , "Google Pixel 3" ) ;
capabilities . setCapability ( "browserstack.appium_version" , "1.21.0" ) ;索環
//demo.java
MutableCapabilities caps = new MutableCapabilities ();
caps . setCapability ( "platformName" , "Android" );
caps . setCapability ( "browserName" , "Chrome" );
caps . setCapability ( "appium:deviceName" , "Google Pixel 3 GoogleAPI Emulator" );
caps . setCapability ( "appium:platformVersion" , "12.0" );
MutableCapabilities sauceOptions = new MutableCapabilities ();
sauceOptions . setCapability ( "appiumVersion" , "1.21.0" );
caps . setCapability ( "sauce:options" , sauceOptions );lambdatest
//demo.java
DesiredCapabilities capabilities = new DesiredCapabilities ( ) ;
capabilities . setCapability ( "build" , "your build name" ) ;
capabilities . setCapability ( "name" , "your test name" ) ;
capabilities . setCapability ( "platformName" , "Android" ) ;
capabilities . setCapability ( "deviceName" , "Google Pixel 3" ) ;
capabilities . setCapability ( "isRealMobile" , true ) ;
capabilities . setCapability ( "platformVersion" , "9" ) ;讓我們看一個示例,顯示整個遷移過程。測試方案是打開一個搜索“ lambdatest”一詞的Wikipedia應用程序。以下測試在Google Pixel 3運行Android 11上進行。
from appium import webdriver
from appium . webdriver . common . mobileby import MobileBy
from selenium . webdriver . support . ui import WebDriverWait
from selenium . webdriver . support import expected_conditions as EC
import time
userName = "BrowserStack_UserName"
accessKey = "BrowserStack_AccessKey"
desired_caps = {
"build" : "Python Android" ,
"device" : "Google Pixel 3" ,
"app" : "<app_url>"
}
driver = webdriver . Remote ( "https://" + userName + ":" + accessKey + "@hub-cloud.browserstack.com/wd/hub" , desired_caps )
search_element = WebDriverWait ( driver , 30 ). until (
EC . element_to_be_clickable (( MobileBy . ACCESSIBILITY_ID , "Search Wikipedia" ))
)
search_element . click ()
search_input = WebDriverWait ( driver , 30 ). until (
EC . element_to_be_clickable (( MobileBy . ID , "org.wikipedia.alpha:id/search_src_text" ))
)
search_input . send_keys ( "BrowserStack" )
time . sleep ( 5 )
search_results = driver . find_elements_by_class_name ( "android.widget.TextView" )
assert ( len ( search_results ) > 0 )
driver . quit () #samplewikipedia.py
import ssl
try :
_create_unverified_https_context = ssl . _create_unverified_context
except AttributeError :
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else :
# Handle target environment that doesn't support HTTPS verification
ssl . _create_default_https_context = _create_unverified_https_context
from threading import Thread
import time
from selenium import webdriver
from selenium . webdriver . common . keys import Keys
from selenium . webdriver . common . desired_capabilities import DesiredCapabilities
from selenium . common . exceptions import TimeoutException
from selenium . webdriver . support . ui import WebDriverWait
from selenium . webdriver . support import expected_conditions as EC
from appium . webdriver . common . mobileby import MobileBy
from appium import webdriver
# This array 'caps' defines the capabilities browser, device and OS combinations where the test will run
caps = {
caps [ 'platformName' ] = 'Android'
caps [ 'browserName' ] = 'Chrome'
caps [ 'appium:deviceName' ] = 'Google Pixel 3a GoogleAPI Emulator'
caps [ 'appium:platformVersion' ] = '11.0'
caps [ 'sauce:options' ] = {}
caps [ 'sauce:options' ][ 'appiumVersion' ] = '1.20.2'
}
# run_session function searches for 'saucelabs' on google.com
def run_session ( desired_cap ):
driver = webdriver . Remote (
command_executor = "https://SAUCE_USERNAME:[email protected]/wd/hub" ,
desired_capabilities = desired_cap )
# driver.get("https://www.ifconfig.me")
# time.sleep(10)
# Test case for the saucelabs sample Android app.
# If you have uploaded your app, update the test case here.
search_element = WebDriverWait ( driver , 30 ). until (
EC . element_to_be_clickable (
( MobileBy . ACCESSIBILITY_ID , "Search Wikipedia" ))
)
search_element . click ()
search_input = WebDriverWait ( driver , 30 ). until (
EC . element_to_be_clickable (
( MobileBy . ID , "org.wikipedia.alpha:id/search_src_text" ))
)
search_input . send_keys ( "saucelabs" )
time . sleep ( 5 )
search_results = driver . find_elements_by_class_name (
"android.widget.TextView" )
assert ( len ( search_results ) > 0 )
# Invoke driver.quit() after the test is done to indicate that the test is completed.
driver . quit ()
# The Thread function takes run_session function and each set of capability from the caps array as an argument to run each session in parallel
for cap in caps :
Thread ( target = run_session , args = ( cap ,)). start () #samplewikipedia.py
import ssl
try :
_create_unverified_https_context = ssl . _create_unverified_context
except AttributeError :
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else :
# Handle target environment that doesn't support HTTPS verification
ssl . _create_default_https_context = _create_unverified_https_context
from threading import Thread
import time
from selenium import webdriver
from selenium . webdriver . common . keys import Keys
from selenium . webdriver . common . desired_capabilities import DesiredCapabilities
from selenium . common . exceptions import TimeoutException
from selenium . webdriver . support . ui import WebDriverWait
from selenium . webdriver . support import expected_conditions as EC
from appium . webdriver . common . mobileby import MobileBy
from appium import webdriver
# This array 'caps' defines the capabilities browser, device and OS combinations where the test will run
caps = [
{
"deviceName" : "Google Pixel 3" ,
"platformName" : "Android" ,
"platformVersion" : "11" ,
"app" : "<lt_app_url>" ,
"isRealMobile" : True ,
"deviceOrientation" : "PORTRAIT" ,
"build" : "Demo" ,
},
]
# run_session function searches for 'lambtest' on google.com
def run_session ( desired_cap ):
driver = webdriver . Remote (
# hub.mobile-dev-1.dev.lambdatest.io/wd/hub",
command_executor = "https://LT_USERNAME:[email protected]/wd/hub" ,
desired_capabilities = desired_cap )
# driver.get("https://www.ifconfig.me")
# time.sleep(10)
# Test case for the lambdatest sample Android app.
# If you have uploaded your app, update the test case here.
search_element = WebDriverWait ( driver , 30 ). until (
EC . element_to_be_clickable (
( MobileBy . ACCESSIBILITY_ID , "Search Wikipedia" ))
)
search_element . click ()
search_input = WebDriverWait ( driver , 30 ). until (
EC . element_to_be_clickable (
( MobileBy . ID , "org.wikipedia.alpha:id/search_src_text" ))
)
search_input . send_keys ( "lambdatest" )
time . sleep ( 5 )
search_results = driver . find_elements_by_class_name (
"android.widget.TextView" )
assert ( len ( search_results ) > 0 )
# Invoke driver.quit() after the test is done to indicate that the test is completed.
driver . quit ()
# The Thread function takes run_session function and each set of capability from the caps array as an argument to run each session in parallel
for cap in caps :
Thread ( target = run_session , args = ( cap ,)). start ()如上所示,大多數實施都保持不變。僅對基礎架構進行更改(即而不是Browserstack,應用程序自動化測試將在lambdatest上進行)。
讓我們分析從實施的角度發生了什麼變化。
Browserstack
from appium import webdriver
from appium . webdriver . common . mobileby import MobileBy
from selenium . webdriver . support . ui import WebDriverWait
from selenium . webdriver . support import expected_conditions as EC
import time
userName = "BrowserStack_UserName"
accessKey = "BrowserStack_AccessKey"
desired_caps = {
"build" : "Python Android" ,
"device" : "Google Pixel 3" ,
"app" : "<app_url>"
}
driver = webdriver . Remote ( "https://" + userName + ":" + accessKey + "@hub-cloud.browserstack.com/wd/hub" , desired_caps )索環
from threading import Thread
import time
from selenium import webdriver
from selenium . webdriver . common . keys import Keys
from selenium . webdriver . common . desired_capabilities import DesiredCapabilities
from selenium . common . exceptions import TimeoutException
from selenium . webdriver . support . ui import WebDriverWait
from selenium . webdriver . support import expected_conditions as EC
from appium . webdriver . common . mobileby import MobileBy
from appium import webdriver
# This array 'caps' defines the capabilities browser, device and OS combinations where the test will run
caps = {
caps [ 'platformName' ] = 'Android'
caps [ 'browserName' ] = 'Chrome'
caps [ 'appium:deviceName' ] = 'Google Pixel 3a GoogleAPI Emulator'
caps [ 'appium:platformVersion' ] = '11.0'
caps [ 'sauce:options' ] = {}
caps [ 'sauce:options' ][ 'appiumVersion' ] = '1.20.2'
}
# run_session function searches for 'saucelabs' on google.com
def run_session ( desired_cap ):
driver = webdriver . Remote (
command_executor = "https://SAUCE_USERNAME:[email protected]/wd/hub" ,
desired_capabilities = desired_cap )lambdatest
from threading import Thread
import time
from selenium import webdriver
from selenium . webdriver . common . keys import Keys
from selenium . webdriver . common . desired_capabilities import DesiredCapabilities
from selenium . common . exceptions import TimeoutException
from selenium . webdriver . support . ui import WebDriverWait
from selenium . webdriver . support import expected_conditions as EC
from appium . webdriver . common . mobileby import MobileBy
from appium import webdriver
caps = [
{
"deviceName" : "Google Pixel 3" ,
"platformName" : "Android" ,
"platformVersion" : "11" ,
"app" : "<lt_app_url>" ,
"build" : "Demo" ,
},
]
def run_session ( desired_cap ):
driver = webdriver . Remote ( command_executor = "https://LT_USERNAME:[email protected]/wd/hub" , desired_capabilities = desired_cap )我們已經討論瞭如何從醬汁實驗室或瀏覽器遷移到Lambdatest。讓我們探索如何從本地網格遷移到基於雲的Appium網格。
Appium所需的功能是包裹在JSON對像中的鍵值對的集合。這些鍵值配對請求Appium服務器進行所需的測試自動化會話。
假設您想在Samsung Galaxy Tab S4運行Android 10的Python中運行APP測試。您可以以下面給出的功能形式定義相同的定義。
caps = [
{
"deviceName" : "Galaxy Tab S4" ,
"platformName" : "Android" ,
"platformVersion" : "10" ,
"build" : "Demo" ,
},
]首先,在測試套件的配置設置中更改身份驗證。要在Lambdatest Appium網格上運行測試,您需要一個有效的用戶名和訪問密鑰。如果您已經在本地網格上進行了測試,則需要修改測試腳本以初始化Appium驅動程序以及所需的功能。
將功能傳遞給@hub.lambdatest.com/wd/hub並帶有您的lambdatest身份驗證詳細信息,您就完成了。這是示例Python測試腳本。
#samplewikipedia.py
import ssl
try :
_create_unverified_https_context = ssl . _create_unverified_context
except AttributeError :
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else :
# Handle target environment that doesn't support HTTPS verification
ssl . _create_default_https_context = _create_unverified_https_context
from threading import Thread
import time
from selenium import webdriver
from selenium . webdriver . common . keys import Keys
from selenium . webdriver . common . desired_capabilities import DesiredCapabilities
from selenium . common . exceptions import TimeoutException
from selenium . webdriver . support . ui import WebDriverWait
from selenium . webdriver . support import expected_conditions as EC
from appium . webdriver . common . mobileby import MobileBy
from appium import webdriver
# This array 'caps' defines the capabilities of the browser, device, and OS combinations where the test will run
caps = [
{
"deviceName" : "Galaxy Tab S4" ,
"platformName" : "Android" ,
"platformVersion" : "10" ,
"app" : "lt://APP10051525539885437397" ,
"isRealMobile" : True ,
"deviceOrientation" : "PORTRAIT" ,
"visual" : True ,
"console" : True ,
"build" : "Demo" ,
},
]
# run_session function searches for 'lambdatest' on google.com
def run_session ( desired_cap ):
driver = webdriver . Remote (
# hub.mobile-dev-1.dev.lambdatest.io/wd/hub",
command_executor = "https://LT_USERNAME:[email protected]/wd/hub" ,
desired_capabilities = desired_cap )
# driver.get("https://www.ifconfig.me")
# time.sleep(10)
# Test case for the lambdatest sample Android app.
# If you have uploaded your app, update the test case here.
search_element = WebDriverWait ( driver , 30 ). until (
EC . element_to_be_clickable (
( MobileBy . ACCESSIBILITY_ID , "Search Wikipedia" ))
)
search_element . click ()
search_input = WebDriverWait ( driver , 30 ). until (
EC . element_to_be_clickable (
( MobileBy . ID , "org.wikipedia.alpha:id/search_src_text" ))
)
search_input . send_keys ( "lambdatest" )
time . sleep ( 5 )
search_results = driver . find_elements_by_class_name (
"android.widget.TextView" )
assert ( len ( search_results ) > 0 )
# Invoke driver.quit() after the test is done to indicate that the test is completed.
driver . quit ()
# The Thread function takes run_session function and each set of capability from the caps array as an argument to run each session in parallel
for cap in caps :
Thread ( target = run_session , args = ( cap ,)). start ()就這樣!如果您有任何疑問或需要任何其他信息,則可以通過我們的24x7聊天支持與我們聯繫,或直接通過[email protected]郵寄我們。
請訪問以下鏈接,以了解有關Lambdatest功能,設置和教程,圍繞測試自動化,移動應用測試,響應式測試和手動測試的更多信息。
Lambdatest社區允許人們與技術愛好者互動。連接,提出問題並向精通技術的人學習。與來自全球的專業人員討論Web開發,測試和DevOps中的最佳實踐?
要保持最新功能和產品附件的更新,請訪問ChangElog
Lambdatest是一個領先的測試執行和編排平台,它是快速,可靠,可擴展且安全的。它允許用戶在3000多個瀏覽器,操作系統和真實設備組合中對Web和移動應用程序進行手冊和自動測試。使用lambdatest,企業可以確保更快的開發人員反饋,從而更快地進入市場。 130多個國家 /地區的500多家企業和100萬用戶依靠Lambdatest來滿足其測試需求。
