Appium Installation Through Terminal
By: Rakesh Kamaraju
Tags: Maven, Install Appium On Mac, Intellij Idea, Testng, Brew

Pre-Requisites

1. Update MacOS

2. Install XCode from AppStore. Once XCode finishes the install, launch it and let it continue installing all the necessary components.

3. Exit XCode.

Brew Installation

4. Goto https://brew.sh/ and copy the latest installation command

5. Open terminal and run the command to install brew on your system.

6. Run the below command to make sure your system is ready to brew. Follow any recommendation from brew doctor

a. brew doctor

7. Next, add the Homebrew location to your $PATH and source your bash or zsh profile file after adding/saving this:

Open vi .bash_profile and add the below.

a. export PATH=/usr/local/bin:$PATH b. export PATH=/opt/local/bin:$PATH

8. After completion, esc + :wq and then source .bash_profile

a. brew help b. brew tap homebrew/cask-versions

9. Exit the terminal

Java Installation:

10. Run the below commands in a new terminal for latest Java JDK.

a. brew tap caskroom/versions b. brew search java c. brew cask install java

11. Or for specific Java version

a. brew tap adoptopenjdk/openjdk b. brew cask install adoptopenjdk8

12. Existing users of Homebrew may encounter Error: Cask adoptopenjdk8 exists in multiple taps due to prior workarounds with different instructions. This can be solved by fully specifying the location with

a. brew cask install adoptopenjdk/openjdk/adoptopenjdk8. b. java -version c. echo $JAVA_HOME

13. Above command will give empty response. Now let us set up java environment paths by running the below commands

a. vi .bash_profile 14. Copy the updated export in the bash profile a. export JAVA_HOME=$(/usr/libexec/java_home) or export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_265.jdk/Contents/Home export PATH=$JAVA_HOME/bin:$PATH

15. Finally, follow the below steps to exit and save successfully.

a. esc + :wq b. source .bash_profile c. echo $JAVA_HOME

16. Successful Java set up will show the below path

/Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home

17. Exit the terminal

IntelliJ Installation:

18. Run the following commands, remembering to re-run the install in case of any error while installing.

a. brew search intellij b. brew cask install intellij-idea-ce

19. Launch IntelliJ from Launchpad and create maven project

20. Project SDK will auto select’s the Java JDK version or select the desired Java JDK

21. Create a main method

22. Run a print program to make sure Java / IntelliJ installation is successful.

23. Close IntelliJ and Exit the terminal

TestNG Installation:

24. Open pom.xml in the above project.

25. Add below testng maven dependency

<dependencies>

<!-- https://mvnrepository.com/artifact/org.testng/testng | TestNG for running testing-->

<dependency>

<groupId>org.testng</groupId>

<artifactId>testng</artifactId>

<version>7.1.0</version>

<scope>compile</scope>

</dependency>

</dependencies>

26. Right click on pom.xml and click on Reload project & Generate source to make sure testng is installed.

27. Now create a method and run print program using testng command using @Test notation

Maven Installation:

28. Run the following commands, remembering to re-run the install in case of any error while installing

a. brew search maven b. brew install maven and then run mvn -version c. vi .bash_profile and get the below path from your system d. export M2_HOME =/usr/local/Cellar/maven/3.*.*/libexec export PATH =$Path:$M2_HOME/bin e. or copy the below commands f. export M2_HOME=/Applications/apache-maven-3.6.* export PATH=$PATH:$M2_HOME/bin g. esc + :wq h. source .bash_profile i. mvn -version Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec Java version: 1.8.0_241, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home/jre Default locale: en_US, platform encoding: UTF-8 OS name: “mac os x”, version: “10.15.7”, arch: “x86_64”, family: “mac” j. echo $M2_HOME /Applications/apache-maven-3.6.3

29. Add steps to validate maven

30. Exit the terminal

Appium Installation

31. Go into the iOS device you plan to use and set the screen to not lock. Locking will cause issues during this process so its key to go into your ios settings app > display and brightness > auto-lock > set to “never”

32. Make sure XCode is install with its necessary components

33. When XCode finally launches go into the XCode preferences, accounts, then add your dev apple account. Once you have signed in, connect an iPhone device (make sure you are on the latest version of iOS) and go into XCode → Window → Device and simulator menu, verify your iPhone is present on the device list and wait for XCode to finish installing all the necessary support onto the iPhone.

34. Once you notice XCode completes its installs, go into your iPhone settings, you will notice a Developer option that you did not see before, click on that and make sure the Enable UI Automation option is selected and green, then close XCode

35. Run the following commands, remembering to approve all requests for the terminal to access your file system.

a. brew install wget b. brew install node c. brew install carthage d. brew install — HEAD libimobiledevice e. brew install –HEAD usbmuxd f. brew install ios-deploy g. npm install wd h. sudo gem install xcpretty i. npm install -g appium-doctor

36. Go to appium.io and download the latest version of Appium

37. Install the dmg file

38. Launch appium via applications folder and verify it launches successfully. If you cannot launch the app right click on it the second time and click open. That should give you another option to open the app.

