Could not connect and automate app via java automation code

Hello,i very new to appium…i have followed tutorials and used the Testapp7 in the appium site
but i could not automate the app with the java code written in Eclipse.

Below is my code and Error
org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

@SuppressWarnings(“unused”)
public class AppiumIOSDemoTest {
//private AppiumDriver idriver;
public IOSDriver driver;

@BeforeMethod
public void setup() {
	DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("appium-version", "1.4.0");
	capabilities.setCapability("platformName", "iOS");
	capabilities.setCapability("platformVersion", "8.0");
	capabilities.setCapability("deviceName", "iPhone 6");
	capabilities.setCapability("platformName", "/Volumes/company/ProjectsiOs/TestApp.app");
	capabilities.setCapability("app", "iOS");
	// String appPath = "/Volumes/company/ProjectsiOs/TestApp7.1.app.zip";
	//capabilities.setCapability("app", appPath);
	driver.manage().timeouts().implicitlyWait(180,TimeUnit.SECONDS);
	//driver.quit();
	driver.close();
	try {

		System.out.println("running...");
		driver = new IOSDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
		
		
		
	} catch (MalformedURLException e) {
		
		e.printStackTrace();
	} catch (SessionNotCreatedException e) {
		System.out.println("still running...");
		e.printStackTrace();
	}

}

@AfterMethod
public void tearDown() {

	if (driver != null)
		driver.quit();
}

@Test
public void simpleTest() {
	driver.findElementByName("TextField1").sendKeys("88");
	driver.findElementByName("TextField2").sendKeys("888");
	driver.findElementByName("ComputeSumButton").click();
	int answer = Integer.parseInt(driver.findElementByName("Answer")
			.getText());
	Assert.assertEquals(answer, 976);

}

}

pom.xml


4.0.0

org.mortbay.jetty jetty-maven-plugin 7.6.8.v20121106

com.company.ProjectsiOS
appium-ios-tutorial
0.0.1-SNAPSHOT
jar

appium-ios-tutorial
http://maven.apache.org

UTF-8
<dependency> 
	<groupId>io.appium</groupId>
	<artifactId>java-client</artifactId>
	<version>2.1.0</version>
</dependency>

<dependency> 
	<groupId>org.testng</groupId>
	<artifactId>testng</artifactId>
	<version>6.8</version>
</dependency>

<dependency>


	<groupId>org.seleniumhq.selenium</groupId>
	<artifactId>selenium-java</artifactId>
	<version>LATEST</version>
	<scope>test</scope>
</dependency>

Error

[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects…
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building appium-ios-tutorial 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] — maven-resources-plugin:2.6:resources (default-resources) @ appium-ios-tutorial —
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Volumes/Company/ProjectsiOs/appium-ios-tutorial/src/main/resources
[INFO]
[INFO] — maven-compiler-plugin:2.5.1:compile (default-compile) @ appium-ios-tutorial —
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] — maven-resources-plugin:2.6:testResources (default-testResources) @ appium-ios-tutorial —
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Volumes/Company/ProjectsiOs/appium-ios-tutorial/src/test/resources
[INFO]
[INFO] — maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ appium-ios-tutorial —
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] — maven-surefire-plugin:2.12.4:test (default-test) @ appium-ios-tutorial —
[INFO] Surefire report directory: /Volumes/Company/ProjectsiOs/appium-ios-tutorial/target/surefire-reports


T E S T S

Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@77468bd9
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@7791a895
Tests run: 4, Failures: 1, Errors: 0, Skipped: 2, Time elapsed: 1.038 sec <<< FAILURE!
setup(com.example.company.appium_ios_tutorial.AppiumIOSDemoTest) Time elapsed: 0.648 sec <<< FAILURE!
java.lang.NullPointerException
at com.example.company.appium_ios_tutorial.AppiumIOSDemoTest.setup(AppiumIOSDemoTest.java:35)

Results :

Failed tests: setup(com.example.company.appium_ios_tutorial.AppiumIOSDemoTest)

Tests run: 4, Failures: 1, Errors: 0, Skipped: 2

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.393 s
[INFO] Finished at: 2015-06-22T12:40:13+05:45
[INFO] Final Memory: 13M/178M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project appium-ios-tutorial: There are test failures.
[ERROR]
[ERROR] Please refer to /Volumes/Company/ProjectsiOs/appium-ios-tutorial/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project appium-ios-tutorial: There are test failures.

Please refer to /Volumes/Company/ProjectsiOs/appium-ios-tutorial/target/surefire-reports for the individual test results.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.

