How to run appium test scripts through jenkins

Hi, How to run the appium test scripts through jenkins, If any tutorial have please share that links or email.

Thanks Advance.

we solved it as moving to maven. and start with maven needed test suite.

If you have any samples please share me.

We can create the job in jenkins and we can the suite file which has the testcases for mobile app. So in jenkins how appium server will start and run these test cases? in real or simulator devices.

you need start appium in code. i do it in section beforeSuite. Google - > TestNG example - it is easy. you may ask for details later.

Hi Aleksei,

   While running the test script through testNG i am facing a problem, It through the org.openqa.selenium.remote.UnreachableBrowserException. Please see my code below and help me out.

Thanks Advance.

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;

public class MainClass {

private AndroidDriver<WebElement> driver;
private WebDriverWait driverWait;
private Process p;
private String nodePath = "C:/Program Files (x86)/Appium/node.exe";
 // Set path of your appium.js file.
private String appiumJSPath = "C:/Program Files (x86)/Appium/node_modules/appium/bin/appium.js";
private String cmd = nodePath + " " + appiumJSPath;
 
 // This method Is responsible for starting appium server.
public void appiumStart() throws IOException, InterruptedException {
  // Execute command string to start appium server.
  p = Runtime.getRuntime().exec(cmd);
  Thread.sleep(10000);
  if (p != null) {
   System.out.println("Appium server Is started now.");
  }
 }
 
 // This method Is responsible for stopping appium server.
public void appiumStop() throws IOException {
  if (p != null) {
   p.destroy();
  }
  System.out.println("Appium server Is stopped now.");
 }

@Test
public void createAccount() throws Exception, MalformedURLException
{
	
    appiumStop();
    appiumStart();
	
	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
	capabilities.setCapability(MobileCapabilityType.PLATFORM,Platform.ANDROID);
	capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
	capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "phone");
	capabilities.setCapability(MobileCapabilityType.VERSION, "7.0");
	capabilities.setCapability("appPackage", "com.kobobooks.android");
	capabilities.setCapability("appActivity","com.kobobooks.android.screens.AppLoading");
	driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

	driverWait = new WebDriverWait(driver, 20);
	driverWait.until(ExpectedConditions.presenceOfElementLocated(By.id("com.kobobooks.android:id/ftux_create_account")));
	driver.findElementById("com.kobobooks.android:id/ftux_create_account").click();
	driver.closeApp();
}

}

replace with:
private AppiumDriver driver = null;

who to start appium in right way:

private Process appium_Process;

// create appium server with custom properties
List list = new ArrayList<String>();
list.add(nodePath + " " + appiumJSPath);
list.add("--log-level");
list.add("error");
...
try {
            ProcessBuilder pb1 = new ProcessBuilder(list);

            // print errors and logs into console
            pb1.redirectErrorStream(true);
            pb1.redirectOutput(ProcessBuilder.Redirect.INHERIT);
            appium_Process = pb1.start();
           
            //give time to start servers
            Thread.sleep(10000);
} catch (Exception e) {
            e.printStackTrace();
}

now after appium server start you should see it initial logs into console including URL where appium started.

Hi Aleksei,

  Thank you so much for your interest. Sorry to say you i am still facing the problem, using the above code also i am getting the same error. I am new to automation testing framework and i didn't analyse the error. If you have any test sample for this please send me. My email id is [email protected].

Thanks Advance.

you can try something here - https://github.com/appium/java-client/tree/master/src/test/java/io/appium/java_client