Appium Small Example

Source: Internet
Author: User

Package com.saucelabs.appium;

Import Java.io.File;
Import Java.net.URL;
Import java.util.List;
Import Org.junit.After;
Import Org.junit.Before;
Import Org.junit.Test;
Import Org.openqa.selenium.By;
Import org.openqa.selenium.Capabilities;
Import Org.openqa.selenium.WebDriver;
Import org.openqa.selenium.WebElement;
Import Org.openqa.selenium.interactions.HasTouchScreen;
Import Org.openqa.selenium.interactions.TouchScreen;
Import Org.openqa.selenium.remote.CapabilityType;
Import org.openqa.selenium.remote.DesiredCapabilities;
Import Org.openqa.selenium.remote.RemoteTouchScreen;
Import Org.openqa.selenium.remote.RemoteWebDriver;

public class Androidcontactstest {
Private Webdriver driver;

@Before
public void SetUp () throws Exception {
File Classpathroot = new file (System.getproperty ("User.dir"));
File Appdir = new file (Classpathroot, "app");
File app = new file (appdir, "contactmanager.apk");
Desiredcapabilities capabilities = new Desiredcapabilities ();
Capabilities.setcapability ("Device", "Android");
Capabilities.setcapability ("PlatformName", "Android");
Virtual machines
Capabilities.setcapability ("DeviceName", "Android Emulator");
Real Machine
Capabilities.setcapability ("DeviceName", "Android");
Test machine Android version
Capabilities.setcapability ("Platformversion", "4.4");
Capabilities.setcapability (Capabilitytype.platform, "WINDOWS");
Capabilities.setcapability ("App", App.getabsolutepath ());
Capabilities.setcapability ("Apppackage", "Com.example.android.contactmanager");
Capabilities.setcapability ("Appactivity", ". Contactmanager ");
Driver = new Swipeablewebdriver (New URL ("Http://127.0.0.1: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.findelements (By.tagname ("TextField"));
Textfieldslist.get (0). SendKeys ("Some Name");
Textfieldslist.get (2). SendKeys ("[email protected]");
Driver.findelement (By.name ("Save")). Click ();
}

public class Swipeablewebdriver extends Remotewebdriver implements Hastouchscreen {
Private Remotetouchscreen touch;

Public Swipeablewebdriver (URL remoteaddress, capabilities desiredcapabilities) {
Super (remoteaddress, desiredcapabilities);
Touch = new Remotetouchscreen (Getexecutemethod ());
}

Public touchscreen Gettouch () {
return touch;
}
}
}

Appium Small Example

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.