# 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:**

```javascript
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);
    }
}
```

{% hint style="info" %}
**it's also possible to use the ES6 arrow function and template literals**
{% endhint %}

```javascript
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:**

```javascript
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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.oxygenhq.org/advanced/code-components.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
