Komal Batra

Komal Batra

Recent Posts

Tutorial: Inspect your Mobile Apps with Appium Desktop & Macaca Inspector

Posted by Komal Batra on Apr 26, 2019 5:04:00 PM

A high-quality and robust app can be produced only with regression testing. Mobile Test Automation increases test efficiency, effectiveness while also enabling faster time-to-market for apps.

While there are various test automation frameworks and tools like Monkey Talk, Robotium, Selendroid, Appium Desktop, UIAutomator, Testdroid etc. to execute test automation effectively and conveniently, we will discuss Appium Desktop and Macaca Inspector.

One of the most significant tests automation frameworks, Appium provides a graphical frontend and inspect applications through Appium Desktops.

In simpler words, Appium Desktop is a graphical interface for starting an Appium server and inspecting the app's structure via Appium. While Macaca is an open-source automation test solution for native, hybrid, mobile web and web application on mobile and desktop platforms.

Here’s a step-by-step guide to inspect mobile applications using Appium Desktop Inspector and Macaca Inspector.

Getting Started

Using Appium Desktop

To write mobile automation scripts with Appium, we need to, first, run Appium Server and also a mechanism to identify the controls/elements of the mobile app which we want to automate.

Considering Appium with global packages is already installed, one of the ways to launch the Appium server is via  Appium Desktop.

appium-desktop-srijan-technologies

To start the server, simply click on Start Server Button.  

After the server has been started, Inspector option is displayed using which we can get the properties of the elements in mobile application

  1. Start your inspector session with Appium Desktop Inspector by clicking on the search icon.

apium-srijan-technologies 1

 2. After the inspector session is launched, you will see the following view on your screen.

automatic-server-srijan-technologies

You can, now, inspect by creating a new session.

   a) Click on ‘Desired Capabilities’ tab
   b) Input the necessary desired capabilities in ‘JSON representation’ tab.

automatic-server-srijan-technologies-2

    3.Click on the ‘Start Session’

       After this, the simulator with the configuration as (stated in desired capabilities)  will be                             launched and the app will be installed. You can access the path through app desired capability.

 Inspect with Existing Session

         If we already have an Appium script.

              a. Run Your Existing Appium Script and your session id will be generated.

              b. As we click on the inspector icon, current session id will be displayed automatically in the                       text box as shown in the screenshot below.

          c. Next, click on ‘Attach to the Session’ tab to attach the current session with the appium                            inspector.

automatic-server-srijan-technologies-capabilities

Simulator with the configuration as stated in the script or in desired capabilities will be launched along with the appium desktop inspector view.

srijan-assistant

And Appium Desktop Inspector View will be displayed that contains the

    1. The App View of the application
    2. The App source / DOM
    3.  Properties of the selected element

srijan-assistant-1

Click an element in the app view whose locator we want to know, it automatically selects the element in the Source and the properties of that element are displayed on the right side.

The properties include the selectors - xpath , class , id , name etc.

Inspecting Mobile Elements Using Macaca Inspector 

Install Application Inspector with  

$ npm i app-inspector -g

Launch from the cli with

$ app-inspector -u YOUR-DEVICE-ID

YOUR-DEVICE-ID is the udid of the device in case of IOS. For Android, simply launch your device first, then use adb to list all your devices.

$ adb devices

After the $ app-inspector -u YOUR-DEVICE-ID command is run then open the following link http://192.168.10.100:5678 in your browser.

Now Macaca App Inspector displays the view as shown below.
macaca-app-inspector-srijan-technologies

Simply Click on the element in the app view and see the DOM/Source in the next panel and the properties on the right side of the selected element.

       Done!

And that’s how you can inspect mobile application elements in easy steps. You can use it in your appium scripts for automation of mobile application.

We provide unified Test Automation Framework and tools to enable easy automation for you. Not only it saves up your many hours, but it reduces the operating cost too. Get in touch with our experts at business@srijan.net to know more about high-quality test automation solutions.

Topics: Coding and Tutorial

Interactive and Detailed Automated Test Case Reports

Posted by Komal Batra on Dec 4, 2018 3:57:00 PM

Reporting element in test automation framework plays an important role. The success of a test automation framework and its survival depends on how effectively reporting mechanism is implemented.

To transfer the information from the development team to the customer/business team, a detailed and interactive report of test case is required.

There are various reporting libraries that an automation framework designer can use for the reporting component. One of them is the Extent HTML Report, which provides beautiful, detailed and interactive report of automated tests.

