PackagemyTest;Import Staticorg.junit.assert.*;ImportIo.appium.java_client.android.AndroidDriver;ImportOrg.junit.After;ImportOrg.junit.Before;Importorg.junit.Test;Importorg.openqa.selenium.By;Importorg.openqa.selenium.WebElement;ImportOrg.openqa.selenium.remote.CapabilityType;Importorg.openqa.selenium.remote.DesiredCapabilities; ImportJava.io.File; ImportJava.net.URL; Importjava.util.List;ImportJava.util.concurrent.TimeUnit; Public classMytestcase {PrivateAndroiddriver driver; @Before Public voidSetUp ()throwsException {//set the path of the APKFile Classpathroot =NewFile (System.getproperty ("User.dir")); File Appdir=NewFile (Classpathroot, "apps"); File app=NewFile (Appdir, "calculator_debug_2.3.1_10000_svn80220_200_staging_2017_12_16.apk"); //setting Automation-related parametersDesiredcapabilities capabilities =Newdesiredcapabilities (); Capabilities.setcapability ("PlatformName", "Android"); Capabilities.setcapability ("DeviceName", "7n2sse158p001892"); Capabilities.setcapability ("DeviceName", "p4m7n15104001008"); //setting up the Android system versionCapabilities.setcapability ("Platformversion", "4.4.2"); Capabilities.setcapability ("Platformversion", "6.0"); //Set APK pathCapabilities.setcapability ("App", App.getabsolutepath ()); //set the app's main package name and main class nameCapabilities.setcapability ("Apppackage", "Com.gomo.calculator"); Capabilities.setcapability ("Appactivity", ". Ui.activity.MainActivity"); //InitializeDriver =NewAndroiddriver (NewURL ("Http://127.0.0.1:4723/wd/hub"), capabilities); Driver.manage (). Timeouts (). Implicitlywait (30, Timeunit.seconds); } @After Public voidTearDown ()throwsException {driver.quit ();//Driver.closeapp ();//Driver.launchapp ();} @Test Public voidTest_add () {driver.findelement (By.id ("Com.gomo.calculator:id/input_num_1") . Click (); Driver.findelement (By.id ("Com.gomo.calculator:id/display_op_add") . Click (); Driver.findelement (By.id ("Com.gomo.calculator:id/input_num_2") . Click (); Driver.findelement (By.id ("Com.gomo.calculator:id/display_eq") . Click (); System.out.println ("Test_add Success!!!"); } @Test Public voidTest_mul () {driver.findelement (By.id ("Com.gomo.calculator:id/input_num_3") . Click (); Driver.findelement (By.id ("Com.gomo.calculator:id/op_mul") . Click (); Driver.findelement (By.id ("Com.gomo.calculator:id/input_num_4") . Click (); Driver.findelement (By.id ("Com.gomo.calculator:id/display_eq") . Click (); System.out.println ("Test_mul Success!!!"); }}
Python Edition: Writing app automation test cases with Python and unittest
Writing app automation test cases with Java and JUnit