In my appium + testng app, what I have put is:
package com.tribehr.ios.ios_test;
import java.net.URL;
import io.appium.java_client.AppiumDriver;
import org.junit
Surround "driver" with an if statement, to understand whether it == null.
if(driver!=null){
System.out.println("driver does not == null");
driver.findElement(By.xpath("YourXpath"));
} else {
System.out.println("driver == null")
}
Here are my capabilities Working with appium 1.2*
public WebDriver appiumCapabilities() {
File appDir = new File(System.getProperty("user.dir"), "/app/");
File app = new File(appDir, "test.app");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");
capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("deviceName", "iPod");
capabilities.setCapability("platformVersion", "7.1");
capabilities.setCapability("device", "iphone");
capabilities.setCapability("udid", "cd827d3778cfdee2fc7210f8f44184821a083c06");
capabilities.setCapability("app", app);
try {
driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return driver;
}