Skip to main content

Job

The Job class provides a way to verify if a batch job is in a certain state. It allows for positive and negative checks.

Extends

This class extends the abstract Question<boolean> class from Core.

Methods

answeredBy

public async answeredBy(actor: Actor): Promise<boolean>;
  • Description: Perform the verification based on the specified action.
  • Parameters:
    • actor - The actor performing the action.
  • Returns: Promise<boolean> - The verification result (true or false).

toHave

Introduced in: 1.0.0

static get toHave(): Job;
  • Description: Create a new instance of the Job class for positive verification.
  • Returns: Job - A new instance of the Job class.

notToHave

Introduced in: 1.0.0

static get notToHave(): Job;
  • Description: Create a new instance of the Job class for negative verification.
  • Returns: Job - A new instance of the Job class.

toBe

Introduced in: 1.0.0

static get toBe(): Job;
  • Description: Create a new instance of the Job class for positive verification.
  • Returns: Job - A new instance of the Job class.

notToBe

Introduced in: 1.0.0

static get notToBe(): Job;
  • Description: Create a new instance of the Job class for negative verification.
  • Returns: Job - A new instance of the Job class.

status

Introduced in: 1.0.0

public status(jobId: string, statusToLookup: JobStatus): Job;
  • Description: Set up the verification for the job status.
  • Parameters:
    • jobId - The job id
    • statusToLookup - The status to be checked against
    • options - The job status check options (optional)
  • Returns: Job - The updated instance of the Job class.

Usage:

// To verify that the job has a given status
await actor.asks(
Job.toHave.status('myJobId', 'SUCCEEDED', { timeout: 30000, delayBetweenRetries: 500 }),
);
// To verify that the job does not have a given status
await actor.asks(
Job.toNotHave.status('myJobId', 'SUCCEEDED', { timeout: 30000, delayBetweenRetries: 500 }),
);

finished

Introduced in: 1.0.0

public finished(jobId: string, options): Job;
  • Description: Set up the verification for the job to be finished.
  • Parameters:
    • jobId - The job id
    • options - The job status check options (optional)
  • Returns: Job - The updated instance of the Job class.

Usage:

// To verify that the job is finished
await actor.asks(
Job.toBe.finished('myJobId', { timeout: 30000, delayBetweenRetries: 500 }),
);
// To verify that the job is not fnished
await actor.asks(
Job.toNotBe.finished('myJobId', { timeout: 30000, delayBetweenRetries: 500 }),
);

Methods inherited from Core Question

failAsFalse

Introduced in core: 0.5.0

In some cases you may want to ask questions to find out about the status of the system under test to make decisions on how to move on with your test. In order to not fail a test but receive information about questions being answered negative you can use failAsFalse on a question which then returns a boolean value instead.

public get failAsFalse(): Question;
  • Description: Returns false instead of failing when exception occurrs.
  • Returns: Question - Returns the current question.

Usage:

// get evaluation result based on valid check
const evaluationResult = await actor.asks(
MyQuestion.is.asExpected().failAsFalse,
);

// proceed based on answer from above
if (wasLoggedIn === false) {
// some code to be executed on false case
}

withAbilityAlias

Introduced in core: 0.3.0

It happens that there is the need to make use of the same ability but with different settings. The solution Testla Screenplay offers is Ability Aliasing. With that multiple instances of an ability can be assigned to a user at the same time. To use an aliased ability in a question you can use the withAbilityAlias method to define the alias to be used during execution.

public withAbilityAlias(alias: string): Question;
  • Description: Defines the ability alias to be used during execution.
  • Parameters:
    • alias - The alias.
  • Returns: Question - Returns the current question.

Usage:

await actor.asks(
MyQuestion.is.asExpected().withAbilityAlias('myAlias'),
);