Writing appium use cases with idea

Source: Internet
Author: User
Tags appium

1. Install CONTACTMANAGERS.SPK:

Path APPS/CONTACTMANAGER/CONTACTMANAGERS.SPK

2. Open the use case to IntelliJ:

Open--Check appium/sample-code/examples/java/junit/pom.xml opens

3. Environment configuration:

If the dependent jar package is not loaded, you may need to configure the path of MAVEN

4. Run the test case:

Right-click to select Androidcontactstest-run ' Androidcontactstest '

Use Case appreciation:
Package Com.saucelabs.appium;import io.appium.java_client. Appiumdriver;import org.junit.after;import org.junit.before;import Org.junit.test;import org.openqa.selenium.By; Import Org.openqa.selenium.webelement;import Org.openqa.selenium.remote.capabilitytype;import Org.openqa.selenium.remote.desiredcapabilities;import Java.io.file;import Java.net.url;import java.util.List;    public class Androidcontactstest {private Appiumdriver driver; @Before public void SetUp () throws Exception {//Set up Appium file Classpathroot = new file (system.getp        Roperty ("User.dir")); File Appdir = new file (Classpathroot, ". /.. /..        /apps/contactmanager ");        File app = new file (appdir, "contactmanager.apk");        Desiredcapabilities capabilities = new Desiredcapabilities ();        Capabilities.setcapability ("Device", "Android");        Capabilities.setcapability (Capabilitytype.browser_name, "");        Capabilities.setcapability (Capabilitytype.version, "4.4"); Capabilities. Setcapability ("App", App.getabsolutepath ());        Capabilities.setcapability ("App-package", "Com.example.android.contactmanager"); Capabilities.setcapability ("App-activity", ".        Contactmanager ");    Driver = new Appiumdriver (New URL ("Http://0.0.0.0:4723/wd/hub"), capabilities);    } @After public void TearDown () throws Exception {driver.quit ();        } @Test public void Addcontact () {webelement el = driver.findelement (By.name ("Add contact");        El.click ();        list<webelement> textfieldslist = Driver.findelementsbyclassname ("Android.widget.EditText");        Textfieldslist.get (0). SendKeys ("Some Name");        Textfieldslist.get (2). SendKeys ("[email protected]");        Driver.swipe (100, 500, 100, 100, 2);    Driver.findelementbyname ("Save"). Click (); }}
Two. Create your own test project
    1. Step: New Project--Maven--Enter project name--project Location--next--Next

    2. Join Pom Dependency

    <dependencies> <dependency> <groupId>junit</groupId> <artifact        Id>junit</artifactid> <version>4.11</version> <scope>test</scope>            </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>LATEST</version> < scope>test</scope> </dependency> <dependency> <groupid>io.appium</g        Roupid> <artifactId>java-client</artifactId> <version>1.0.2</version>            </dependency> <dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1</version> <scop E>test</scope>       </dependency> <dependency> <groupId>commons-lang</groupId> &lt ;artifactid>commons-lang</artifactid> <version>2.6</version> <scope>test& Lt;/scope> </dependency> <!--includes the Sauce JUnit Helper Libraries--<depend Ency> <groupId>com.saucelabs</groupId> &LT;ARTIFACTID&GT;SAUCE_JUNIT&LT;/ARTIFACTID&G            T <version>1.0.18</version> <scope>test</scope> </dependency> &LT;DEP Endency> <groupId>com.google.code.gson</groupId> <artifactid>gson</artifacti         d> <version>2.2.4</version> </dependency> </dependencies> <build>            <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-surefire-plugin</artifactId> </plugin> <plugin>                    <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> &LT;/CONFIGURATION&G            T </plugin> </plugins> </build> <repositories> <repository> &lt ;id>saucelabs-repository</id> <url>https://repository-saucelabs.forge.cloudbees.com/release</            url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </reposi Tory> </repositories>
Use case start
Package Com.wirelessqa.android;import io.appium.java_client. Appiumdriver;import org.junit.after;import org.junit.before;import org.junit.test;import static org.junit.Assert.*; Import Org.openqa.selenium.by;import Org.openqa.selenium.webdriver;import Org.openqa.selenium.webelement;import Org.openqa.selenium.firefox.firefoxdriver;import Org.openqa.selenium.remote.capabilitytype;import Org.openqa.selenium.remote.desiredcapabilities;import Org.openqa.selenium.remote.remotewebdriver;import Org.openqa.selenium.support.ui.expectedcondition;import Org.openqa.selenium.support.ui.webdriverwait;import Java.io.file;import java.net.url;import java.util.concurrent.timeunit;/** * Created by Bixiaopeng on 14-5-13.    */public class Appium {private Appiumdriver driver;        @Before public void SetUp () throws Exception {file Classpathroot = new File (System.getproperty ("User.dir"));        File Appdir = new file (classpathroot, "apk");        File app = new file (appdir, "xiamimusic.apk");System.out.print (App.getabsolutepath ());        Desiredcapabilities capabilities = new Desiredcapabilities ();        Capabilities.setcapability (Capabilitytype.browser_name, "");        Capabilities.setcapability (Capabilitytype.version, "4.4");        Capabilities.setcapability ("App", App.getabsolutepath ());        Capabilities.setcapability ("App-package", "Fm.xiami.main");        Capabilities.setcapability ("App-activity", "fm.xiami.bmamba.activity.StartActivity");    Driver = new Appiumdriver (New URL ("Http://0.0.0.0:4723/wd/hub"), capabilities); } @Test public void login () throws Exception {//Determines whether an element displays an if (Driver.findelement (By.name ("Create desktop shortcut        "). Isdisplayed ()) {Driver.findelement (By.name (" OK ")). Click ();        } driver.findelement (By.name ("My Music")). Click ();        Driver.findelementbyname ("Click on Avatar Login"). Click ();        Driver.findelementbyname ("Shrimp account Login"). Click ();    Enter the character driver.findelementbyname ("Enter email address"). SendKeys ("********");    Find Driver.findelement by ID (by.id ("Fm.xiami.main:id/edit_password")). SendKeys ("* * *");        Driver.findelementbyid ("Fm.xiami.main:id/btn_login"). Click ();        String userName = Driver.findelementbyid ("Fm.xiami.main:id/user_name"). GetText ();    Assert Assertequals (UserName, "Lao bi");    } @After public void TearDown () throws Exception {driver.quit ();     }}
Note the selection of JDK versions

Open Module Setting--Language level:5.0


Public account: WIRELESSQA

About

Author: Bi Xiaobong | Old bi e-mail: [email protected]

Weibo:   @WirelessQA   blog:   HTTP://BLOG.CSDN.NET/WIRELESSQA

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.