Appium learn a variety of small functions summary-the function of "sliding pictures, save screenshots, verify the existence of elements,"---beginner summary (Daniel do not spray, novice to communicate with each other)

Source: Internet
Author: User
Tags appium

1. Home Slide Image Click

1    /**2 * This Method for swipe left3 * Large distance sliding WIDTH/6 the larger the divisor, the greater the left sliding distance. 4 * width:7205 *height:12806          * @author Young7          * @paramDriver28          * @paramduring9          */Ten          Public voidSWIPETOLEFT2 (Androiddriver Driver2,intduring) { One             intwidth =driver2.manage (). window (). GetSize (). width; A            //System.out.println ("width:" +width); -             intHeight =driver2.manage (). window (). GetSize (). Height; -             //System.out.println ("Height:" +height); the             //driver2.swipe (Width * 3/4, HEIGHT/2, WIDTH/4, HEIGHT/2, during); -Driver2.swipe (Width * 8/9, HEIGHT/2, WIDTH/8, HEIGHT/2, during); -             //wait for page loading -}

How to use:

SWIPETOLEFT2 (driver,3000);

2. Save

  /** * This Method create for take screenshot * Capture function * @author young * @param drivername * @param fil     ename * Call Snapshot ((takesscreenshot) driver, "zhihu_showclose.png"); */public static void Snapshot (Takesscreenshot drivername, String filename) {//The This method would take the screen sh OT, require, parameters, one is//driver name, another is file name String Currentpath = System.getprope Rty ("User.dir"); Get current work//folder File Scrfile = Drivern        Ame.getscreenshotas (Outputtype.file); Now you can do whatever need to do with it, for example copy//somewhere try {System.out            . println ("Save snapshot Path is:" + Currentpath + "/" + filename);        Fileutils.copyfile (Scrfile, New File (Currentpath + "\ \" + filename); } catch (IOException e) {System.out.println ("Can ' t save ScreenshoT ");        E.printstacktrace ();        } finally {System.out.println ("screen shot finished, it's in" + Currentpath + "folder"); }    }

How to use:

Snapshot ((takesscreenshot) driver, "firstjt.png");

3. Verify that the element exists

Verify that the login element exists public  Boolean iselementexsitandroid (Androiddriver Driver,by elemnt) {Boolean flag = false;           try {               webelement element=driver.findelement (elemnt);               flag=null!=element;           } catch (Nosuchelementexception e) {               System.out.println ("Element:" + elemnt.tostring ()                       + "is not exsit!");              Flag=false;                   }           return flag;  }   

How to use:

Iselementexsitandroid (Driver,by.id ("Com.zhanglb.yijiebao:id/editremark"));

4.appium initialization:

/** * Android Configuration Item initialization * */public androiddriver appconfige (androiddriver driver) {//Set apk path File classpathroot = new       File (System.getproperty ("User.dir"));       File Appdir = new file (Classpathroot, "apps");              File app = new file (appdir, "debuglemonoa.apk");       Set automation-related parameters desiredcapabilities capabilities = new Desiredcapabilities (); Capabilities.setcapability (Capabilitytype.browser_name, "");       This sentence is not necessary//start which device, is the real machine or the simulator? Capabilities.setcapability ("DeviceName", "Android Emulator");       Android Simulator//use which platform Capabilities.setcapability ("PlatformName", "Android");              Set up Android version capabilities.setcapability ("Platformversion", "4.4.2");        Set apk path Capabilities.setcapability ("app", App.getabsolutepath ());       Set name time-out time//capabilities.setcapability ("Newcommandtimeout", 30);       The time, in milliseconds, to wait for the Webview context to activate//capabilities.setcapability ("Autowebviewtimeout", 10); Wait for the device to be ready when the app is started.      The unit is in seconds. Capabilities.setcapability ("Androiddevicereadytimeout", 10);              Mobile browser name Chromium Google Chrome//Capabilities.setbrowsername ("Chromium");       Set the app's main package name and main class name main parameters appactivity Note that the native app should add a "." Before the activity.       Capabilities.setcapability ("Apppackage", "Com.zhanglb.yijiebao");      Capabilities.setcapability ("Appactivity", "com.hzh.main.WelcomeActivity");       Capabilities.setcapability ("Apppackage", "Com.qihoo.util"); Capabilities.setcapability ("Appactivity", ".              StartActivity ");        Initialize//driver = new androiddriver<> (New URL ("Http://127.0.0.1:4723/wd/hub"), capabilities);       Driver=new androiddriver<> (New URL ("Http://127.0.0.1:4723/wd/hub"), capabilities);       try {driver = new Androiddriver (New URL ("Http://127.0.0.1:4723/wd/hub"), capabilities);       } catch (Malformedurlexception e) {//TODO auto-generated catch block E.printstacktrace (); } return driver;}

Appium learn a variety of small functions summary-the function of "sliding picture, save, verify the existence of elements,"---beginner summary (Daniel do not spray, novice to communicate with each other)

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.