3

I want to automated Facebook app on my android device.

I have tried to init a driver like this:

    private AppiumDriver driver;

    @Before
    public void setUp() throws Exception {
        File classpathRoot = new File(System.getProperty("user.dir"));
        File appDir = new File(classpathRoot, "../../../data/app/ ");
        File app = new File(appDir, "Facebook.apk");
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
        capabilities.setCapability("deviceName","Android Emulator");
        capabilities.setCapability("platformVersion", "4.4");
        capabilities.setCapability("platformName","Android");
        capabilities.setCapability("app", app.getAbsolutePath());


//        capabilities.setCapability("appPackage", "com.example.android.apis");
//        capabilities.setCapability("appActivity", ".ApiDemos");
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }

and I got:

info: --> POST /wd/hub/session {"desiredCapabilities":{"app":"/Users/eladb/WorkspaceQa/myAppiumExm/../../../data/app/ /Facebook.apk","platformVersion":"4.4","browserName":"","platformName":"Android","deviceName":"Android Emulator"}}

info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)

error: Failed to start an Appium session, err was: Error: Bad app: /Users/data/app/ /Facebook.apk. 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: Error locating the app: ENOENT, stat '/Users/data/app/ /Facebook.apk'

info: [debug] No appActivity desired capability or server param. Parsing from apk.
info: [debug] No appPackage desired capability or server param. Parsing from apk.
info: [debug] Using local app from desired caps: /Users/data/app/ /Facebook.apk
info: [debug] Got configuration error, not starting session
info: [debug] Cleaning up appium session
info: [debug] Error: Bad app: /Users/data/app/ /Facebook.apk. 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: Error locating the app: ENOENT, stat '/Users/data/app/ /Facebook.apk'
    at null.<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/android/android-common.js:56:13)
    at /Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/device.js:81:16
    at FSReqWrap.oncomplete (fs.js:99:15)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Bad app: /Users/data/app/ /Facebook.apk. 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: Error locating the app: ENOENT, stat '/Users/data/app/ /Facebook.apk')","origValue":"Bad app: /Users/data/app/ /Facebook.apk. 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: Error locating the app: ENOENT, stat '/Users/data/app/ /Facebook.apk'"},"sessionId":null}
info: <-- POST /wd/hub/session 500 8.318 ms - 628 

I have tried:

        capabilities.setCapability("app", "Facebook.apk"); 

and I got:

error: Failed to start an Appium session, err was: Error: Bad app: null. 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: You passed in an app package as the 'app' capability, but didn't include appActivity. We need to know that too in order to start your app

info: [debug] No appActivity desired capability or server param. Parsing from apk.
info: [debug] No appPackage desired capability or server param. Parsing from apk.
info: [debug] Got configuration error, not starting session
info: [debug] Cleaning up appium session
info: [debug] Error: Bad app: null. 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: You passed in an app package as the 'app' capability, but didn't include appActivity. We need to know that too in order to start your app
    at null.<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/android/android-common.js:56:13)
    at androidCommon.configureApp (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/android/android-common.js:69:14)
    at androidCommon.configure (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/android/android-common.js:37:10)
    at Appium.configure (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/appium.js:250:15)
    at null.<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/appium.js:118:10)
    at Appium.start (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/appium.js:129:5)
    at Object.exports.createSession [as handle] (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/server/controller.js:182:16)
    at next_layer (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/router/route.js:113:13)
    at Route.dispatch (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/router/route.js:117:5)
    at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/router/index.js:222:24
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Bad app: null. 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: You passed in an app package as the 'app' capability, but didn't include appActivity. We need to know that too in order to start your app)","origValue":"Bad app: null. 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: You passed in an app package as the 'app' capability, but didn't include appActivity. We need to know that too in order to start your app"},"sessionId":null}
info: <-- POST /wd/hub/session 500 9.616 ms - 712 

error: Unexpected error: Error: Can't set headers after they are sent.
    at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:335:11)
    at ServerResponse.res.set.res.header (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/response.js:561:10)
    at ServerResponse.res.send (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/response.js:133:12)
    at ServerResponse.res.json (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/response.js:210:15)
    at ServerResponse.res.send (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/response.js:121:21)
    at /Applications/Appium.app/Contents/Resources/node_modules/appium/lib/server/helpers.js:42:9
    at safely (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/server/helpers.js:306:5)
    at Layer.module.exports.catchAllHandler [as handle] (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/server/helpers.js:41:3)
    at trim_prefix (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/router/index.js:261:17)
    at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/router/index.js:225:9 context: [POST /wd/hub/session {"desiredCapabilities":{"app":"Facebook.apk","platformVersion":"4.4","browserName":"","platformName":"Android","deviceName":"Android Emulator"}}]
TypeError: Cannot set property 'onResetTimeout' of null
    at Appium.configure (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/appium.js:252:30)
    at null.<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/appium.js:118:10)
    at Appium.start (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/appium.js:129:5)

how can I make it work?

Update

