Apache Ivy

Ivy is a tool for managing project dependencies, including recording, tracking, resolving, and reporting aspects of a project. This section walks you through setting up an Ivy project with Perfecto.

A sample project is available on GitHub: https://github.com/PerfectoMobileSA/PerfectoIvySample

Important: This document includes references to a third-party product, Apache Ivy. The user interface and usage of third-party products are subject to change without notice. For the latest published information about Apache Ivy, see https://ant.apache.org/ivy/history/latest-milestone/index.html.

1 | Get started

In this step, you install Java and Ant.

To get started:

  1. Download and install JDK 8.

  2. Set up the JAVA_HOME environment variable to point to the JDK 8 installation folder.

  3. Install Apache Ant.

  4. Download and install the IvyDE Eclipse plugin.

  5. Launch a command line window and run the following command to verify that the installation was successful:

    Copy
    ant -version

2 | Create and configure a project

In this step, you create a Java project and add the repositories and dependencies using Ivy and the plugins required to run it with Perfecto.

To create and configure a project:

  1. In your IDE, create a Java project.
  2. In the project's root folder, create a build.xml file and update it as follows. A sample build.xml file that includes all required properties and ant targets is available here.

    Copy

    Sample code

    <project name="PerfectoIvySample" xmlns:ivy="antlib:org.apache.ivy.ant">
        <property environment="env"/>
        <!-- some variables used -->
        <property name="basedir" value="." />
        <property name="lib.dir" value="lib" />
        <property name="build.dir" value="build" />
        <property name="bin.dir" value="bin" />
        <property name="src.dir" value="src" />
        <property file="ivysettings.properties" />
        <property name="report-dir" value="${basedir}/Test-Report" />
        <property name="testng-report-dir" value="${report-dir}/TestNGreport" />
        <property name="target" value="1.8" />
        <property name="source" value="1.8" />
        <property name="TestNGXmlFile" value="testng_Selenium.xml">
        
        </property>    <!-- paths used for compilation and run  -->
        <path id="build.classPath">
            <pathelement location="${bin.dir}" />
            <fileset dir="${lib.dir}">
                <include name="*.jar" />
                <include name="**/*.jar" />
            </fileset>
        </path>
        <path id="run.path.id">
            <path refid="build.classPath" />
            <path location="${build.dir}" />
        </path>
        
        <target name="clean">
            <delete dir="{bin.dir}"/>
        </target>
        <target name="bootstrap" description="Used to install the ivy task jar" depends="clean">
            <!--        <mkdir dir="${ant.home}/lib"/>-->
            <get dest="${ant.home}/lib/ivy.jar" src="https://repo1.maven.org/maven2/org/apache/ivy/ivy/2.5.0/ivy-2.5.0.jar"/>
        </target>    <!-- =================================
                  target: resolve
                 ================================= -->
        <target name="resolve" description="--> retreive dependencies with ivy" depends="bootstrap">
            <ivy:resolve />
            <ivy:retrieve/>
        </target>
        
        <!-- Compile the java code from ${src} into ${bin} -->
        <target name="compile" depends="resolve">
            <javac srcdir="${src.dir}" classpathref="build.classPath" includeAntRuntime="No" destdir="${bin.dir}" />
            <echo> /* Compiled Directory Classes */ </echo>
        </target>
        
        <target name="testng-execution" depends="compile">
            <taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="build.classPath"/>
            <mkdir dir="${testng-report-dir}" />
            <testng outputdir="${testng-report-dir}" classpathref="build.classPath" useDefaultListeners="true">
                <jvmarg value="-DcloudName=${cloudName}"/>
                <jvmarg value="-DsecurityToken=${securityToken}"/>
                <jvmarg value="-Dreportium-job-name=${reportium-job-name}"/>
                <jvmarg value="-Dreportium-job-number=${reportium-job-number}"/>
                <xmlfileset dir="${basedir}" includes="${TestNGXmlFile}" />
            </testng>            <!-- Runs the file and generates Reportng report for TestNG-->                        
        </target>
    </project>
  3. In the project's root folder, create an ivy.xml file and add the below dependencies. A sample file is located here.

    Copy

    Sample code

    <ivy-module version="2.0">
        <info organisation="org.perfecto.sample" module="PerfectoIvySample"/>
        <dependencies>
            <dependency org="io.appium" name="java-client" rev="6.1.0"/>
            <dependency org="org.seleniumhq.selenium" name="selenium-support" rev="3.141.59"/>
            <dependency org="org.seleniumhq.selenium" name="selenium-api" rev="3.141.59"/>
            <dependency org="org.testng" name="testng" rev="7.1.0"/>
            <dependency org="com.perfecto.reporting-sdk" name="reportium-java" rev="2.2.9"/>
            <dependency org="com.perfectomobile" name="pm-webdriver" rev="18.6.0.0"/>
            <dependency org="com.perfectomobile" name="http-client" rev="18.6.0.0"/>
            <dependency org="com.google.guava" name="guava" rev="25.0-jre"/>
        </dependencies>
    </ivy-module>
  4. In the project's root folder, create an ivysettings.xml file and add the following repositories. A sample file is located here.

    Copy

    Sample code

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <ivysettings>
        <settings defaultResolver="chain" />
        <resolvers>
            <chain name="chain">
                <ibiblio name="central" m2compatible="true" />
                <ibiblio name="Perfecto mobile" m2compatible="true" root="https://repo1.perfectomobile.com/public/repositories/maven" />
            </chain>
        </resolvers>
    </ivysettings>
  5. To download all dependencies, run the target with an Ivy resolve task (resolve).

3 | Execute TestNG tests

In this step, you run the tests. Optionally, you can also integrate with Perfecto Smart Reporting.

To execute TestNG tests: 

  1. Run the build.xml with the following Ant targets and properties:

    If credentials are hardcoded

    testng-execution

    If credentials are passed as parameters

    testng-execution -DcloudName=${cloudName} -DsecurityToken=${securityToken} -DTestNGXmlFile=testng_Perfecto.xml

    Ant automatically kick-starts the execution of testng_Selenium.xml. If you want to run mobile tests, providethe following:

    Copy
    DtestngXmlFile=testng_Perfecto.xml as Ant properties.
  2. To perform CI dashboard integration, supply the following properties to top-level Ant targets or the Ivy module configuration:

    Copy
      testng-execution
      -DcloudName=${cloudName}
      -DTestNGXmlFile=testng_Perfecto.xml
      -DsecurityToken=${securityToken}
      -Dreportium-job-name=${JOB_NAME}
      -Dreportium-job-number=${BUILD_NUMBER}
      -Dreportium-job-branch=${GIT_BRANCH}
      -Dreportium-tags=${myTag}

CI Dashboard integration

To integrate Ivy with Perfecto Smart Reporting, contact the Perfecto Professional Services team.

The following images show the PerfectoIvySample job in the CI Dashboard view and the sample Perfecto mobile web test report in the Report Library.