Basic Keyword Development

This article explains Keywords in Step and demonstrates how to create simple ones.

Illustration for Basic Keyword Development

Getting Started

In this tutorial, we will demonstrate how to develop a simple keyword. Java will be utilized as our default language and platform and Maven will act as our dependency management and build tool. Alternatively, you can use other languages supported by Step (JS, .NET, etc.) as long as the dependencies are correctly downloaded and linked.

You can find details about the Keyword API itself here.

Prerequisites

You must have at least Java 8 SDK installed on your machine for Step Keyword development. There are several ways to install Java 8 SDK depending on your platform:

  • Windows: Refer to the official website and follow the instructions, Oracle Java download.
  • Debian/Ubuntu: Execute the following command as root: apt-get install default-jdk
  • Mac OS: Refer to the official website and follow the instructions, Oracle Java Max OS installation

Setting up Maven

Dependencies

We have created a public maven artifact available on our nexus for your convenience:

  <dependency>
	<groupId>ch.exense.step</groupId>
	<artifactId>step-api-keyword</artifactId>
	<version>1.1.3</version>
</dependency>
  

Maven Repository

Exense’s public repository is deprecated. As of version 3.6.1 and onwards, you should be able to pull our dependencies directly out of the public sonatype repository.

We recommend you set up the Maven compiler plugin to use Java 8 using the following code:

  <build>
<plugins>
 <plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.1</version>
  <configuration>
   <source>1.8</source>
   <target>1.8</target>
  </configuration>
 </plugin>
</plugins>
</build>
  

Your “pom.xml” should look like the code below:

  <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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.step</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>scripts-keyword-demo</artifactId>

<dependencies>
 <dependency>
  <groupId>ch.exense.step</groupId>
  <artifactId>step-api-keyword</artifactId>
  <version>1.1.3</version>
 </dependency>
</dependencies>
<build>
 <plugins>
  <plugin>
   <artifactId>maven-compiler-plugin</artifactId>
   <version>3.1</version>
   <configuration>
    <source>1.8</source>
    <target>1.8</target>
   </configuration>
  </plugin>
 </plugins>
</build>
</project>
  

Basic Example

The following examples apply to all languages supported by Step (i.e, Java, .NET, JS/NodeJS, etc). Syntax may vary due to the language’s specifics, but the objects exposed to the developer should not vary.

Java will be our default platform in our documentation. Make sure your Keyword class extends Step’s class step.handlers.javahandler.AbstractKeyword and that your dependencies have been set up.

Code

We will create a simple keyword by waiting for a period passed into the Input and adding a boolean with a value of true to the Output. Please see the code below:

  import step.handlers.javahandler.AbstractKeyword;
import step.handlers.javahandler.Keyword;

public class KeywordDemo extends AbstractKeyword {
  // Annotation tells step that this function can be used as a Keyword
  @Keyword()
  public void Sleep() throws NumberFormatException, InterruptedException {
   // Waiting for the period passed in Input
   Thread.sleep(Long.parseLong(input.getString("sleep")));
   // Add a boolean object to the Output
   output.add("success", true);
  }
}
  

Testing the Keyword Locally

The code below is an example of how you can run your keyword locally as a JUnit test.

  @Test
public void KeywordTest() throws Exception{
  ExecutionContext ctx = KeywordRunner.getExecutionContext(properties, this.getClass());
  Output output = ctx.run("Sleep", "{\"sleep\":\"100\"}");
  System.out.println(output.getPayload());
}
  

As a result of the execution, you should be able to see the following message in your console:

  2019-01-11 15:47:07,481 DEBUG [main] s.h.j.KeywordHandler [KeywordHandler.java:91] Invoking method Sleep from class com.example.step.KeywordDemo loaded by sun.misc.Launcher$AppClassLoader@b4c966a
{"success":true}
  

Packaging and Deployment

You should now be able to package your class into a single Jar file using Maven. After changing the directory to the one containing your Java class (you may also use your IDE in order to generate the Jar file), you can use the following command:

  mvn clean install
  

This will generate the Jar file. Now, you need to copy into the installation path of your Controller. For example, in data/scripts/:

You can now register the keyword into Step. To do this, go to the Keyword tab, click on “New Keyword” and properly complete the required fields:

Note, Jar files can also be dragged and dropped into the input box or uploaded programmatically via REST or our Remote Java Client.

Lastly, you can test your keyword by clicking on the run button and filling the Input value properly.

Summary: This article explains Keywords in Step and demonstrates how to create simple ones.

Illustration for Using Step with Grafana
Using Step with Grafana

This article demonstrates how to connect Grafana to data generated by Step.

Illustration for Setting up system monitoring with a Step agent
Setting up system monitoring with a Step agent

This article demonstrates how to set up distributed system monitoring using Keyword executions, and analyze the results as measurements.

Illustration for NET tutorials: Microsoft Office automation with Step
NET tutorials: Microsoft Office automation with Step

This tutorial demonstrates how to automate interaction with Microsoft Office applications using the Office Interop Assembly.

Illustration for JUnit Plan Runner
JUnit Plan Runner

This article provides documentation for how to integrate JUnit tests into Step.

