Writing app automation test cases with Java and JUnit

Source: Internet
Author: User

 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.