编程知识 cdmana.com

Construction of IOS automated test environment (Python & Java)

 
  

One 、 Preface

IOS Of App Automated testing and Android The same as , It can also be used. appium To carry out . however IOS Automation depends on Apple's osx System 、Xcode Construction, etc , And the closed system requires an apple developer account to drive the real machine .Appium The environment configuration is a little troublesome , Maybe I spend most of my time dealing with all kinds of strange error reports , Even need to reinstall the system .
The purpose of this article is to document the configuration process (MacOS Systematic Python and Java The environment configuration is also recorded ), Provide reference for people in the same way , Let's avoid detours .

Two 、 Environment depends on

1、 Environmental dependencies

  • Xcode
  • Git
  • homebrew
  • npm、nodejs
  • libimobiledevice
  • idevicesinstaller
  • ios-deploy
  • Carthage
  • appium
  • appium-doctor
  • Webdriveragent
  • ios-webkit-debug-proxy
  • Python and Java
  • Android SDK

2、 Environmental requirements and support

demand
Minimum version requirements
My environment version
Mac OSX
10.11+
macOS 11.3.1
iOS
9.3+
13.3、14.7
Xcode
7+
12.5
Appium
1.6+
1.20.2

 

The driver
Corresponding iOS edition
XCUITest Driver
ios9.3 Or more
UIAutomation Driver
ios9.3 following
 

3、 ... and 、 Environment configuration

1、xcode install

Xcode It's running on the operating system Mac OS X Integrated development tools on (IDE),iOS Automated testing uses Xcode It is mainly used to bind the Apple Developer Certificate WebDriverAgent Pack it up to iOS mobile phone .
There are two installation methods , Choose according to your system version .
Mode one :Mac Platform App Store install
adopt App store Installed Xcode It's the latest version , Need the latest version macOS System compatibility . If you have upgraded to the latest system , Can be directly in App store Download and install . It is best not to upgrade to the latest system , Other compatibility issues may be encountered .
Mode two : Offline package installation
Yours macOS When the system is not the highest version , To ensure the minimum version requirements :macOS stay 10.12 above ,xcode stay 8.1 above .
Offline package download address :https://developer.apple.com/cn/support/xcode/ ( You can choose the version )
Offline package Xcode Version selection , It's best to decide according to the release time of your system version , Select the version with similar release time . My version is :macOS 11.3.1 、Xcode12.5

2、Git install

Installed Xcode Bring their own Git Program , commonly Xcode After installation, there is no need to install it separately Git, verification Git Just the environment . If the later environment depends on installation, there is a problem about Git The error of , You need to update Git, Or uninstall and reinstall .
Verify the installation :git --version
verification git Connect :ping github.com
When the connection is successful , Terminal display :
Installation command :brew install git
to update Git:brew upgrade git

3、Homebrew install ( use brew To install dependencies )

Homebrew Is a Mac OS Software package management tools under the platform , Own installation 、 uninstall 、 to update 、 see 、 Search and many other practical functions . A simple command , Package management can be realized , You don't have to worry about dependencies and file paths , It's very convenient . similar apt-get、yum.
There are two ways to install : Foreign sources and domestic parks , Recommended Domestic source , I have never succeeded in using foreign sources .
Mode one ( Foreign sources ):
Official website :https://brew.sh/
Copy the following installation command on the homepage of the official website , Execute the command to install at the terminal :
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
 
Verify the installation :brew -v
to update Homebrew command :brew update && brew upgrade && brew clean
Mode two ( Domestic source ):
The above official website installation method has a high failure rate , It can be installed from domestic sources .
homebrew Domestic source installation method , The terminal executes the following command :
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

When the terminal is running , Follow the prompts :

Restart the terminal after installation perhaps function source /Users/sinosun/.bash_profile Otherwise, you may not be able to use .
Terminal execution :brew update Keep up to date
Finally, verify the installation :brew -v Get the version number
Reference link :
https://blog.csdn.net/ljl6158999/article/details/118144440 (macOS Solution to installation error after upgrade )

4、npm and nodejs install

Appium It's through Node.js Developed http The server , Used to create and control WebDriver Of session, So you need to install Node.js.npm yes Node.js Package management tools , Accompanying Node.js With the installation .
4.1、( Mode one :brew Online installation )【 my nodejs The version is :16.6.0】
Installation command :brew install node This method installs the latest version
Verify the installation :node -v  Get the version number
       npm -v  Get the version number
Other online installation methods :( Specify version installation )
The terminal executes the command line to find its own appropriate node edition  :brew search node
The query shows that up to... Can be installed node14 edition
Installation command :brew install node@ Version number ( Will npm and nodejs With the installation )
Bind installed node, command :brew link --overwrite --force node@ Version number
Verify the installation :node -v Get the version number
       npm -v Get the version number