Illustration for How to monitor services availability and performance
How to monitor services availability and performance

This tutorial demonstrates how Step can be used to monitor services, availability and performance metrics.

Illustration for .NET tutorials: AutoIt with Step
.NET tutorials: AutoIt with Step

This tutorial demonstrates how to utilize the AutoIt C# binding to automate interactions with Windows applications.

Illustration for Android Testing using Step and Appium
Android Testing using Step and Appium

This article demonstrates the automation of mobile applications on Android using the Appium framework.

Illustration for Browser-based automation with Step and Selenium
Browser-based automation with Step and Selenium

This article defines three Keywords which will be used in browser-based automation scenarios, using Step and Selenium, as general drivers.

Illustration for Load Testing with Cypress
Load Testing with Cypress - advanced

This tutorial shows you how to efficiently set up a browser-based load test using existing Cypress tests in the Step automation platform.

Illustration for Adding and Configuring New Agents
Adding and Configuring New Agents

In this short tutorial, we show how to quickly implement a simple browser-based load test based on Cypress scripts in Step.

Illustration for Load Testing with Playwright
Load Testing with Playwright using Step UI

This tutorial shows you how to set up a browser-based load test using existing Playwright tests in the Step UI.

Illustration for Designing functional tests
Designing functional tests

This tutorial demonstrates the design, execution, and analysis of functional tests using the web interface of Step.

Illustration for Robotic Process Automation (RPA) with Selenium
Robotic Process Automation (RPA) with Selenium

This tutorial will demonstrate how to use Step and Selenium to automate various browser tasks.

Illustration for Robotic Process Automation (RPA) with Cypress
Robotic Process Automation (RPA) with Cypress

This tutorial demonstrates how to use Step and Cypress to automate various browser tasks.

Illustration for Synthetic Monitoring with Selenium
Synthetic Monitoring with Selenium

This tutorial demonstrates how Selenium automation tests can be turned into full synthetic monitoring using Step.

Illustration for Load Testing with Cypress
Load Testing with Cypress

In this tutorial, you'll learn how to reuse existing Cypress tests to quickly set up and run a browser-based load test using the automation as code approach.

Illustration for Load Testing with Cypress
Load Testing with Serenity BDD and Cucumber

In this tutorial, you'll learn how to reuse existing tests written with Serenity BDD and Cucumber for load testing.

Illustration for Synthetic Monitoring with Cypress
Synthetic Monitoring with Cypress

This tutorial demonstrates how Cypress automation tests can be turned into full synthetic monitoring using the automation as code approach.

Illustration for Load Testing with Cypress
Load Testing with Cypress using Step UI

In this tutorial, you'll learn how to reuse existing Cypress tests to quickly set up and run a browser-based load test using the Step UI.

Illustration for Load Testing with Selenium
Load Testing with Selenium

This tutorial demonstrates how to leverage existing Selenium tests to set up and execute browser-based load tests, following a full code-based approach.

Illustration for Load Testing with Selenium
Load Testing with Selenium using Step UI

This tutorial demonstrates how to set up a browser-based load test in the Step UI using existing Selenium tests.

Illustration for Synthetic Monitoring with Playwright
Synthetic Monitoring with Playwright

This tutorial demonstrates how Playwright automation tests can be turned into full synthetic monitoring using Step.

Illustration for Synthetic Monitoring with Cypress
Synthetic Monitoring with Cypress using Step UI

This tutorial demonstrates how Cypress automation tests can be turned into full synthetic monitoring using the Step UI.

Illustration for Robotic Process Automation (RPA) with Playwright
Robotic Process Automation (RPA) with Playwright

This tutorial will demonstrate how to use Step and Playwright to automate various browser tasks.

Illustration for Load Testing with Playwright
Load Testing with Playwright for Java

In this tutorial, you'll learn how to reuse existing Playwright tests written in Java to quickly set up and run a browser-based load test using the automation as code approach.

Illustration grafana devops tutorial
Continuous load testing with K6

Quickly integrate K6 based load-tests in your DevOps workflow

Illustration for playwright synthetic monitoring in a devops workflow
DevOps Synthetic Monitoring with Playwright - Advanced

This tutorial demonstrates how Playwright tests can be reused for synthetic monitoring of a productive environment in a DevOps workflow

Illustration for playwright synthetic monitoring in a devops workflow
DevOps Synthetic Monitoring with Playwright

This tutorial demonstrates how Playwright tests can be reused for synthetic monitoring of a productive environment in a DevOps workflow

Illustration for okhttp devops
Protocol-based load testing with okhttp

In this tutorial you'll learn how to quickly set up a protocol-based load test with okhttp

Illustration for playwright devops
Continuous end-to-end testing

Learn how to set up continuous end-to-end testing across several applications based on Playwright tests in your DevOps pipeline using Step

Illustration for playwright devops
Continuous load testing with Playwright

Learn how to quickly set up continuous browser-based load testing using Playwright tests in your DevOps pipeline

Want to hear our latest updates about automation?

Don't miss out on our regular blog posts - Subscribe now!

Image of a laptop device to incentivize users to subscribe