SetBatchId method

Class: BatchClosePlatform: Selenium 3Language: C# SDK:

Set the batch id of the batches that should be closed.

Introduction

The Test Manager displays test results in batches. The article Grouping tests into batches with the SDK explains how tests are associated with batches based on a batch ID, and how you can use the SDK to control which tests will be part of a particular batch.

Here, we will focus on understanding the notions of an active batch and closing a batch.

A batch is created and becomes active when a test is started with a batch ID that does not match an existing active batch. As long as a batch is active, new tests that have a matching batch ID will be added to the batch.

Batches are closed automatically in one of two ways. Runner based SDKs implement Auto batch closure by default, which closes the batches associated with the runner's test after the tests have completed. In addition, in order to prevent large batches that could cause performance issues, the Eyes server closes active batches that have not been used for several hours, or if they have been in continuous use for more than a few days.

When a batch is closed, the Eyes server sends a batch completion notification, if this feature is enabled. See Batch completion notifications for details.

You can manage batch closure by:

  • Disabling the runner Auto batch close. This is useful if you want to combine tests from multiple runners, or that run in separate executions into a common batch.

  • Manually closing the batch. This is recommended if you have disabled auto batch closure, in order to get a batch completion notification when the tests have completed and not when the batch is closed automatically by the server.

When closing a batch manually, this call is typically followed by a call to the method BatchClose.Close.

Syntax


EnabledBatchClose value = obj.SetBatchId(batchIds);

EnabledBatchClose value = obj.SetBatchId(batchIds);

Parameters

batchIds
Type:params string[]
One or more batches to be closed.
batchIds
Type:IEnumerable<string>
One or more batches to be closed.

Return value

Type: EnabledBatchClose
The returned object is an instance of a class inherited from BatchClose. This is to ensure that you only call BatchClose.Close if you've set the batch ID by calling SetBatchId

Example

The example below illustates:

  • How to prevent the runner from closing the batch, using the method VisualGridRunner.DontCloseBatches. This method is also available when using the ClassicRunner.
  • How to manually close the batch when all tests on all runners have completed, using the method BatchClose.Close.

Note that the batch id of the batch being closed needs to be passed to BatchClose.SetBatchId. In this example, we assume that a batch id was set for all the batches by assigning a unique ID to the environment variable APPLITOOLS_BATCH_ID. This is used as a default by the method Configuration.SetBatch which is setup in the suite Configuration object which is then assigned to each Eyes instance.

/*
 * After creating the runner, configure it so that won't close the batch
 */
runner = new VisualGridRunner(new RunnerOptions().TestConcurrency(10));
runner.DontCloseBatches = true;
/*
 * Setup a common batch for all tests
 */
BatchInfo batchInfo = new BatchInfo(batchName);
batchInfo.Id = MyGetUniqueBatchID(); // User defined
suiteConfig = (Configuration) new Configuration() 
    .SetBatch(batchInfo)
    /* ... other configurations */; 
/* 
 * Assign the configuration to all newly created Eyes instances
 */
eyes = new Eyes(runner);
eyes.SetConfiguration(suiteConfig);
/*
 * After all the tests have completed, in all the runners
 */
List<String> batchIds = new List<string>() { Environment.GetEnvironmentVariable("APPLITOOLS_BATCH_ID") };
BatchClose batchClose = new BatchClose();
batchClose.SetBatchId(batchIds).Close();