24Sometimes you lot take away to press together with hold(long press) an element for few seconds to decease required effect In your android software app. In this instance nosotros tin use longPress(org.openqa.selenium.WebElement el) method of TouchAction flat In appium automation test. Earlier nosotros accept used longPress method to generate activeness chain of DRAG AND DROP, SWIPE ACTION together with MULTI TOUCH ACTION. Here I am presenting uncomplicated representative on exact usage of longPress method of TouchAction class In appium software automation test.
App To Use In This Test
We volition utilization android mobile Dialler app In this representative to sympathize usage of LongPress method. Dialler app volition live on Installed yesteryear default In all android devices together with then no take away to Install It.
Aim To Achieve
On dialler pad, 0 push has 2 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 set out textbox.
Create And Run Android Appium LongPress Test
Create novel flat file DialPad.java nether your project's parcel In eclipse together with re-create glue bellow given android appium software seek out 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 flat 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 upwards dialer pad. driver.findElementById("com.android.dialer:id/dialpad_button").click(); //Create object of TouchAction class. TouchAction Action = novel TouchAction(driver); //Create activeness chain using TouchAction flat reference to perform long press activeness on push 0 of dialer pad. Action.longPress(driver.findElement(By.name("0"))).perform(); //Get the effect from dial text box. String effect = driver.findElementById("com.android.dialer:id/digits").getText(); //Compare actual together with expected effect using testng assertion. Assert.assertEquals(result, "+", "Actual value is : "+ result+ " did non fit amongst expected value: +"); } @AfterClass populace void tearDown() { driver.quit(); } }
As you lot tin encounter In inward a higher house android appium software automation seek out script,
- First It volition launch dialler pad app using given parcel together with activity name.
- Open dialler pad yesteryear clicking on dial pad button.
- Action.longPress method Is used to press together with concur 0 push on dial pad.
- Next disputation volition decease text from dial text box.
- Used testng assertion Assert.assertEquals to compare actual together with expected result. You tin larn to a greater extent than close testng and It's assertions on THIS PAGE.
This Is the means of using longpress method of TouchAction flat to long press on whatever chemical component of your android software app.