A simple Appium script

Source: Internet
Author: User

This is a simple appium script that tests the Amazon shopping process, including searching for items, then selecting items from the results list, then adding to the cart, and so on.

It is a primitive script that does not encapsulate the test elements, data, reports, etc., and later plans to merge them into the existing Webdriver Web test framework.

The problem is finally reached in operation:

1, the Genymotion simulator performs a little delay, the script command issued about 3 seconds after the simulator to react;

2, after entering the search conditions, the execution of the carriage return command, the effect is the backspace bar (BACKSPACE), hundred tear not to ride elder sister Ah;

3, and then the non-native object recognition, such as WebView object, with the SDK Uiautomationviewer sometimes get the key attributes, then you can try to identify the PC side, and if an app is mobile-specific (not supported PC), Its identification please refer to another article

Http://www.cnblogs.com/jingwei/p/4739618.html

If you have done Web testing with Webdriver, look at this script should be very simple, similar to the test Web, the biggest difference is that the phone side of the test, you need to specify desire capacity some properties, such as device name, test Platform, test platform version, the package of the app being tested.

 Public classContacttest {PrivateWebdriver Driver; //private Androiddriver driver; //private Appiumdriver driver;@Before Public voidSetUp ()throwsException {//Set up AppiumFile Classpathroot=NewFile (System.getproperty ("User.dir")); System.out.println (System.getproperty ("User.dir")); File Appdir=NewFile (Classpathroot, "app"); File app=NewFile (Appdir, "com.amazon.mShop.android093010.apk"); Desiredcapabilities Capabilities=Newdesiredcapabilities ();
Predefined capabilities.setcapability for test devices and apps (Capabilitytype.browser_name,
""); //capabilities.setcapability ("DeviceName", "Android Emulator");Capabilities.setcapability ("DeviceName", "Android Emulator"); Capabilities.setcapability ("Platformversion", "4.4.4"); Capabilities.setcapability ("PlatformName", "Android"); Capabilities.setcapability ("App", App.getabsolutepath ()); Capabilities.setcapability ("App-package", "com.amazon.mShop.android"); Capabilities.setcapability ("App-activity", "com.amazon.mShop.splashscreen.StartupActivity"); //Driver = new Androiddriver<webelement> (The new URL ("http://127.0.0.1: 4723/wd/hub "), capabilities);System.out.println ("OK??")); //Driver = new Androiddriver (New URL ("Http:/127.0.0.1:4723/wd/hub"), capabilities);Driver =NewSwipeablewebdriver (NewURL ("Http://127.0.0.1:4723/wd/hub"), capabilities); } @After Public voidTearDown ()throwsException {driver.quit (); } @Test Public voidaddcontact () {System.out.println ("Start Test"); Wait (10); if( This. elementexist (Driver, by.id ("Com.amazon.mshop.android:id/skip_sign_in_button"))); {Wait (2); Driver.findelement (By.id ("Com.amazon.mshop.android:id/skip_sign_in_button") . Click (); } Wait (5); Webelement Search= Driver.findelement (By.id ("Com.amazon.mshop.android:id/search_edit_text")); Search.Click (); Wait (2); Webelement SEARCH2= Driver.findelement (By.id ("Com.amazon.mshop.android:id/rs_search_src_text")); Search2.sendkeys ("Huawei"); Search2.sendkeys (Keys.enter); Wait (2); List<WebElement> searchlist = driver.findelements (By.id ("Com.amazon.mshop.android:id/rs_search_dropdown_item_ Text)); for(webelement l:searchlist) {System.out.println (L.gettext ()); } System.out.println (Searchlist.size ()); if(Searchlist.size () >0) Searchlist.get (0). Click (); Wait (5); Webelement honor3c= Driver.findelement (By.name ("Huawei Honor 3C Android 4.2 Quad Core 1.3GHz 3G" + "Dual Sim 5.0 Inch HD to Uch screen 2GB RAM unlocked 3G Smartphone Black ")); Honor3c.click (); Here you can continue to add other operations to the shopping/*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 (); */System.out.println ("Test End"); } Public classSwipeablewebdriverextendsRemotewebdriverImplementsHastouchscreen {PrivateRemotetouchscreen Touch; PublicSwipeablewebdriver (URL remoteaddress, desiredcapabilities capabilities) {Super(remoteaddress, capabilities); Touch=NewRemotetouchscreen (Getexecutemethod ()); } Publictouchscreen Gettouch () {return(touchscreen) touch; } } Public Booleanelementexist (Webdriver driver, by Pro) {Try{driver.findelement (pro); return true; }Catch(nosuchelementexception e) {return false; } } Public voidWaitinti) { Try{thread.sleep (i*1000); } Catch(interruptedexception e) {//TODO auto-generated Catch blockE.printstacktrace (); } } }

A simple Appium script

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.