Pattern unlock with Appium

Source: Internet
Author: User
Tags appium

For the function of the pattern unlocking in the application, the use of appium can accomplish this function well.

Here is an example of a lock screen when the pattern is unlocked:

The pattern is set to:


Unlock in the lock screen:



When you get the coordinates of 9 points in a pattern, you can get them using the Hierarchyviewer tool in the SDK Tools directory.

The following code is unlocked:

Package Com.xuxu.autotest;import Java.net.url;import io.appium.java_client. Appiumdriver;import io.appium.java_client. Touchaction;import Io.appium.java_client.android.androiddriver;import Org.junit.after;import Org.junit.Before; Import Org.junit.test;import Org.openqa.selenium.remote.desiredcapabilities;public class Unlocktest {private Appiumdriver driver;public unlocktest () {} @Beforepublic void SetUp () throws Exception {Desiredcapabilities capabilities = new Desiredcapabilities (); Capabilities.setcapability ("DeviceName", "Android Emulator"); Capabilities.setcapability ("Platformversion", "4.4"); Capabilities.setcapability ("PlatformName", "Android"); Capabilities.setcapability ("Apppackage", "com.android.settings"); Capabilities.setcapability ("Appactivity", ". Settings ");d river = new Androiddriver (New URL (" Http://127.0.0.1:4723/wd/hub "), capabilities); Sleep (2000);} @Afterpublic void TearDown () throws Exception {Driver.quit ();} @Testpublic void Test () {driver.sendkeyevent (26);//press Power key to lock the screen sleep (3000);d River.sendkeyevent (26); Press the Power key to light the screen Driver.tap (1, 540, 960, 500); Touch the middle of the screen to show the Pattern Unlock Box Sleep (2000);//pattern unlock touchaction action = new touchaction (driver); Action.press (215, 870). MoveTo (540, 870). MoveTo (862, 870). MoveTo (540, 1195). MoveTo (215, 1195). MoveTo (215, 1518). MoveTo (862, 1518). MoveTo (862, 1195). Release (). perform (); private void sleep (int i) {try {thread.sleep (i);} catch (Interruptedexception e) {//TODO auto-generated catch Blocke.prin Tstacktrace ();}}}

Finally, attach a video of the unlocking process that was recorded using Screenrecord during the execution of the script:

Unlok.mp4

Pattern unlock with Appium

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.