I am trying to execute the following code on “Ubuntu” but unable to execute it, getting error as below.
import java.io.File;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
public class TestLatestAppiumVersion {
public static AndroidDriver<MobileElement> driver;
@Test
public void testServer() throws Exception {
File classpathRoot = new File(System.getProperty("user.dir"));
System.out.println(classpathRoot);
File app = new File(classpathRoot, "whatsapp.apk");
AppiumDriverLocalService service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
.usingDriverExecutable(new File("/home/xxx/.linuxbrew/Cellar/node/4.2.1/bin/node"))
.withAppiumJS(new File("/home/xxx/.linuxbrew/lib/node_modules/appium/bin/appium.js"))
.withLogFile(new File("/home/xxx/workspace/xxx/log.txt")));
System.out.println("Requesting to start server");
service.start();
System.out.println("Server has started!!!");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "MyVirtualDevice");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.0");
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.1.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(20L, TimeUnit.SECONDS);
driver.quit();
service.stop();
System.out.println("Server has stopped successfully!!!");
}
}
OUTPUT:
2015-10-28 12:44:38:266 - info: Welcome to Appium v1.4.13 (REV c75d8adcb66a75818a542fe1891a34260c21f76a)
2015-10-28 12:44:38:268 - info: Appium REST http interface listener started on 0.0.0.0:4723
2015-10-28 12:44:38:271 - info: [debug] Non-default server args: {“log”:"/home/grabhouse/workspace/Grabhouse/log.txt"}
2015-10-28 12:44:38:271 - info: Console LogLevel: debug
2015-10-28 12:44:38:271 - info: File LogLevel: debug
2015-10-28 12:44:38:529 - info: --> GET /wd/hub/status {}
2015-10-28 12:44:38:531 - info: [debug] Responding to client with success: {“status”:0,“value”:{“build”:{“version”:“1.4.13”,“revision”:“c75d8adcb66a75818a542fe1891a34260c21f76a”}}}
2015-10-28 12:44:38:537 - info: <-- GET /wd/hub/status 200 7.669 ms - 105 {“status”:0,“value”:{“build”:{“version”:“1.4.13”,“revision”:“c75d8adcb66a75818a542fe1891a34260c21f76a”}}}
2015-10-28 12:44:38:915 - info: --> POST /wd/hub/session {“desiredCapabilities”:{“automationName”:“Appium”,“platformVersion”:“5.0”,“app”:"/home/grabhouse/workspace/Grabhouse/whatsapp.apk",“deviceName”:“MyVirtualDevice”,“platformName”:“Android”,“browserName”:""}}
2015-10-28 12:44:38:916 - info: Client User-Agent string: Apache-HttpClient/4.3.3 (java 1.5)
2015-10-28 12:44:38:919 - info: [debug] No appActivity desired capability or server param. Parsing from apk.
2015-10-28 12:44:38:919 - info: [debug] No appPackage desired capability or server param. Parsing from apk.
2015-10-28 12:44:38:920 - info: [debug] Using local app from desired caps: /home/grabhouse/workspace/Grabhouse/whatsapp.apk
2015-10-28 12:44:38:921 - info: [debug] Creating new appium session 4bacfd6b-b7c6-42fe-996c-147689cc2e7c
2015-10-28 12:44:38:921 - info: Starting android appium
2015-10-28 12:44:38:923 - info: [debug] Getting Java version
2015-10-28 12:44:38:969 - info: Java version is: 1.7.0_79
2015-10-28 12:44:38:971 - info: [debug] Checking whether adb is present
2015-10-28 12:44:38:971 - warn: The ANDROID_HOME environment variable is not set to the Android SDK root directory path. ANDROID_HOME is required for compatibility with SDK 23+. Checking along PATH for adb.
2015-10-28 12:44:38:971 - info: [debug] executing cmd: which adb
2015-10-28 12:44:38:976 - info: [debug] Cleaning up android objects
2015-10-28 12:44:38:976 - info: [debug] Cleaning up appium session
2015-10-28 12:44:38:977 - error: Failed to start an Appium session, err was: Error: Could not find adb. Please set the ANDROID_HOME environment variable with the Android SDK root directory path.
2015-10-28 12:44:38:979 - info: [debug] Error: Could not find adb. Please set the ANDROID_HOME environment variable with the Android SDK root directory path.
at [object Object]. (/home/grabhouse/.linuxbrew/lib/node_modules/appium/node_modules/appium-adb/lib/adb.js:126:12)
at ChildProcess.exithandler (child_process.js:210:5)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:818:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
2015-10-28 12:44:38:979 - info: [debug] Responding to client with error: {“status”:33,“value”:{“message”:“A new session could not be created. (Original error: Could not find adb. Please set the ANDROID_HOME environment variable with the Android SDK root directory path.)”,“origValue”:“Could not find adb. Please set the ANDROID_HOME environment variable with the Android SDK root directory path.”},“sessionId”:null}
2015-10-28 12:44:38:982 - info: <-- POST /wd/hub/session 500 67.119 ms - 342.
I had set the Environment variables in “~/.bashrc”,"~/.profile" & also “~/.bash_profile” as follows:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
export MAVEN_HOME=/home/grabhouse/Documents/apache-maven-3.3.3
export PATH=$MAVEN_HOME/bin:$PATH
export ANDROID_HOME=/home/grabhouse/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools/
export PATH=$PATH:$ANDROID_HOME/tools/
export PATH=$PATH:$ANDROID_HOME/build-tools/
and also tried with,
export ANDROID_HOME=/home/grabhouse/Android/Sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/build-tools:$PATH
Also unable to install GUI version of “Appium on Ubuntu”, unable to open "uiautomatorviewer"
Help me in this regard,
Thanks in advance
Sandeep.