# Extensions Library

This extension library provides a set of ready to use examples you can add to Virtuoso with a single click.

There is no coding necessary to use any of these extensions, but if you are a developer, you can view the source of each extension and even customize them further or use them as base for making your own extensions.

# Available extensions:

# Making API calls

You can make API calls in Virtuoso by relying on the underlying XHR capabilities of the browser.

Note that in some cases you may wish to disable the Enforce same-origin policy option in your goals' advanced settings, in order to avoid cross-origin issues.

In this section, we provide examples for making API calls using Virtuoso extensions.

# Make GET call

You can make GET REST API calls, by simply calling the extension API_GET, and supplying the URL as the parameter (you can include any query parameters on the URL as well).



API_GET("https://reqres.in/api/users?page=2") returning $data
assert $data.page equals "2"

# Make POST call

You can make POST REST API calls, by simply calling the extension API_POST, supplying the URL as the parameter, and the body of the post request.



API_POST ("https://reqres.in/api/users", '{"name":"Virtuoso", "job":"Intelligent Quality Assistant"}') returning $data
Assert $data.name equals "Virtuoso"

You can even construct the request body JSON using the store command:


Store value "Virtuoso" in $request.name
Store value "Intelligent Quality Assistant" in $request.job
API_POST ("https://reqres.in/api/users", $request) returning $data
Assert $data.name equals "Virtuoso"

# Make PUT call

You can make PUT REST API calls, by simply calling the extension API_PUT, supplying the URL as the parameter, and the body of the put request.



API_PUT ("https://reqres.in/api/users/2", '{"first_name":"John"}') returning $data
Assert $data.first_name equals "John"

You can even construct the request body JSON using the store command:


Store value "John" in $request.first_name
Store value "read" in $request.access
API_PUT ("https://reqres.in/api/users/2", $request) returning $data
Assert $data.first_name equals "John"

# Make DELETE call

You can make DELETE REST API calls, by simply calling the extension API_DELETE, and supplying the URL as the parameter.



API_DELETE ("https://reqres.in/api/users/2") returning $data

Delete operation responses

Note that a success delete operation usually returns an empty response with 204 as status code, if the status code differs from 2xx, the test would fail.

# Advanced API calls

Some APIs require specific parameters to be passed on the request headers (e.g., authentication, content type, etc). To support this, all above API extensions have an additional optional headers parameter to support this.

Content type example


store value '{"content-type":"multipart/form-data"}' in $contentTypeHeader
API_POST ("https://reqres.in/api/users", '{"name":"Virtuoso", "job":"Intelligent Quality Assistant"}',$contentTypeHeader) returning $data

Header authentication example (authentication token stored in $token variable)


store value ${'Bearer ' + $token} in $authenticationHeader.Authorization
API_POST ("https://reqres.in/api/users", '{"name":"Virtuoso", "job":"Intelligent Quality Assistant"}',$authenticationHeader) returning $data

# Get computed style

This extension can be used to extract specific computed style values of an element. It can be used with XPath selectors or CSS selectors.




// XPath selector
getComputedStyle("//*[@id='gbw']/div/div[2]", "font-size") returning $fontSize
Assert $fontSize equals "13px"

// CSS selector
getComputedStyle("#gbw > div > div:nth-child(2)", "font-family") returning $fontFamily
Assert $fontFamily equals "arial, sans-serif"

# Generate Random Data

This extension enables you to generate random data on demand using the Faker.js library.

You can use various data types, as documented here.


generateRandom("{{name.firstName}} {{name.lastName}}") returning $fullName
generateRandom("{{address.city}}") returning $randomCity
generateRandom("{{lorem.sentence}}") returning $loremIpsum
generateRandom("{{random.number}}") returning $randomNumber

# Get query parameter value by name

This extension receives a query parameter name and returns its value. Let's say we are testing an action on the application that should update a query parameter, with this extension we can assert the action is updating the query parameter adding two simple steps after doing the action.

Example usage:


navigate to "https://www.google.com/?source=hp"
getQueryParameterByName("source") returning $param
assert $param equals "hp"

In the above example, on line two, this extension extracts the value of source from the current URL and stores it in a variable named $param, so we can use it later, for example, for asserting its value like in line three.

# Drag and Drop

Although Virtuoso supports drag and drop (using mouse over "from" then mouse drag to "target"), in few special cases of HTML5 drag and drop implementations, the events fired from browser automation on Virtuoso may not trigger the events the page is expecting.

In these circumstances, you can use this extension to overcome the limitation.

Example using selectors:

dragAndDrop(".from.selector", "#to.selector")

Example using stored elements:

store element details of "Element to drag from" in $from
store element details of "Element to drop to" in $to
dragAndDrop($from, $to)

# View PDF files

Extensions are very powerful and can perform complex functionality. An example of a complex extension is one which opens a PDF file in the web browser, so that you can see its content and perform assertions.

If the PDF file is not available as a public link, the first step is to download the PDF file in a test step; for example by clicking on it:


click "Download PDF"
Navigate to "https://s3-eu-west-1.amazonaws.com/virtuoso-downloaded-files/test.html"
see "Some text on the PDF"

Download file in new tab

As a limitation of our PDF download feature, PDF files opened in a new tab will cause the test step to time out. If possible, trying downloading the file in the current tab (e.g., by removing target="_blank" of a link) or explicitly mark the link as a download (e.g., by appending download='somepdf.pdf' to the anchor tag).

If the PDF file is available is a public link (e.g., doesn't require a download), first navigate to the same host as the one showing the PDF (e.g., navigate to "https://test.virtuoso.qa" if the file is on https://test.virtuoso.qa/path/file.pdf):


Navigate to "https://test.virtuoso.qa"
see "Some text on the PDF"

# Validate that images have alt attributes for accessibility

The W3C Web Content Accessibility Guidelines (WCAG) require that a text alternative should be provided for non-text content unless it is for decoration or formatting. This extension checks that images have an appropriate description for screen readers. If an image does not have an alt text attribute it will be highlighted red on the page and the step will fail. Compliant images will be highlighted with a green border.

Example usage:

Navigate to "https://test.virtuoso.qa"

# Get accessibility violations

You can fetch the set of accessibility violations on your page (if any) by using the Axe library in your journeys.

Using the extension, you add a test step to collect the violations detected into a variable, which you can then review as part of the side effects, or to add further validations based on them, e.g., to make sure they don't contain a specific violation, or that there are no violations.

Example usage:

getAxeViolations returning $violations
// check that there are no violations
assert ${ $violations.length } equals "0"

Note: if you wish to run this on all your pages and to automatically generate these steps, see Accessibility testing using directives.

Last Updated: 3/8/2021, 1:38:21 PM