OXYGEN
HomeGitHubReleasesCommunity
  • Welcome to Oxygen
  • About
    • What is Oxygen?
    • Getting Started (Videos)
      • Oxygen IDE Controls Overview
      • Recording a Web Test
      • Oxygen Commands Explained
    • Getting help
  • Download and work with Oxygen
    • Download & Installation
      • Oxygen IDE Installation
      • Oxygen for Mobile Installation
      • Oxygen for Windows Desktop Automation Setup
      • Oxygen for Mac Installation
        • Mac Installation Troubleshooting
      • Oxygen CLI Installation
      • Java Installation Instructions
      • Recording Troubleshooting
    • Start working with Oxygen
      • Getting Started - Web
        • Introduction - Web Testing
        • Recording a Web Test
        • Creating a Web Test
        • Sample Project - Web Test
      • Getting Started - Mobile
        • Introduction - Mobile Testing
        • Recording a Test on Mobile
        • Creating a Test - Mobile
        • Sample Project - Mobile
      • Getting Started - Oxygen for Windows Desktop Automation
      • Getting Started- Oxyge CLI
        • Running a Test Script on Windows
        • Running Multiple Tests (Suites) on Windows
    • Oxygen Modules
      • assert
      • date
      • db
      • email
      • eyes
      • http
      • log
      • mailinator
      • mob
      • pdf
      • proxy
      • serial
      • shell
      • soap
      • twilio
      • utils
      • web
      • win
    • Test Parameters
  • Cloud Providers
    • Sauce Labs
    • Lambda Test
    • TestObject
  • Advanced programming in Oxygen
    • Project Configuration
    • Locating Elements
    • Page Objects
    • Environments
    • Code Components
Powered by GitBook
On this page

Was this helpful?

  1. Advanced programming in Oxygen

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 po object statement.

Functions file:

module.exports = {
    Login: function(username, password) {
        web.type('id=userName',username);
        web.type('id=password',password);
        web.click('name=login');
        web.assertText('id=firstHeading', 'Welcome ' + username);
    }
}

it's also possible to use the ES6 arrow function and template literals

module.exports = {
    Login: (username, password) => {
        web.type('id=userName', username);
        web.type('id=password', password);
        web.click('name=login');
        web.assertText('id=firstHeading', `Welcome ${username}`);
    }
}

Script to run:

web.transaction('Opening browser and web-page');
web.init();
web.open('https://oxygenhq.org');
web.transaction('Logging in');

po.Login('User1', 'Password123');

web.click('id=button1');

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

PreviousEnvironments

Last updated 4 years ago

Was this helpful?