39. Close Appium

40. Launch XCode

41. Open the following project in XCode

/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent/WebDriverAgent.XCodeproj

42. Double click on the WebDriverAgent item under the left panel

43. On the center top panel, click on WebDriverAgentLib

44. Click on the signing and capabilities tab up top

45. Enable the automatically manage signing checkbox

46. Set the team drop down to your team (apple id account)

47. The provisioning profile should be set to none required

48. On the center top panel, click on WebDriverAgentRunner

49. Enable the automatically manage signing checkbox

50. Set the team drop down to your team (apple id account)

51. The provisioning profile should be set to XCode managed profile

52. The signing certificate should be set to (your apple id and certificate name this should be auto generated. If the device already has a certificate it may ask you to revoke and recreate. There should not be any errors on this screen)

53. On the center top panel, click on IntegrationApp

54. Enable the automatically manage signing checkbox

55. Set the team drop down to your team (apple id account)

56. The signing certificate should be populated

57. Make sure on the center top panel, click on WebDriverAgentLib_tvOS and make sure “automatically manage signing” is disabled. Repeat for WebDriverAgentRunner_tvOS

58. Click on the webdriveragaint again just above the webdriveragentlib and build the project (play icon on upper left of XCode) This process will install integrationapp onto your ios device and verify the build is successful. You may be prompted to enter your macOS password. Make sure if you are to click always allow after inputting your password.

59. Once you get the build successful notification, stop the build in XCode and exit XCode

60. Go back to your terminal session and perform the following commands

a. sudo XCode-select -s /Applications/XCode.app/Contents/Developer b. cd /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent/ c. Mkdir -p /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent/WebDriverAgent.bundle d. bash Scripts/bootstrap.sh -d e. appium-doctor –ios f. Once you run the appium-doctor –ios command, you may be prompted to enter your password. After you do so make sure you only get warnings for optional fixes and there are no necessary fixes needed g. If any errors are listed under necessary fixes, you will need to install and troubleshoot those independently one by one.

61. Exit your terminal session

62. Launch Appium

63. Start the server

64. Click on start inspector session button

65. Set the following capabilities

a. udid = <udid of the device you are using to test> b. bundleId = <bundle id of the app you are testing, I used safari com.apple.mobilesafari> c. automationName = XCUITest d. platformName = iOS e. platformVersion = <current ios version your device is on> f. deviceName = <anything you want> g. Make sure to save these settings

66. Once you have saved, go ahead and start the inspector, the appium logs should start to flow with data and the inspector will launch as well as your app. You may be asked to enter your password multiple times, make sure when you are prompted to click always allow after entering your password (your mac password NOT your icloud password) for each prompt. You will see your app on the left side of the inspector. IF YOU ENCOUNTER A PORT 8100 OCCUPIED ERROR: All you have to do is bounce your machine. Once you restart your machine do not launch anything other than appium and launch the appium app again and load the capabilities again and try to launch the inspector.

67. Add Appium Server dependency to pom.xml

<dependencies>

<!-- https://mvnrepository.com/artifact/org.testng/testng | TestNG for running testing-->

<dependency>

<groupId>org.testng</groupId>

<artifactId>testng</artifactId>

<version>7.1.0</version>

<scope>compile</scope>

</dependency>

<dependency>

<groupId>io.appium</groupId>

<artifactId>java-client</artifactId>

<version>7.3.0</version>

</dependency>

</dependencies>

Android Studio Installation:

68. Run the following commands, remembering to re-run the install in case of any error while installing

a. brew search Android Studio b. brew cask install android-studio c. vi .bash_profile d. export PATH=$ANDROID_HOME/platform-tools:$PATH export PATH=$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$PATH export PATH=$ANDROID_HOME/build-tools/30.0.2:$PATH export PATH=/usr/local/bin:$PATH export PATH=/opt/local/bin:$PATH e. esc + :wq f. source .bash_profile g. echo $ANDROID_HOME

69. Run each below command to make sure installation is successful

a. adb devices [Shows the list of active devices] b. emulator -list-avds [Shows the list of active emulators] c. emulator -avd Pixel_3a_XL_API_30 [Launch an emulator] d. Run appium-doctor e. Once you run the appium-doctor command, you may be prompted to enter your password. After you do so make sure you only get warnings for optional fixes and there are no necessary fixes needed i. If any errors are listed under necessary fixes, you will need to install and troubleshoot those independently one by one.

70. Exit your terminal session

71. Add steps to launch Android system app using Appium and IntelliJ

Charles Proxy Installation:

72. Run the following commands, remembering to re-run the install in case of any error while installing

a. brew search charles b. brew cask install Charles c. vi .bash_profile d. export CHARLES_HOME=/Applications/Charles.app/Contents/MacOS export PATH=$PATH:$CHARLES_HOME e. esc + :wq f. source .bash_profile g. echo $CHARLES_HOME

73. Install the certificate on device / emulator / simulator and test.

Launch Apps Using IntelliJ:

74. Create a Class and run the modified program