• Documentation
  • Tutorials
  • Case studies
  • Blogs
  • Product

What's on this Page

  • Agent Setup
    • Installation
    • Validation
    • Troubleshooting
  • Controller
    • Validation
    • Troubleshooting
  • Example
    • Keyword Unit Testing
    • Keyword Execution
    • Special purpose functions
  • step
  • Plugins
  • Node.js agent
Categories: PLUGINS AGENTS
This article references one of our previous releases, click here to go to our latest version instead.

Node.js agent

Agent Setup

Installation

Follow this link to install the NodeJS Step Agent : NodeJS Agent installation

Validation

You can now test the installation by first running the following command in a shell:

1521733320460-476.png

You can also check on the controller that a new agent of type “node” appears:

1522092112241-170.png

Troubleshooting

  • If you forget to pass the configuration file, the following error will be displayed:
1521732049542-793.png
  • If you have the following error:
1521731521204-221.png

This can mean that:

  • The agent was installed with a different user
  • The Path environment variable of the user is not correct
  • You didn’t restart the shell since the installation

Restart your shell and start again. If this is still not working, check the Path environment. It should contain the folder** C:\Users<UserName>\AppData\Roaming\npm** and this folder should contain the step-node-agent command

Controller

Validation

Your node.js installation should be up and running now. You can test it by copying the following example into your …/keywords/keywords.js file:

exports.Test_Keyword = async (input, output, session) => {
  output.send({ result:input.parameter})
}

This small example will return as an output the value of an input parameter named “parameter”. You can quickly run this example as follow:

Create the keyword, the name should match the name of the function:

1522070375048-917.png

The node project parameter is a folder containing your keywords and the npm dependencies needed to run them. This folder has to comply with the following:

  1. The folder should be on the controller machine (the agent will download them automatically)
  2. It must contain a file …/keywords/keywords.js defining your keywords

Then click on the “run keyword” button:

1522070499993-441.png

Add the parameter and click on “execute this plan”:

1522070570579-557.png

The result should be the following:

1522070649049-846.png

Troubleshooting

  • If you see the following error message:
1533823034391-976.png

Go in the grid view and check that you node agent is properly connected to the controller.

1533823392258-619.png

If you cannot see your agent:

  • Check you** AgentConf.json** for a misconfigured agentPort or agentUrl
  • Check that the network connection between the agent and the controller is open

Example

The node agent comes with a more complex example, showing how to create and test Selenium based keywords. You can get the source code on our git repository:

$ git clone https://github.com/exense/step-node.git
$ cd step-node\examples\my-keyword-library 

 You will then need to:

  • Include the ChromeDriver location in your PATH environment variable
  • Or drop the chrome driver in the **my-keyword-library **folder

You can finally install the dependencies and run a local test:

$ npm install
$ npm run test

Keyword Unit Testing

The file index.js at the root of the folder gives you an example of how to unit test your keywords:

const runner = require('step-node-agent').runner()
const assert = require('assert')

;(async () => {
  var output = await runner.run('Open_Chrome', {})
  assert.equal(output.payload.result, 'OK')
  output = await runner.run('Google_Search', { search: 'djigger' })
  assert.equal(output.payload.result, 'OK')
  await runner.run('Google_Search', { search: 'exense step' })
  assert.equal(output.payload.result, 'OK')
})()

The keywords.js file contains the logic needed for managing a session and keeping track of the driver between keywords execution:

exports.Open_Chrome = async (input, output, session) => {
  const webdriver = require('selenium-webdriver')

  const driver = await new webdriver.Builder()
    .forBrowser('chrome')
    .build()

session.driver_wrapper = { 'driver': driver, 'close': function() {
      console.log('[Driver wrapper] Closing selenium driver')
      this.driver.quit()
  } }

    output.send({ result: 'OK' })
}

exports.Google_Search = async (input, output, session, properties) => {
  var googleUrl = properties['google.url'];

  const webdriver = require('selenium-webdriver')
  const { By } = webdriver
  const driver = session.driver_wrapper.driver

  session.driver_wrapper.driver = driver
  await driver.get(googleUrl)
  await driver.findElement(By.name('q')).sendKeys(input.search + webdriver.Key.ENTER)

  const data = await driver.takeScreenshot()

    -   output.attach({ name: 'screenshot.png', hexContent: data })
          output.send({ result: 'OK' })
        }

  exports.Close_Chrome = async (input, output, session) => {
  const driver = session.driver_wrapper.driver
  driver.quit()

  output.send({ result: 'OK' })
}

exports.onError = async (exception, input, output, session, properties) => {

    if (session.driver_wrapper) {
        const data = await session.driver_wrapper.driver.takeScreenshot()
        output.attach({ name: 'screenshot_onError.png', hexContent: data })
    }

    return true
}

Keyword Execution

You can now create the new keywords on the controller side and execute Selenium tests from the controller:

1522091301631-426.png

Special purpose functions

You can notice in the example two helper callback function:

  • exports.onError: This is a specific function allowing to manage the exception handling of your keywords. This function will be called each time on of your keyword execution throws an exception. The return value of this function will determine the status of the execution:
    • if true, the keyword execution will be reported as TECHNICAL_ERROR
    • if false, the exception is ignored and the keyword will be reported as PASSED
  • session.driver_wrapper.close:This is a callback function that will be called when your test execution end. This allows to free all the resources used by our Selenium driver even if the test is aborted. The logic of that mechanism is that all the objects in the **session **are scanned for a **close **function each time a test is finished.

See Also

  • .NET agent
  • Astra Plugin
  • Cypress Plugin
  • JMeter
  • PDF and Image compare
  • Home
  • Whats new?
  • Admin guide
  • User guide
  • Developer guide
  • Plugins
    • .NET agent
    • Astra Plugin
    • Cypress Plugin
    • Node.js agent
    • SikuliX Plugin
    • ALM
    • Azure DevOps
    • Jira Xray
    • Async packages
    • JMeter
    • SoapUI
    • PDF and Image compare
    • Artifact repository connector
    • Analytics and external DBs
  • Libraries
Step Logo
    • Documentation
    • Tutorials
    • Case studies
    • Blogs
    • Product
    • Home
    • Whats new?
    • Admin guide
    • User guide
    • Developer guide
    • Plugins
      • .NET agent
      • Astra Plugin
      • Cypress Plugin
      • Node.js agent
      • SikuliX Plugin
      • ALM
      • Azure DevOps
      • Jira Xray
      • Async packages
      • JMeter
      • SoapUI
      • PDF and Image compare
      • Artifact repository connector
      • Analytics and external DBs
    • Libraries