Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Start Appium server from the code

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.01k
    Comment on it

    When we are automating the mobile application and set cron jobs at different time intervals then we do not start and stop the appium server manually. We should have some code that will run before our testcases ie they should be executed in the beginning of our testsuite. If we are using testNG as the testing framework then we should put the method to start the server in "@BeforeSuite" annotation and the method to stop the server in the "@AfterSuite" annotation.

    There are basically two files, we need to start the Appium server:

    • node.exe
    • appium.js

    The code to start and stop Appium server is:

    public class TestAppiumServer {
    
            // Launch Appium on Windows
            private static Process process;
    
            //Calling the node.exe and appium.js
            private static String STARTSERVER = "C:\\Program Files (x86)\\Appium\\node.exe C:\\Program Files (x86)\\Appium\\node_modules\\appium\\bin\\appium.js"; //Give the path of these two files as per your system setting.
    
            //Starting the Appium Server
            public static void startAppiumServer() throws IOException, InterruptedException {
    
            Runtime runtime = Runtime.getRuntime();
            process = runtime.exec(STARTSERVER);
            Thread.sleep(7000);
    
            if (process != null) {
            System.out.println("Appium server started");
            }
            }
    
            //Stopping the Appium Server
    
            public static void stopAppiumServer() throws IOException {
    
            if (process != null) {
            process.destroy();
            }
            System.out.println("Appium server stopped");
            }
    
        public static void main(String[] args) throws IOException, InterruptedException {
    
            stopAppiumServer();
            startAppiumServer();
            Thread.sleep(5000);
            stopAppiumServer();
        }
    }
    

    In the above code I first stop the server to confirm that no instance of the server in the running stop and then start the server again.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: