I have created a java test class to run . I cannot use a .bat file as I am a user and .bat files only work on windows o/s

This is my FIRST appium framework so I am figuring things out as I go along. Things were going great until this happened.

Now, I want to the ‘ java class file’ to my test class.

They’re in 2 different packages in the same Maven Framework

I’ve been trying to resolve this for 7 days. I really need some help.

So my questions are:

1. Is my code right or wrong?

2. If this is wrong, tell me What do I change in the code so it will work in my testNG test class?|

3. How do I link ‘start appium programmatically java class’ that is in one package TO the ‘test a class’ in the other package?

4. If its not possible to link the 2 test classes together. What command should I use to start appium via terminal?

I will be honest, I will need someone to spoon feed me the answer because I am utterly clueless.


(note: All code for 1 & 2 ran in eclipse with no issues)

  1. Launch appium server code (package: aapiumLaunchServer> Filename: LaunchServer)

package aappiumLaunchServer;

import java.io.IOException;

public class LaunchServer {

// 1.Appium Launch on Mac

    private static Process process;

    // 2.  Calling the node.exe and appium.js
    private static String STARTSERVER = "/Users/add_username_here/.nvm/versions/node/v7.2.0/bin/node";

    // 3. Starting the Appium Server

    public static void startAppium() throws InterruptedException, IOException  {

        Runtime runtime = Runtime.getRuntime();

        process = runtime.exec(STARTSERVER);


        if (process != null) {

            System.out.println("Your Appium server session has started");


    public static void stopAppium() throws IOException {

        if (process != null) {



        System.out.println("Your Appium server session has ended. Thank you and Goodbye");


    public static void main(String[] args) throws IOException, InterruptedException {


  1. Java Test Class (page object file layout) (package: apkDemoTest

    Filename: ConnectToWifiTest)

package apkDemoTest;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import apkDemoPageObject.HomeScreen;
import apkDemoPageObject.Preferences;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Driver;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.interactions.touch.TouchActions;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.MobileCapabilityType;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class ConnectToWifiTest {
static AndroidDriver<MobileElement> driver;

    public AndroidDriver<MobileElement> initDriver() throws MalformedURLException{

        DesiredCapabilities caps =new DesiredCapabilities();
        caps.setCapability("deviceName", "Nexus5");
        caps.setCapability("platformName", "Android");
        caps.setCapability("platformVersion", "8.0");
        caps.setCapability("automationName", "UiAutomator2");
        caps.setCapability("appPackage", "com.example.android.apis");
        caps.setCapability("appActivity", "ApiDemos");
        caps.setCapability("newCommandTimeout", "2000");

        driver = new AndroidDriver<MobileElement>(new URL(""), caps);
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
        return driver;

    //Scenario:  Connect to wifi

    //Given I am on the Home screen 
    //When I tap  the 'Preferences'  menu item
    //Then I will tap 'preference dependencies'  
    //When I  tap  the 'Wifi ' option in preference dependencies
    //Then a text box will appear
    //When I type 'hello' 
    //And tap the 'OK' button
    //Then I am connected to wifi

    public void addWifi(){

        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

           HomeScreen hs = new HomeScreen(driver);
           Preferences p = new Preferences(driver);



           // multiple objects with duplicates class names

          // p.Button.get(1).click();

  1. My attempt to start appium desktop programmatically (is code right or wrong?)

    public void InvokeAppum() {

            driver = AndroidUtilities.setAndroidCapabilites(
    public void EndAppium()  {
    stopAppium.info("Executing After Suite");
    stopAppium.info("Your Appium server session has ended. Thank you and Goodbye.");

Source link https://sqa.stackexchange.com/questions/35419/launch-appium-desktop-programmatically-and-link-to-a-testng--for-mac-h


Please enter your comment!
Please enter your name here