How to create apk from my appium automation

I am try to appium automation and i write 1 appium automation code. i use appium server and this code

public class WaitTests {

     WebDriver driver;

     @Before
     public void setUp() throws MalformedURLException {

      DesiredCapabilities capabilities = new DesiredCapabilities();

      capabilities.setCapability("deviceName", "XT1562");

      capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");

      capabilities.setCapability(CapabilityType.VERSION, "6.0.1");

      capabilities.setCapability("platformName", "Android");

      capabilities.setCapability("appPackage", "com.android.calculator2");

      capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");

      driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
      driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);


     }

     @Test
     public void testFirstCalculator() {

      driver.findElements(By.xpath("//android.widget.Button")).get(0).click();

      driver.findElement(By.name("7")).click();

     driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); 
    }

i want to run this appium automation code without IDE after creating .apk so what i do please tell me

@rahul_rai Wrong question! you should ask how you can package your test script as fat jar!
appium listens your automation script using socket! it is not putting it inside device!
click on how to create a fat jar or simply google it… tones of tutorials available.
fat jar is a single jar which contains all of your project dependencies into it and you can distribute that jar.
if your jar name is “projecttestcode.jar”,
you may run it via terminal …

java -jar projecttestcode.jar
if you want to make it further independent,put jre in same folder as your projecttestcode.jar is and create a .batch or .sh file… using that you can run your script just by double click.

@PositiveCrux @rahul_rai final question why do we need build jar at all for CI?
with CI we need download/updated test code and start project in command_line/terminal

@Aleksei
why it is useful?
If we packaged jar with bundled jre , I need to just paste that folder into fresh machine and double click on batch or .sh file and my script is running… No configuration at all!

where it is helpful?
MANAGIBILITY when company have lots of products in market and they have automation team writing scripts everyday so they would have a build system which will make a fat jar/jars for me and copy/replace that jar to destination machines! simple process to manage complex test setup to keep all test execution clients updated and working! there may be products web,mobile,rest etc…

hope i made my point!

you point is wrong in terms - you updated your test code and you need repeat all again manually :slight_smile:

how it should be (we do in Jenkins following commands):

  1. update code (git pull)
[email protected]:xxxxxx/xxxxxx-tests.git
  1. start tests (we are with maven) with needed suite file (suite file contains list of tests that need to be executed. you can create different suites for different needs: full, bvt or …):
mvn clean test -DsuiteXmlFile=src/test/java/recources/android_BVT.xml

thus all you need to execute updated tests is click on start icon.

@Aleksei
you do not need to install jenkins to every machine you are running you script if you package.

install ssh client with public key of the server(where your single jenkins is installed) and using that single jenkins execute shell script “PATHTOBUNDLEDJRE/java -jar projecttestcode.jar”! using ssh to every machine(for windows cygwin) at one time!

If we packaged jar with bundled jre , I need to just paste that folder into fresh machine

No No… i do not “say you updated your test code and you need repeat all again manually” I said FRESH MACHINE means I want to configure new machine where jenkins,git,java,maven anything is not installed or I want to add new machine in my test architecture

and double click on batch or .sh file and my script is running… No configuration at all!

My test architecture is ready with new machine without installing jenkins,git,java,maven anything! or any configuration stuff of scheduling for every jenkins I have!

MANAGIBILITY
when company have lots of products in market and they have automation team writing scripts everyday so they would have a build system which will make a fat jar/jars

Yes that jenkins & git + maven part was elaboration of line "so they would have a build system"

and copy/replace that jar to destination machines!

Instead of building at every machine where it is supposed to run, build+package once and replace jars at targeted machines using ssh and you are up! or checkout all of the product code at that machines and build there and run there! as if you want iOS automation you need mac, you have some linux some windows!

simple process to manage complex test setup to keep all test execution clients updated and working! there may be products web,mobile,rest etc…

iOS app we need physical devices such as iphone 4,5,6,7 + ipad mini…
Android app we need physical devices which are multiple!
we can not accomodate all iOS+android +rest+web on a single machine!

ok - i got your point. the only thing:

  1. Jenkins is just some machine but where code executed (slaves). e.g. we have Jenkins in Amazon :slight_smile: but slave machines connected to it and executing whatever needed are in different parts of world/or office.
  2. build test code on slave takes same 1-2sec as e.g. in IntellJ where you are coding.
1 Like

Thank you for your answers. We are using Android Studio 2.3.2 and Appium server. We have created simple test cases to run a andriod app and it is working good from Android studio. but now we want to run this test cases without Android studio IDE. so we want a excutable file (It will be great if it is APK so it will run automation on same device or emulator).

Please suggest us with Android Studio.

@rahul_rai
rahul lets take this on [email protected]
and post here the final conclusion to help others rather than lengthy chain here.

@PositiveCrux please any one tell me how to create fat jar in android studio (I am search in google but not getting any proper way for creating fat.jar ) so, i am create executable file for run my above code. without any IDE

hey can we connect over this?