I have tried:

    @Before
    public void setUp() throws Exception {
        File classpathRoot = new File(System.getProperty("user.dir"));
        File appDir = new File(classpathRoot, "../../../data/app/");
        File app = new File(appDir, "Facebook.apk");
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
        capabilities.setCapability("deviceName","Android Emulator");
        capabilities.setCapability("platformVersion", "4.4");
        capabilities.setCapability("platformName","Android");
        capabilities.setCapability("app", app.getCanonicalPath());

//        capabilities.setCapability("appPackage", "com.example.android.apis");
//        capabilities.setCapability("appActivity", ".ApiDemos");
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

and got:

org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Bad app: /Users/data/app/Facebook.apk. 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: Error locating the app: ENOENT, stat '/Users/data/app/Facebook.apk') (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 900 milliseconds
Build info: version: '2.43.1', revision: '5163bceef1bc36d43f3dc0b83c88998168a363a0', time: '2014-09-10 09:43:55'
System info: host: 'eladb-macbookpro.roam.corp.google.com', ip: '10.0.0.2', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.8.0_25'
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
  • Capability 'app' wants the absolute path to the app! I do not know which driver you are using (is it Java?), but the getAbsolutePath is returning something strange. Your error is in the test, Appium is not the problem here – Andry Feb 21 '15 at 16:18
  • it's not. but any way I have tried (removing white space or any other path) fails. – Elad Benda Feb 21 '15 at 17:11
  • You apk file, can you please tell me the exact canonical path (absolute with no parent clauses) to that file in your file system? Also please confirm me that your apk file resides in the same computer where Appium is running – Andry Feb 21 '15 at 17:16
  • no, I want to automated a Facebook app on my android device. I don't have the apk other than installed on the device itself – Elad Benda Feb 22 '15 at 10:53

2 Answers2

1

I cannot verify it at the moment but my guess is that you have a blank space generating some problems here:

1. private AppiumDriver driver;
2.
3. @Before
4. public void setUp() throws Exception {
5.    File classpathRoot = new File(System.getProperty("user.dir"));
6.    File appDir = new File(classpathRoot, "../../../data/app/ "); // <== HERE
7.    File app = new File(appDir, "Facebook.apk");
8.    ...

Appium log is telling you that the generated path is:

"app":"/Users/eladb/WorkspaceQa/myAppiumExm/../../../data/app/ /Facebook.apk"

That space in line 6 at "app/ " is causing the final path to be "/Users/eladb/WorkspaceQa/myAppiumExm/../../../data/app/ /Facebook.apk". I would rewrite line 6 like this:

File appDir = new File(classpathRoot, "../../../data/app/");

Instead of "app/ ", use "...app/"

Canonical paths

I haven't been using Java for a while so I do not remember IO APIs how they work, however you should find a better way to get the absolute path to you appfile because you have a final address which using the parent folder pattern ../ to access a resource... This is not the best. The final path should be:

"app":"/Users/data/app/Facebook.apk"

Am I right? In this answer you can see that probably you should be using getCanonicalPath rather than getAbsolutePath.

If my guess is right, the following code should work:

public void setUp() throws Exception {
    File classpathRoot = new File(System.getProperty("user.dir"));
    File appDir = new File(classpathRoot, "../../../data/app/");
    File app = new File(appDir, "Facebook.apk");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
    capabilities.setCapability("deviceName","Android Emulator");
    capabilities.setCapability("platformVersion", "4.4");
    capabilities.setCapability("platformName","Android");
    capabilities.setCapability("app", app.getCanonicalPath());
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

If you want to automate an existing app...

So looks like you might want to automate an existing app, the set of capabilities is as follows for Android:

public void setUp() throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
    capabilities.setCapability("deviceName","Android Emulator");
    capabilities.setCapability("platformVersion", "4.4");
    capabilities.setCapability("platformName","Android");
    capabilities.setCapability("appPackage", "<java-package-name-of-the-app>");
    capabilities.setCapability("appActivity", "<android-app-activity-name>");
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

Those new capabilities: appPackage and appActivity can be found in your app's property if you inspect Settings.

Community
  • 1
  • 1
Andry
  • 16,172
  • 27
  • 138
  • 246
  • I got `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: Error locating the app: ENOENT, stat '/Users/data/app/Facebook.apk') (WARNING: The server did not provide any stacktrace information)` – Elad Benda Feb 21 '15 at 17:08
  • Your apk is on the same computer where Appium is running right? Please confirm this. If positive, try avoiding the filesystem logic to get the path and, just to make it work, write the path manually. That should work. After that you should try playing a bit with those IO APIs in Java in order to get the correct canonical path. – Andry Feb 21 '15 at 17:11
  • no, I want to automated a Facebook app on my android device. I don't have the apk other than installed on the device itself – Elad Benda Feb 22 '15 at 10:52
  • In that case you do not need to specify an APK file, look at my answer with most recent edits – Andry Feb 22 '15 at 16:24
  • Also this ongoing question might be of help: http://stackoverflow.com/questions/28644170/i-have-an-installed-apk-but-i-cannot-find-its-path-using-usb-with-file-explorer/28648289?noredirect=1#comment45594293_28648289 – Andry Feb 22 '15 at 16:29
0

I did nothing but clearing up the space in mac, and it worked.!

Emjey
  • 2,038
  • 3
  • 18
  • 33