Basic Keyword Development
This article explains Keywords in Step and demonstrates how to create simple ones.
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.
This article demonstrates how to connect Grafana to data generated by Step.
This article demonstrates how to set up distributed system monitoring using Keyword executions, and analyze the results as measurements.
This tutorial demonstrates how to automate interaction with Microsoft Office applications using the Office Interop Assembly.
This article provides documentation for how to integrate JUnit tests into Step.
This tutorial demonstrates how Step can be used to monitor services, availability and performance metrics.
This tutorial demonstrates how to utilize the AutoIt C# binding to automate interactions with Windows applications.
This article demonstrates the automation of mobile applications on Android using the Appium framework.
This article defines three Keywords which will be used in browser-based automation scenarios, using Step and Selenium, as general drivers.
This tutorial shows you how to efficiently set up a browser-based load test using existing Cypress tests in the Step automation platform.
In this short tutorial, we show how to quickly implement a simple browser-based load test based on Cypress scripts in Step.
This tutorial shows you how to efficiently set up a browser-based load test using existing Playwright tests in the Step automation platform.
This tutorial demonstrates the design, execution, and analysis of functional tests using the web interface of Step.
This tutorial will demonstrate how to use Step and Selenium to automate various browser tasks.
This tutorial demonstrates how to use Step and Cypress to automate various browser tasks.
This tutorial demonstrates how Selenium automation tests can be turned into full synthetic monitoring using Step.
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.
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.
This tutorial shows you how to efficiently set up a browser-based load test using existing Selenium tests in the Step automation platform.
This tutorial demonstrates how Playwright automation tests can be turned into full synthetic monitoring using Step.
This tutorial demonstrates how Cypress automation tests can be turned into full synthetic monitoring using Step.
This tutorial will demonstrate how to use Step and Playwright to automate various browser tasks.
In this tutorial, we'll show you how to easily set up and run a browser-based load test with Step's wizard, using your existing Playwright tests, on the Step automation platform.
Quickly integrate K6 based load-tests in your DevOps workflow
This tutorial demonstrates how Playwright tests can be reused for synthetic monitoring of a productive environment in a DevOps workflow
This tutorial demonstrates how Playwright tests can be reused for synthetic monitoring of a productive environment in a DevOps workflow
In this tutorial you'll learn how to quickly set up a protocol-based load test with okhttp
Learn how to set up continuous end-to-end testing across several applications based on Playwright tests in your DevOps pipeline using Step
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!