mac系統appium ios鏈接真機java自動化測試環境搭建

一、需要安裝或配置的清單:
1.java JDK
2.Xcode
3.eclips (根據個人習慣,選擇java開發工具)
4.appium desktop
5.homebrew
6.node
7.npm
8.libimobiledevice
9.carthage
10.ios-deploy
11.xcpretty
12.appium-doctor (可有可無)

二、本次安裝的環境
1.macOS:10.13.6
2.appium desktop: 1.6.3
3.Xcode: 9.4.1
4.java JDK: 1.8.0_181
5.java-client: 6.1.0

三、安裝步驟,在安裝前最好是先鏈接vpn,國內的防火牆,你懂的。
1.安裝java Jdk
a.下載jdk 這裏提供一個官網地址Java下載地址
2.安裝好java後,安裝Xcode,
a.xcode直接在AppStore下載安裝即可。
3.安裝eclipse
a.下載地址 eclipse下載
b.安裝eclipse
選擇這個
4.安裝appium-desktop
a.下載地址github下載地址, csdn下載地址
b.安裝appium desktop,將appium拖入applications,就完成安裝了。
這裏寫圖片描述
5.安裝homebrew
a.打開終端,在終端輸入
(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)
這裏寫圖片描述

6.安裝node
a.在終端輸入:brew install node
7.安裝npm
a.在終端輸入:brew install npm
8.安裝libimobiledevice
a.在終端輸入:brew install libimobiledevice –HEAD
9.安裝carthage
a.在終端輸入:brew install carthage
10.安裝ios-deploy
a.在終端輸入:npm install -g ios-deploy
11.安裝xcpretty
a.在終端輸入:gem install xcpretty
b.如果提示You don’t have write permissions,在前面加上sudo,然後會提示輸入電腦的登陸祕密。
12.安裝appium-doctor
a.在終端輸入:npm install -g appium-doctor
b.安裝成功後,可以使用appium-doctor –ios 檢查appium的ios環境有沒有安裝成功。
13.WebDriverAgent配置
a.WebDriverAgent地址:
/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent
b.打開WebDriverAgent.xcodeproj文件
這裏寫圖片描述
c.按以下配置操作
第一步
第二步
第三步
第四步
第五步
第六步
d.將WebDriverAgent安裝到手機上
A.在終端跳轉到WebDriverAgent的目錄下,WebDriverAgent目錄見上面的a步驟有
B.在終端輸入
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination ‘id=測試機的udid’ test

這裏寫圖片描述
C.去描述文件信任就可以了。
至此環境已經安裝完成了。
四、在eclipse中創建一個maven項目
a.在pom中配置java-client

<dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>6.1.0</version>
</dependency>

b.appium初始化
public class AppTest 

{
private static AppiumDriver driver;

public static void main(String[] args) throws MalformedURLException {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iphone 6s Plus");
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iostest");
    capabilities.setCapability("udid", "測試機id");
    //capabilities.setCapability("app", "/Users/hem/ShareSDKDemo.ipa");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.3.1");
    capabilities.setCapability("bundleId", "com.mob.product.ShareSDK");
    capabilities.setCapability("sessionOverride", false);
    capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);
    driver = new IOSDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    driver.manage().timeouts().implicitlyWait(180,TimeUnit.SECONDS);    
    driver.findElementById("微信好友").click();
    //System.out.println(driver.findElement(By.xpath("//XCUIElementTypeStaticText[@name=\"微信好友\"] ")).getText()+"------");
    try {
        Thread.sleep(10000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //XCUIElementTypeStaticText[@name="微信好友"]       shareMenuIcon
    driver.quit();
}

}

來補一下踩的坑。
之前按網上說的要去github下載一個最新的WebDriverAgent,替換掉appium自帶的WebDriverAgent。
當我下載好以後,配置好了替換掉appium自帶的WebDriverAgent,結果運行不了。報錯。下面爲報錯log
eclipse log
Exception in thread “main” org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Unhandled endpoint: /session/F885DA2F-2CFF-43CE-A609-5F6F8EA22505/wda/screen – http://localhost:8100/ with parameters {
wildcards = (
“session/F885DA2F-2CFF-43CE-A609-5F6F8EA22505/wda/screen”
);
}
Build info: version: ‘3.12.0’, revision: ‘7c6e0b3’, time: ‘2018-05-08T14:04:26.12Z’
System info: host: ‘youuzdeMac-mini.local’, ip: ‘192.168.110.5’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.13.6’, java.version: ‘1.8.0_181’
Driver info: io.appium.java_client.ios.IOSDriver
Capabilities {app: /Users/hem/ShareSDKDemo.ipa, automationName: XCuiTest, browserName: , databaseEnabled: false, deviceName: iostest, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: false, platform: MAC, platformName: iOS, platformVersion: 10.3.1, sessionOverride: true, takesScreenshot: true, udid: 71b53307f6b547a37d6e2041443…, webStorageEnabled: false}
Session ID: 0c34de1d-e5a2-4e07-8895-300a2652500f
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:231)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:46)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
at io.appium.java_client.HasSessionDetails.getSessionDetails(HasSessionDetails.java:39)
at io.appium.java_client.HasSessionDetails.getSessionDetail(HasSessionDetails.java:56)
at io.appium.java_client.HasSessionDetails.getPlatformName(HasSessionDetails.java:65)
at io.appium.java_client.internal.JsonToMobileElementConverter.(JsonToMobileElementConverter.java:49)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:89)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:94)
at io.appium.java_client.ios.IOSDriver.(IOSDriver.java:95)
at gameAPI.appium.AppTest.main(AppTest.java:34)

找了半天資料沒找到解決辦法。還去github問了一下,給github提的問題
按他回覆的處理後還是不行。

最後實在解決不了啦,心累。。。。。
最後在testhome裏面找到了一個哥們遇到了和我一樣的問題。
呀!那個鏈接找不到了。
解決方法就是,使用appium自帶的WebDriverAgent。
問題就解決了。。。。
由於對mac系統不是很熟,Xcode也不熟。所以打這個ios的環境有點費勁。
Android相對來說簡單的多。後面在補一個mac下搭建appium的android環境。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章