Please refer to /Volumes/Company/ProjectsiOs/appium-ios-tutorial/target/surefire-reports for the individual test results.
at org.apache.maven.plugin.surefire.SurefireHelper.reportExecution(SurefireHelper.java:83)
at org.apache.maven.plugin.surefire.SurefirePlugin.writeSummary(SurefirePlugin.java:176)
at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary(SurefirePlugin.java:150)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:650)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:586)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
… 19 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

These two values are interchanged.

platformName should have value iOS
app should have absolute path to application file

Also,

Comment out this code, as Driver will be null at this point. Driver is created in the next line.

Hey Ram, Thank you for replying I did got the mistakes i made and changed the code…according to what you said but still im getting the same issue

Error Below:
Tests run: 4, Failures: 1, Errors: 0, Skipped: 2

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.393 s
[INFO] Finished at: 2015-06-22T12:40:13+05:45
[INFO] Final Memory: 13M/178M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project appium-ios-tutorial: There are test failures.
[ERROR]
[ERROR] Please refer to /Volumes/Company/ProjectsiOs/appium-ios-tutorial/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project appium-ios-tutorial: There are test failures.

Please refer to /Volumes/Company/ProjectsiOs/appium-ios-tutorial/target/surefire-reports for the individual test results.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.

Please refer to /Volumes/Company/ProjectsiOs/appium-ios-tutorial/target/surefire-reports for the individual test results.
at org.apache.maven.plugin.surefire.SurefireHelper.reportExecution(SurefireHelper.java:83)
at org.apache.maven.plugin.surefire.SurefirePlugin.writeSummary(SurefirePlugin.java:176)
at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary(SurefirePlugin.java:150)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:650)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:586)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
… 19 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Your error logs does NOT mention why tests failed.

In your first log, tests failed due to Null pointer exception as quoted below -

Can you post detailed error logs for second run … along with updated test code. Also, I could see only one test in your code, but Maven output says 4 tests.

Hey Ram, i some how fixed the earlier issue but i have come across new issue which says:
session could be created and bad app. I have used the Testapp7 from appium.io example which resides with my java project workspace and i have used the absolute path.

A new session could not be created. (Original error: Bad app: /Applications/Appium.app/Contents/Resources/node_modules/appium/TestApp. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Using local app, but didn’t end in .zip, .ipa or .app) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.67 seconds
Build info: version: ‘2.46.0’, revision: ‘61506a4624b13675f24581e453592342b7485d71’, time: ‘2015-06-04 10:22:50’
System info: host: ‘rajans-Mac-mini.local’, ip: ‘172.16.0.187’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.10.3’, java.version: ‘1.8.0_25’
Driver info: io.appium.java_client.ios.IOSDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:180)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:153)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:109)
at io.appium.java_client.ios.IOSDriver.(IOSDriver.java:23)
at AppiumIOSDemoTest.main(AppiumIOSDemoTest.java:42)
Exception in thread “main” java.lang.NullPointerException
at AppiumIOSDemoTest.main(AppiumIOSDemoTest.java:54)

The Updated Code ( with little change):

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.ios.IOSDriver;

import java.net.MalformedURLException;
//import com.gargoylesoftware.htmlunit.javascript.host.URL;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.SessionNotCreatedException;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

@SuppressWarnings(“unused”)
public class AppiumIOSDemoTest {
//private AppiumDriver idriver;
public static IOSDriver driver;

@BeforeMethod
public static void main(String[] args ){
//public void setup() {
	DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("appium-version", "1.4.0");
	capabilities.setCapability("platformName", "iOS");
	capabilities.setCapability("platformVersion", "8.0");
	capabilities.setCapability("deviceName", "iPhone Simulator");
	//capabilities.setCapability("iOS", "/Volumes/Company/ProjectsiOs/TestApp.app");
	String appPath = "/Volumes/Company/ProjectsiOs/appium-ios-tutorial/TestApp7.1.app.zip ";
	//capabilities.setCapability("app", "iOS");
	capabilities.setCapability("app", "TestApp");
	//driver.manage().timeouts().implicitlyWait(180,TimeUnit.SECONDS);
	//driver.quit();
	//driver.close();
	try {

		System.out.println("running...");
		driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
		
		
		
	} catch (MalformedURLException e) {
		
		e.printStackTrace();
	} catch (SessionNotCreatedException e) {
		System.out.println("still running...");
		e.printStackTrace();
	}

	driver.findElementByName("TextField1").sendKeys("88");
	driver.findElementByName("TextField2").sendKeys("888");
	driver.findElementByName("ComputeSumButton").click();
	int answer = Integer.parseInt(driver.findElementByName("Answer")
			.getText());
	Assert.assertEquals(answer, 976);
}

@AfterMethod
public void tearDown() {

	if (driver != null)
		driver.quit();
}



}

}