Code Components

Re-using code is a very useful working method, saves time and energy when it comes to performing the same actions or any common action on each test, therefore when it needs an update or a fix, you only need to fix it in the script file itself.

Scripts can call the functions in the file using the require statement.

Functions file:

module.exports =
Login: function(username,password)
const web = ox.web;
web.assertText('id=firstHeading', 'Welcome '+username);

Script to run:

var common = require('./FunctionsFolder/common.js');
web.transaction('Opening browser and web-page');
web.transaction('Logging in');

In the above example , the script shall use the code it has inherited from a file called common.js, it can contain many functions as you want and call it from any script you are running.

Video Tutorial : Here's a way to create your own code component with this tutorial: