Appium - Capture Screenshot Android App Mobile Screen

Capturing screenshot in appium android automation Is original requirement for whatever software automation tool. During software automation testing process, It should permit yous to capture screenshot automatically to present põrnikas or approximately blueprint Issue to development/design team. For android software application automation testing using appium, We tin piece of job TakesScreenshot Interface of WebDriver to capture screenshot of android app screen. I stimulate got prepared uncomplicated representative on how to capture screenshot In android appium automation software exam using TakesScreenshot Interface of WebDriver.

App To Use Capture Screenshot Test
We volition use API Demos android software app for Capture Screenshot test. You tin download it from HERE.

Aim to Achieve In Capture Screenshot Test
We wants to capture screenshot of android mobile covert on approximately phase of appium automation test. And hence nosotros volition shop It Inside screenshots folder nether project. We volition produce file refer using electrical flow appointment fourth dimension programmatically every bit shown In bellow Image.


Above Image shows screenshot which Is taken during android appium automation test.

Create And Run Capture Screenshot Test
Create novel file CaptureScreenShot.java file nether your Android packet of your projection in addition to write bellow given exam script In It.

package Android;  import io.appium.java_client.android.AndroidDriver;  import java.io.File; import java.io.IOException; import java.net.URL; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.concurrent.TimeUnit; import org.apache.commons.io.FileUtils; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  populace degree CaptureScreenShot {  AndroidDriver driver;  Dimension size;  String destDir;  DateFormat dateFormat;   @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", "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  populace void ScrollToTab() {   // Scroll till chemical cistron 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 cistron which contains "Tabs" text If It Is non visible on screen.   driver.scrollTo("Tabs");   //Call takeScreenShot() component subdivision to capture screenshot of android screen.   takeScreenShot();   }   populace void takeScreenShot() {   // Set folder refer to shop screenshots.   destDir = "screenshots";   // Capture screenshot.   File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);   // Set appointment format to laid It every bit screenshot file name.   dateFormat = novel SimpleDateFormat("dd-MMM-yyyy__hh_mm_ssaa");   // Create folder nether projection alongside refer "screenshots" provided to destDir.   novel File(destDir).mkdirs();   // Set file refer using electrical flow appointment time.   String destFile = dateFormat.format(new Date()) + ".png";    try {    // Copy glue file at finish folder location    FileUtils.copyFile(scrFile, novel File(destDir + "/" + destFile));   } grab (IOException e) {    e.printStackTrace();   }  }   @AfterTest  populace void End() {   driver.quit();  } }

Test Description
Above android appium software exam volition navigate to Views covert in addition to scroll downwardly till Tabs text on API Demos android app. Then It volition call takeScreenShot(); method to capture in addition to shop android app screenshot. takeScreenShot() method will,
  • Capture screenshot using TakesScreenshot Interface of webdriver.
  • Get electrical flow appointment in addition to fourth dimension in addition to shop It inwards variable.
  • Create novel folder alongside refer "screenshots" nether your project.
  • Set file refer using electrical flow appointment in addition to time.
  • Store file In "screenshots" folder.
When yous run higher upwardly test, It volition create screenshots folder nether your projection in addition to shop screenshot file In It. Refresh your projection folder afterwards exam execution to come across novel created folder in addition to screenshot file.

This means yous tin capture in addition to shop screenshot of whatever android 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