Integrate JBehave with Universal Agent

In this article you will learn how to integrate JBehave with the Universal Agent

The sample source code of JBehave project is located at https://github.com/QASymphony/jbehave-agent-sample

Prerequisites

  1. Activate Automation Integrations

  2. Install and Register the Automation Host

  3. The sample project uses Selenium that opens a Chrome browser and performs some actions on it, so make sure you install Google Chrome to the host machine

  4. You machine needs to have Java installed. The Java version should be the one compatible with what you use to run your TestNG project

  5. This example use Maven to execute the tests. Make sure you install maven to the Automation Host machine

  6. Along with Maven, this example also uses maven-compiler-pluginmaven-failsafe-plugin and jbehave-maven-plugin to run JBehave.tests and generate report.

    Refer to the IMPORTANT NOTES section to configure the pom.xml file when you integrate your actual JBehave.project with Universal Agent

Create JBehave.Universal Agent

  1. From Launch, open the host machine where you want to create the new agent.

  2. Select the + New Agent button.

  3. The New Agent dialog will display.

  4. Enter the information below for the new agent.

General Agent Information

  • Agent Name: name of the agent, e.g. JBehave.Universal Agent

  • qTest Manager Project: select a qTest Manager project from which the agent is going to execute scheduled tests, e.g. qConnect Sample Project

  • Agent Type: Universal Agent

Pre-Execute Script

Enter the script below in the Pre-Execute Script editor, which is specific to the Operating System that the host is running.

Linux/Mac

#!/bin/bash 
if [ ! -d "/usr/local/var/jbehave-agent-sample" ]
then
  cd "/usr/local/var"
  git clone https://github.com/QASymphony/jbehave-agent-sample 
else
  cd /usr/local/var/jbehave-agent-sample
  git pull --all 
fi

Windows

if not exist "D:\jbehave-agent-sample" (
  cd /d D:\
  git clone https://github.com/QASymphony/jbehave-agent-sample 
) else (
  cd /d "D:\jbehave-agent-sample"
  git pull --all 
)

Execute Command

Executor

  • If your host machine is running on Linux or Mac, select shell as the executor.

  • If your host machine is running on Windows, select batch as the executor.

Working Directory

  • If your host machine is running on Linux or Mac. enter /usr/local/var/jbehave-agent-sample

  • If your host machine is running on Windows. enter D:\jbehave-agent-sample

Execute Command

We will enter a command to Execute Command editor to execute our sample JBehave.project using Maven.

Notes:

  • make sure you install maven to your host machine for the command to be executed successfully by Universal Agent

  • the execute command will need to specify full path to maven executable. You can execute the following command to find the Maven executable path from either Terminal (Linux/Mac. or Command Prompt (Windows), in bold.

    $ mvn -v
    Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T14:41:47-04:00)
    Maven home: /usr/local/Cellar/maven/3.6.0/libexec
    Java version: 10.0.2, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home
    Default locale: en_US, platform encoding: UTF-8
    OS name: "mac os x", version: "10.14.2", arch: "x86_64", family: "mac"
    

Now enter command below to Execute Command editor.

Linux or Mac

/usr/local/Cellar/maven/3.6.0/libexec/bin/mvn clean integration-test 

Windows

C:\\apache-maven-3.6.0\\bin\\mvn clean integration-test 

Path to Results

Optional field. Enter the value below to specify the path to the test result generated by JBehave.project

  • If your host machine is running on Linux or Mac: /usr/local/var/jbehave-agent-sample/target/failsafe-reports/TEST-org.qas.jbehave.example.stories.ExampleStories.xml

  • If your host machine is running on Windows: D:\jbehave-agent-sample\target\failsafe-reports\TEST-org.qas.jbehave.example.stories.ExampleStories.xml

Result Parser

Optional field. Select JUnit for Java as the Result Parser.

If you want the Universal Agentto submit test results to qTest Manager, you must specify values for both Path to Results and Result Parser. Otherwise, you must do that yourself via Execute Command.

The screenshot below shows how the new JBehave.Universal Agentis configured, on Mac.

Select SAVE to finish creating the agent. The agent will be available the next time the host machine polls to qTest Launch.

Execute JBehave.Universal Agent

  1. Access the host machine where the JBehave.Universal Agentwas created.

  2. Locate the agent in the Agents list and select the Run now button.

  3. The Universal Agentexecution dialog will display.

  4. Select the Execute button to kick off the agent execution and you will see the logs shown in the Console Log section. If the execution is successful, you'll see the test run logs being submitted to qTest Manager.

Next, access to qTest Manager. Select qConnect Sample Project then go to Test Execution module. You'll see the test results submitted to qTest Manager as Test Runs under a Test Suite naming Automation YYYY-MM-DD, as below.

Now we are going to schedule Test Execution for the test run with the JBehave.Universal Agentagent.

Schedule Test Execution for the Test Run(s)

From qTest Manager, select the project qConnect Sample Project then click on Test Execution tab. Do the followings:

  1. Select the newly created test suite, in our example, it is Automation 2019-01-08.

  2. From the test run list on the right, select the first test run.

  3. Click theMORE drop-down, and select Schedule.

On SCHEDULE AUTOMATION TEST EXECUTION dialog, enter the followings:

  1. Name: name of the schedule, e.g.Execute Tests with JBehave.Universal Agent

  2. Agent: select the Cucumber agent we created previously

  3. Click OK button to complete Test Execution scheduling for the selected three test runs.

  4. Now go back to Automation Host UI. Click Poll Now button.

  5. At this stage, the Automation Host does the following:

    • immediately polls to qTest Manager to load schedule jobs and

    • execute the job execution for the test/story in JBehave project

  6. When the execution completes, click on View Log icon to view execution log.

  7. Now get back to Test Execution of qConnect Sample Project in qTest Manager.

  8. Click on each test run that was scheduled to be executed, you'll see the Execution History of the test run was updated with 2 test run logs:

    • one test log created when the agent was executed in the first time,

    • and one test log for the scheduled job execution.

You have successfully integrated and scheduled Test Execution for your JBehave.project with Universal Agent and had it report the Test Execution to qTest Manager.

IMPORTANT NOTES

When integrating your actual JBehave.project with Universal Agentand you choose to execute it with Maven (highly recommended), you must add these plugins maven-compiler-pluginmaven-failsafe-plugin and jbehave-maven-plugin to your pom.xml file, as shown below.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    ... 
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${failsafe.and.surefire.version}</version>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includes>
                        <include>**/*Stories.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jbehave</groupId>
                <artifactId>jbehave-maven-plugin</artifactId>
                <version>${jbehave.version}</version>
                <executions>
                    <execution>
                        <id>run-stories-as-embeddables</id>
                        <phase>integration-test</phase>
                        <configuration>
                            <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
                            <includes>
                                <include>**/*Stories.java</include>
                            </includes>
                            <ignoreFailureInStories>false</ignoreFailureInStories>
                            <ignoreFailureInView>false</ignoreFailureInView>
                            <metaFilters>
                                <!--<metaFilter>${meta.filter}</metaFilter>-->
                                <metaFilter>-skip</metaFilter>
                            </metaFilters>
                        </configuration>
                        <goals>
                            <goal>run-stories-as-embeddables</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        <plugins>
    </build>
    <!-- End configuration -->
</project>

You can also refer to the pom.xml file used in our sample here: https://github.com/QASymphony/jbehave-agent-sample/blob/master/org.qas.jbehave.example/pom.xml