Appium - Perform LongPress Using TouchAction In Android Dialer App

24Sometimes y'all bespeak to press as well as hold(long press) an element for few seconds to drib dead required consequence In your android software app. In this instance nosotros tin sack use longPress(org.openqa.selenium.WebElement el) method of TouchAction cast In appium automation test. Earlier nosotros convey used longPress method to generate activity chain of DRAG AND DROP, SWIPE ACTION as well as MULTI TOUCH ACTION. Here I am presenting uncomplicated illustration on exact usage of longPress method of TouchAction class In appium software automation test.

App To Use In This Test
We volition usage android mobile Dialler app In this illustration to empathize usage of LongPress method. Dialler app volition survive Installed past times default In all android devices then no bespeak to Install It.

Aim To Achieve
On dialler pad, 0 push has ii functions. 1. It volition dial 0 on normal press. 2. It volition dial + on long press. Try It manually first.

In our appium software automation test, We volition long press 0 push of dialler pad to dial + equally shown In bellow Image. It volition type + In dial pose out textbox.


Create And Run Android Appium LongPress Test
Create novel cast file DialPad.java nether your project's parcel In eclipse as well as re-create glue bellow given android appium software evidence script In It.

DialPad.java
package Android;  import io.appium.java_client.TouchAction; import io.appium.java_client.android.AndroidDriver;  import java.net.URL; import java.util.concurrent.TimeUnit;  import org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  populace cast DialPad {  AndroidDriver driver;   @BeforeTest  populace void setUp() throws Exception {   DesiredCapabilities capabilities = novel DesiredCapabilities();   capabilities.setCapability("deviceName", "ZX1B32FFXF");   capabilities.setCapability("browserName", "Android");   capabilities.setCapability("platformVersion", "4.4.2");   capabilities.setCapability("platformName", "Android");   capabilities.setCapability("appPackage", "com.android.dialer");   capabilities.setCapability("appActivity","com.android.dialer.DialtactsActivity");   driver = novel AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);   driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);  }   @Test  populace void dial() {   //Click on dial pad push to opened upwardly dialer pad.   driver.findElementById("com.android.dialer:id/dialpad_button").click();   //Create object of TouchAction class.   TouchAction Action = novel TouchAction(driver);   //Create activity chain using TouchAction cast reference to perform long press activity on push 0 of dialer pad.   Action.longPress(driver.findElement(By.name("0"))).perform();   //Get the consequence from dial text box.   String consequence = driver.findElementById("com.android.dialer:id/digits").getText();   //Compare actual as well as expected consequence using testng assertion.   Assert.assertEquals(result, "+", "Actual value is : "+ result+ " did non represent alongside expected value: +");    }   @AfterClass  populace void tearDown() {   driver.quit();  } }

As y'all tin sack encounter In higher upwardly android appium software automation evidence script, 
  • First It volition launch dialler pad app using given parcel as well as activity name.
  • Open dialler pad past times clicking on dial pad button.
  • Action.longPress method Is used to press as well as agree 0 push on dial pad.
  • Next tilt volition drib dead text from dial text box.
  • Used testng assertion Assert.assertEquals to compare actual as well as expected result. You tin sack larn to a greater extent than nigh testng and It's assertions on THIS PAGE.
Run higher upwardly illustration using testng as well as let on execution In your android device screen. It volition dial + past times long press 0 button.

This Is the means of using longpress method of TouchAction cast to long press on whatever chemical factor of your android software app.

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post