Nightwatch.js set desiredCapabilities per test

In nightwatch.conf.js setting test_settings.default.desiredCapabilities.'LT:Options'.name results in every test executed to have the same name.

Is there a way to map LT:Options.name to the text passed to describe + test functions?

Hi there, greetings! Thank you for reaching out.

When defining the test name in the LT:Options, all tests in the build have the same name. Instead, you can use the Lambdahooks which are JavaScript executor to pass the test name during the execution. You can refer to Lambdahooks documentation at Lambda Hooks For Selenium Automation | LambdaTest | LambdaTest.

Syntax: browser.execute(lambda-name=test_name)

I hope it helps! Let us know if you have any follow-up questions! :slight_smile:

1 Like

It seems like the last call from the last test in a defined becomes the name for all test methods in the lambdatest UI

Hi again, greetings!

The lambda-name webhook has to be passed at the end of individual test sessions for unique test names on the dashboard.

Kindly refer to the below conf file for reference:

username = process.env.LT_USERNAME || "<your username>",
accessKey = process.env.LT_ACCESS_KEY || "<your accessKey>",

  exports.config = {
    'specs': ['../specs/single.js'],

    seleniumAddress: 'https://' + username + ':' + accessKey + '@mobile-hub.lambdatest.com/wd/hub',

    'capabilities': {
    //capabilities
    },
    onPrepare: () => {

      myReporter = {
        specStarted: function (result) {
          specStr = result.id
          spec_id = parseInt(specStr[specStr.length - 1])
          browser.getProcessedConfig().then(function (config) {
            var fullName = config.specs[spec_id];
            browser.executeScript("lambda-name=" + fullName.split(/(\\|\/)/g).pop())
          });
        }
      };
      jasmine.getEnv().addReporter(myReporter);
    },
    onComplete: (passed) => {
      if (passed)
        browser.executeScript("lambda-status=passed");
      else
        browser.executeScript("lambda-status=failed");
      browser.quit();
    }

  };

I hope it helps.