testsigma
Topics
left-mobile-bg

Creating an executable file for Appium Server

right-mobile-bg
Creating an executable file for Appium Server
imageimage

Start automating your tests 5X Faster in Simple English with Testsigma

Try for free

Appium is a well-known mobile automation tool for automating native, hybrid, mobile web, and desktop apps. The appium community has come up with a major release in recent years, appium 2.0.0, and has made some considerable changes in making appium a platform where drivers and plugins can coexist independently.

In this blog, we will see how we can create an executable file for the appium server. 

What are executable files?

  • Executable files contain a set of encoded instructions, which execute sequentially once the user clicks on them.
  • Executable files are available in all operating systems but with extensions pertaining to that OS. While .exe is the Windows extension for executable files, the macOs executable file does not have any extension.

Why do we need executable files for the appium server?

The appium desktop, which is basically a GUI for the appium server was used to start/stop the server in appium 1.x. Moreover, the node runtime comes bundled with Appium Desktop which allowed users to use appium without having to install npm or node. But it is no longer compatible with appium 2.0+. And to overcome this, creating an executable file for the appium server is one of the easiest solutions. Apart from this, below are the benefits of having an executable file for the appium server:

Easy distribution:

  • Users do not have to worry about having node or npm as a pre-requisite to install appium. 
  • Once the executable file is built, the same can be used to start the appium on any machine and on any operating system. 

Easy to start the server: 

  • Appium server can be started with just a click on the executable file. 
  • No need to run commands from the terminal to start the appium server.

Easy to deploy:

  • Allows easy deployment on target machines i.e., if you want to install appium on any cloud server, you can simply deploy the exec file. 

Installing Appium 2: 

Operating System:

  • Mac os

Pre-requisite:

  • We are going to use the node package manager to install appium, so make sure you have the node set up on your machine. If you do not have the node, please download it from the below link:
  • I am using node version 16.20.0.

Installation:

  • To install appium 2, please use the below command:
    • npm i -g appium@next

Starting Appium:

  • Once appium is installed, you can start the server by mentioning “appium” in the terminal. 


  • As I mentioned before, with appium version 2, we need to install the drivers separately. However, this was not the case with appium 1, i.e. When we installed Appium 1. x, all available drivers would be installed at the same time as the main Appium server. This is no longer the case.

Installing Drivers:

  • To find the list of available drivers, use the following command. 
    • appium driver list


  • To install a specific driver, use the following command.
    • appium driver install <drivername> 


  • Now, when you start appium, it starts the server along with the installed drivers. 


Note: By default, appium creates a hidden directory called .appium inside your user home directory. This will be the location of all the appium drivers that we install. In my case, it would be: “/Users/vikramramalingam/.appium”.

Starting Appium via exec file:

In order to create an executable file for the appium server, we need a command line interface called “pkg”.

Pre-requisite:

Pkg:

  • A node.js package that can convert your Node.js app into executable files.
  • Another advantage of using pkg is, it creates executable files for several target machines at once.

Installing Pkg:

  • You can install pkg using the below command:
    • npm install -g pkg

Steps to create an executable file:

  • Create a new node js project using the below command
    • npm init
  • Add appium and pkg as a dependency
    • npm install –save appium@2.0.0-beta.71
    • npm install –save pkg@5.8.0
  • Create an index.js file and add the below code, which will start the appium server:
  • Pkg looks for an entry point to the application in the package.json file, so add bin and mention index.js.
  • Pkg has options such as targets, assets, and outputPath.
    • targets: Specify the format for which you want to build your output. For example, I am generating an exec file for node version:node16, Os: macOS, and Arch: arm64. If we don’t specify the target, Pkg generates an exec file for Windows, Linux, and macOS by default. 
    • assets: Asset is where we need to add all the required dependencies. For the appium server, we need to add the axios.cjs path as assets Apart from that I have also added files related to the sharp module, as I was getting errors for the same. 
    • output path: Path where the exec file should be placed. 

After doing the above, the package.json file should look like this:


  • Then give the below command to create an exec file for the appium server
    • pkg package.json
  • You can ignore the warnings on running the above command and once it is over, in the dist folder, you can find the appium server as an exec file. Double-click on it to start the server.


  • One important thing to consider before packaging is that, when we try to start the server, appium by default fetches the npm version on the machine and checks if the npm version is compatible to start the server. Because of that, if you try to start the appium server using the exec file we have just created in a machine that does not have npm, it will throw the below error. 


  • To overcome this problem, go inside the appium folder which is present inside the node_modules folder of the project’s working directory, and search for the below methods and comment them out. This will stop appium from looking for the npm version on the target machine. 
    • getNpmVersion()
    • checkNpmOk()
  • After doing the above, run the command again to create an executable file, and this time, you will be able to start the server on machines that do not have npm. 

It took me some time to figure this out. And having written this article, I hope it will help you get through the process of creating an executable file for the appium server with ease.

All said and done, I would also like to tell you about a low-code test automation platform for web, mobile, APIs, and desktop applications – Testsigma.  I, along with my team, at Testsigma, am working on some interesting innovations in the field of test automation and would definitely like you to check it out here: https://testsigma.com/signup

Conclusion:

Creating an executable file for the appium server not only helps you with starting/stopping the server but also with easy installation and distribution.

Happy Testing!!

imageimage
Subscribe to get all our latest blogs,
updates delivered directly to your inbox.

RELATED BLOGS


Power of POC in Testing: Your Exclusive Guide to Success

VIJAYARAGHAVAN VASUDEVAN
13 MIN READ
AUTOMATION TESTINGTEST AUTOMATION

Test objects in software testing | Types & How to Create it?

RANJANA KODLEKERE
8 MIN READ
TEST AUTOMATION

How To Write Calculator Test Cases? With Sample Test Cases

AMY REICHERT
13 MIN READ
TEST AUTOMATION