Rudziankoŭ
Rudziankoŭ

Reputation: 11251

How to add app file to appium Desired Capabilities correctly?

I used SauceLabs example

   DesiredCapabilities capabilities = new DesiredCapabilities();
   capabilities.setCapability("BROWSER_NAME", "Android");
   capabilities.setCapability("VERSION", "4.4.2");
   capabilities.setCapability("deviceName", "Android Emulator");
   capabilities.setCapability("platformName", "Android");

   //zip file containing your app to be tested
   capabilities.setCapability("app", "http://appium.s3.amazonaws.com/TestApp6.0.app.zip");

   driver = new RemoteWebDriver
   (new URL(MessageFormat.format("http://{0}:{1}@ondemand.saucelabs.com:80/wd/hub", 
   sauceUserName, sauceAccessKey)), capabilities);

And this is work perfectly fine. But when I downloaded zip with app and switched to local environment

capabilities.setCapability("app", app.getAbsolutePath());    
driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);

I got error from appium console:

error: Failed to start an Appium session, err was: Error: Bad app: /home/.../appium/assets/TestApp6.0.app.zip. 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: App zip unzipped OK, but we couldn't find a .app bundle in it. Make sure your archive contains the .app package and nothing else

Upvotes: 1

Views: 8889

Answers (3)

Jyotiprakash
Jyotiprakash

Reputation: 1

File app= new File("‪D:\\com.boondoggle.mortcalc-1.apk");
DesiredCapabilities capabilities= new DesiredCapabilities();
capabilities.setCapability("deviceName", "Redmi Note 3");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "6.0.1");
capabilities.setCapability("app", app.getAbsolutePath());
AndroidDriver driver= new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

Upvotes: 0

Ganesh Ram
Ganesh Ram

Reputation: 46

Try this instead of RemoteWebDriver: use AndroidDriver. Also, if you run from localhost mention the IP address or just type "localhost".

capabilities.setCapability("app", app.getAbsolutePath());    
driver = new AndroidDriver (new URL("http://localhost:4723/wd/hub"), capabilities);

Create a folder called "app" and place your testing Android app there.

Example code:

File filePath = new File(System.getProperty("user.dir"));
File appDir = new File(filePath, "/app");
File app = new File(appDir, "yourapkfile.apk");

Upvotes: 1

krishna chetan
krishna chetan

Reputation: 659

Your app and script needs to be in same directory, or you should specify complete path to .apk file in order for it work

Upvotes: 0

Related Questions