Extent HTML Report

It is an interactive reporting mechanism which can be integrated with a Selenium test automation framework.

There are many features provided by extent report:

  • Dashboard - provides detailed and graphical analysis of the project
  • Interactive – an interactive HTML format report with a lot of UI widgets.
  • Integration Support - can be configured with Java(JUnit , TestNG) and .Net(NUnit) test automation frameworks.
  • Detailed Information - provides detailed information of the test cases including the details of the failure test cases.

How to generate Extent Report

#Step 1: Download the Extent Report libraries and add them to your Selenium project. Or add below in pom.xml

<dependency>   

<groupId>com.aventstack</groupId>   

<artifactId>extentreports</artifactId>   

<version>3.1.5</version>

</dependency>

#Step 2: Create a java folder say utils , add another folder - Listeners and Create a class - extentListener that implements ITestListener and add the following code

Package utils.Listeners;

import java.io.IOException;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.reporter.*;

import baseFunctions;
public class extentListener extends baseFunctions implements ITestListener {
public static String testName;
ExtentHtmlReporter htmlReporter;
ExtentReports extent;
public static ExtentTest test;

@Override
public void onStart(ITestContext context) {
    htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +    "/test-output/TestResultsReport.html");
    ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(fileName);
    htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
    htmlReporter.config().setChartVisibilityOnOpen(true);
    htmlReporter.config().setTheme(Theme.STANDARD);
    htmlReporter.config().setDocumentTitle("XYZ.com");
    htmlReporter.config().setEncoding("utf-10");
    htmlReporter.config().setReportName("Automation Report")
    extent = new ExtentReports();
    extent.attachReporter(htmlReporter);
    return extent;

 }

@Override
public void onFinish(ITestContext context) {
    extent.flush();
}

@Override
public void onTestStart(ITestResult result) {
    test = extent.createTest(result.getName());
    testName = result.getName();
    test.log(Status.INFO, result.getName() + " Test has Started");
    System.out.println("*******TEST STARTED ******");
}

@Override
public void onTestSuccess(ITestResult result) {
    test.log(Status.PASS, result.getName() + " Test Passed Successfully");
}

@Override
public void onTestFailure(ITestResult result) {
    test.log(Status.FAIL, result.getName() + " Test is failed" +        result.getThrowable());
}

@Override
public void onTestSkipped(ITestResult result) {
    test.log(Status.SKIP, result.getName() + " Test is Skipped" +  result.getThrowable());
}

@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
}
}

#Step 3: For every failed assertion , attach screenshots in the report. Add the class SoftAssertionListener in the same utils folder

Package utils.Listeners;

import java.io.IOException;
import java.util.Map;

import org.testng.asserts.IAssert;
import org.testng.asserts.SoftAssert;
import org.testng.collections.Maps;

public class softAssertionListener extends SoftAssert {
private final Map<AssertionError, IAssert<?>> m_errors = Maps.newLinkedHashMap();

@Override
protected void doAssert(IAssert<?> a) {
onBeforeAssert(a);

try {
a.doAssert();
onAssertSuccess(a);
} catch (AssertionError ex) {
onAssertFailure(a, ex);
m_errors.put(ex, a);

try {
extentListener.test.fail("Snapshot below: " + extentListener.test.addScreenCaptureFromPath(baseFunctions.takeScreenShot(userjourney.methodName)));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Screenshot taken");
} finally {
onAfterAssert(a);
}
}
public void assertAll() {
if (!m_errors.isEmpty()) {
StringBuilder sb = new StringBuilder("The following asserts failed:"); boolean first = true;
for (Map.Entry<AssertionError, IAssert<?>> ae : m_errors.entrySet()) {
if (first) {
first = false;
} else {
sb.append(",");
}
sb.append("\n\t");
sb.append(ae.getKey().getMessage());
}
throw new AssertionError(sb.toString());
}
}
}

#Step 4: Execute your test cases and visualise your beautiful report

Here’s what the final reports look like:

Pass test case 

interactive-automation-test-case-report-srijan-1

Failed Test Case - includes screenshots & the failure details

interactive-automation-test-case-report-srijan-2

And that’s how you can create interactive and detailed automation test case reports.

Do you have some other tips and tricks for presenting automation test reports? Don’t forget to share them in the comments below.

Topics: QA and Testing

Discussion

Write to us

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms Of Service apply. By submitting this form, you agree to our Privacy Policy.

See how our uniquely collaborative work style, can help you redesign your business.

Contact us