Running Appium From Source (Or The Latest Beta)
This is another guest post from Appium contributor Jonah Stiennon. Enjoy!
Have you run into a bug in Appium that has been fixed by open source contributors but hasn't been released in an official version yet? Or maybe you saw an exciting new feature you'd like to try out right away, rather than waiting for the next published release?
In order to do either of these, you can run Appium code which is newer than that latest release. Appium releases occur every one to three months. In between official versions, the Appium contributors release beta versions, every week or so. You can install and use these beta versions, or for the very very latest code, you can run Appium from the most recent code posted to Github.
Installing and Running a Beta version
Appium is a Node.js project hosted on npm. The latest beta version can be installed from the commandline as follows:
npm uninstall -g appium npm install -g appium@beta
As easy as that. The first step is to remove a previously-installed version of Appium.
It should go without saying that a beta version of Appium may be less stable than an official release. Beta versions are not published without running tests first, but bugs may exist, especially in new features. Testers are encouraged to try use the beta versions, and reporting bugs will ensure a better official release.
Appium is composed of many modules, specifically one for each "driver" which controls mobile devices (xcuitest-driver, uiautomator2-driver, chrome-driver, safari-driver...). Most new code for Appium is added to these drivers rather than to the Appium repository itself. Whenever code is added to a driver, the driver is usually published to npm right away. Each time an official Appium release is created, specific versions of each driver are selected to be included in the Appium release.
Beta releases of Appium do not specify specific versions of drivers, so every time you install a beta version, all the drivers are updated to the latest published version. If you are already using a beta version of Appium, then all that is necessary to install newer versions of the drivers is to run:
npm install -g appium@beta
Installing Appium from Lastest Source Code
Appium releases are published to npm, but the most recent code resides in github.
First we clone the repository from github:
git clone https://github.com/appium/appium.git
Then navigate to the new directory:
Then install all Node.js dependencies:
Appium requires some other dependencies you will need to install yourself, depending on which platforms you aim to automate. These are all covered in the standard installation guides in the Appium docs and aren't covered here.
The Appium code can be run as follows, within the Appium code directory:
We can of course, choose to run this from anywhere else:
Appium was not added to the PATH when we installed it, so running the
appium command in a terminal will either fail, or run another version of Appium we have installed. We can set the
appium command to run our source code by setting an alias. Add the following code to your shell config:
alias appium="node path/to/appium/directory"
As mentioned in the section about installing a beta version, the Appium project is comprised of many modules, especially all the various drivers for different platforms. When we ran
npm install above, we installed the latest published versions of those drivers, found on npm. Since we are running on the very latest code from github, we may also want to access the latest code for the one of the Appium drivers.
In order to have our local Appium source code use the latest code for a driver, we need to get the code for the driver from github. Then we use the npm link command to tell Appium to use this code instead of a package from npm.
As an example, here is how we'd have our local Appium code use the latest code for the UiAutomator2 driver:
git clone https://github.com/appium/appium-uiautomator2-driver.git cd appium-uiautomator2-driver npm install npm link cd /path/to/appium/directory npm link appium-uiautomator2-driver
We only need to set this up once, now if get pull the latest code into the appium-uiautomator2-driver directory (or modify the code there), restarting the Appium server will automatically include the new code.
A warning though, if we install a new version of Appium or run
npm install it will break this
npm link and we'll have to do it again.
Installing an Old Version of Appium
While we're on the subject, you can also install and run old versions of Appium like so:
npm install email@example.com
Substitute the version you desire instead of