uninstall node:
brew uninstall node@ Version number --force
for example : Installation is 12.18.1, Unload command :brew uninstall node@12 --force
4.2、( Mode two : Offline package installation )
brew Online installation is downloaded from the official website , Slow and low success rate , You can download the offline package and install it .
nodejs Official website download address :https://nodejs.org/en/ Click on “Current” Regional stable version .
After the installation package is downloaded and installed , Also enter... In the terminal node -v 、 npm -v verification
4.3、cnpm Domestic source installation
NPM The plug-in is installed from NPM Download the corresponding plug-in package on the official website , The server of the website is abroad , There are often slow downloads or exceptions , Then you need to find another way to provide a stable download , This method is CNPM. Alibaba's Taobao team put NPM The plug-ins on the official website are synchronized to the servers in China , Provide us with stable download resources from this server .
CNPM The same is NPM A plug-in for , To install, you need to execute the following commands on the terminal :
sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
Verify the installation :cnpm -v
 
4.4、npm Common errors in installing plug-ins
Through the terminal npm When installing the plug-in , prefix “sudo” It can reduce the probability of error reporting .( add sudo after , The command is executed as a system administrator )
If you pass npm When installing the plug-in , appear “npm ERR!” Tips , Indicates that the installation failed . Prefix with sudo Also reported wrong , Try domestic sources cnpm install , Just put the... In the command npm Switch to cnpm.
If... Occurs during terminal installation “npm WARN” Tips , You can ignore .
 

5、libimobiledevice install

libimobiledevice Is a native protocol used with apple IOS A library where devices communicate , amount to Android Of adb.appium Connect iOS The device must need this dependent Library , Through this library Mac os Easy access to iOS Equipment information . Support iOS10 The above systems
Installation command :brew install --HEAD libimobiledevice
uninstall :brew uninstall --ignore-dependencies libimobiledevice
Common commands :
1、idevice_id -l    Displays the currently connected device [udid], Include usb、WiFi Connect
2、ideviceinfo       Get device information
3、idevicedate       Get device time
4、idevicename       Get device name
5、idevicescreenshot    Screenshot
6、ideviceinstaller -u [udid] -i [xxx.ipa]  #xxx.ipa: Installation file path
7、ideviceinstaller -u [udid] -U [bundleId]  #bundleId: The package name of the app
Check the installation :
 

6、idevicesinstaller install

ideviceinstaller Is a tool for managing connected devices , And ios-deploy、Android Of adb The function is similar to .
ideviceinstaller With the function of libimobiledevice almost , You can get iOS The equipment udid、 install App、 uninstall App、 obtain bundleid etc. , but ideviceinstaller Support only iOS9 The following system environments ,libimobiledevice Support iOS10 The above system environment .
Installation command :brew install ideviceinstaller
Common commands :
1.ideviceinstaller -l Print app list

7、ios-deploy install

ios-deploy Is a command line installation ios app Tools for connecting to devices
The principle is based on os x The command line calls the system's underlying functions , Get connected devices 、 Inquire about / install / uninstall app
iOS10 The above systems use appium, Need to rely on ios-deploy
install :sudo npm install -g ios-deploy or sudo cnpm install -g ios-deploy
Install the specified version of ios-deploy Reference resources :https://www.jianshu.com/p/a100914ec784
ios-deploy Common commands :
1.ios-deploy -c View connected devices ( Including passage usb and wifi Connected )
2.ios-deploy -c --no-wifi Check through usb Connected devices
3.ios-deploy --id [udid] --bundle [xxx.app] Installation applies to the specified device ( among xxx.app yes Xcode The compiled ipa The path of )
4.ios-deploy --id [udid] --uninstall_only --bundle_id [bundleId] Uninstall the app on the specified device ( According to the package name , That is to say bundleId)
5.ios-deploy --id [udid] --list_bundle_id View all apps installed on the specified device ( Including system applications and third parties )
for example : ios-deploy --id 770dfe115807e7d494b4721b1e4ebd6ecb9424d3 --list_bundle_id
6.ios-deploy --id [udid] --exists --bundle_id [bundleId] Check whether an application is installed on the specified device
for example : ios-deploy --id 0420781d4e43f1f99935513c91e9b816f4dddc24 --exists --bundle_id com.facebook.taozhen

Be careful :Xcode It is installed through offline package , install ios-deploy When an error :
This is because Xcode The reason why the version is not set , Setup method : Get into Xcode preferences --> Click on locations-->Comand Line Tools Select the version number in the column ,
Then re execute the installation command . Here's the picture :
 
 
Check the installation :
Installation error resolution reference :https://blog.csdn.net/weixin_44643020/article/details/88226097
 

8、Carthage install

Carthage Is a iOS Projects rely on management tools , And cocoapods Functions are similar , Can help manage third-party dependencies , Be similar to Java Of maven. It compiles third-party dependencies into framework, With framework Third party dependency is added to the project for use and management . For automated testing WebDriverAgent adopt Carthage Managing projects depends on .
Installation command :brew install carthage
Check the order :carthage version
 
 
 
 

To be continued …… 

 
 
 
 
 
 

版权声明
本文为[Lamp holder]所创,转载请带上原文链接,感谢
https://cdmana.com/2021/08/20210804215649102n.html

Scroll to Top