Creating Custom Tasks
In the thekla4j framework, tasks are the fundamental units of work that an Actor can perform. There are different types of tasks, each serving a specific purpose. Below is a description of the different task types and a guide on how to create custom tasks.
Task Types
Task
A Task represents a unit of work that an Actor can perform. It can have input parameters and return a result. Example: Authorize to a backend and returning the token.
import com.teststeps.thekla4j.commons.error.ActivityError;
import com.teststeps.thekla4j.core.base.activities.Task;
import com.teststeps.thekla4j.core.base.persona.Actor;
import io.vavr.control.Either;
public class Authorize implements Task<User, String> {
private final String url;
private Authorize(String url) {
this.url = url;
}
@Override
public Either<ActivityError, String> performAs(Actor actor, User user) {
// Perform the authorization task by sending one or multiple requests to the backend
// Return Either.right() for success, Either.left() for errors
return Either.right("token");
}
public static Authorize toBackend(String url) {
return new Authorize(url);
}
}
BasicInteraction
A BasicInteraction is a simple task that performs an action without returning a result. Example: Clicking a button, entering text into a field.
ConsumerTask
A ConsumerTask is a task that consumes an input and performs an action without returning a result. Example: Logging a message, updating a database record.
SupplierTask
A SupplierTask is a task that supplies a result without requiring any input. Example: Generating a random number, fetching the current date and time.