Appium - Moving SeekBar Of Android App

In android software app, Seekbar Is an chemical part which allows y'all to laid progress flat past times moving draggable pollex In left or correct direction. It Is an extension of Progress Bar. Automating android seekbar movement in appium software automation Is slow but piddling tricky. We volition use TouchAction degree of appium to move sleek bar In correct or left management thence I recommend y'all to view THIS EXAMPLE to exceed to a greater extent than Idea most TouchAction degree as well as It's usage.

App To Use In This Test
Api Demos android software app volition help us to larn seekbar displace inwards appium thence download as well as Install It In your mobile device If It Is non Installed. You tin download it from THIS page too.

Aim Of This Test
I wants to set SeekBar pollex at my desired seat In X(horizontal) direction. Supposing I wants to laid It at 60% seat of full seekbar's width. We volition purpose appium TouchAction degree to displace seekbar pollex of android software app.

Create as well as Run Test
Create novel software test ControlSeekBar.java nether Android bundle of your projection In eclipse as well as position bellow given exam script Inside It.

ControlSeekBar.java
package Android;  import io.appium.java_client.TouchAction; import io.appium.java_client.android.AndroidDriver;  import java.io.IOException; import java.net.URL; import java.util.concurrent.TimeUnit;  import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  world degree ControlSeekBar {  Process p;  // Set path of your node.exe file.  // Progra ,1 represents Program Files folder.  String nodePath = "C:/Progra ,1/Appium/node.exe";  // Set path of your appium.js file.  String appiumJSPath = "C:/Progra ,1/Appium/node_modules/appium/bin/appium.js";  String cmd = nodePath + " " + appiumJSPath;  AndroidDriver driver;   // This method Is responsible for starting appium server.  world void appiumStart() throws IOException, InterruptedException {   // Execute command string to kickoff appium server.   p = Runtime.getRuntime().exec(cmd);   // Provide facial expression fourth dimension of 10 mins to kickoff appium server properly.   // If human face upward whatsoever error(Could non kickoff a novel session...) thence Increase this fourth dimension to twenty or 25 mins.   Thread.sleep(10000);   if (p != null) {    System.out.println("Appium server Is started now.");   }  }   // This method Is responsible for stopping appium server.  world void appiumStop() throws IOException {   if (p != null) {    p.destroy();   }   System.out.println("Appium server Is stopped now.");  }   @BeforeTest  world void setUp() throws Exception {   // Stop appium server If It Is already running.   appiumStop();   // Start appium server.   appiumStart();   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", "io.appium.android.apis");   capabilities.setCapability("appActivity", "io.appium.android.apis.ApiDemos");   driver = novel AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);   driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);  }   @Test  world void ScrollToView() {   // Scroll till chemical part which contains "Views" text If It Is non visible on screen.   driver.scrollTo("Views");   // Click on Views.   driver.findElement(By.name("Views")).click();   // Scroll till chemical part which contains "Seek Bar" text If It Is non visible on screen.   driver.scrollTo("Seek Bar");   // Click on Seek Bar.   driver.findElement(By.name("Seek Bar")).click();      //Locate SeekBar element.   WebElement seekBar=driver.findElementById("io.appium.android.apis:id/seek");   //Get kickoff indicate of seekbar.   int startX = seekBar.getLocation().getX();   System.out.println(startX);   //Get halt indicate of seekbar.   int endX = seekBar.getSize().getWidth();   System.out.println(endX);   //Get vertical location of seekbar.   int yAxis = seekBar.getLocation().getY();      //Set sllebar displace to position.    //endX * 0.6 way at 60% of assay bar width.   int moveToXDirectionAt = (int) (endX * 0.6);   System.out.println("Moving assay bar at " + moveToXDirectionAt+" In X direction.");      //Moving seekbar using TouchAction class.   TouchAction act=new TouchAction(driver);     act.press(startX,yAxis).moveTo(moveToXDirectionAt,yAxis).release().perform();    }   @AfterTest  world void End() throws IOException {   driver.quit();   // Stop appium server when exam Is ended.   appiumStop();  } }

Note : In inwards a higher house android software exam script, I convey also Included code to kickoff as well as halt appium server programatically. If y'all human face upward whatsoever Issue inwards starting as well as stopping appium server programatically thence take away appiumStart() and appiumStop() methods from inwards a higher house exam as well as deal to kickoff as well as halt It manually.

Test Description
In inwards a higher house software exam script,
  • First of all Navigated to SeekBar screen.
  • Then located seekBar webelement.
  • Get startX and endX of assay bar to exceed It's width on screen.
  • Then calculated moveToXDirectionAt value. moveToXDirectionAt Is seat where I wants to displace seekbar pollex In x direction. Here (endX * 0.6) Means It volition calculate 60% from full width of assay bar.
  • TouchAction degree Is used to practise as well as perform displace seekbar pollex activeness chain.
This Is the way to command seekbar of android app In appium automation test.

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