---
title: "Testing using CasperJS and PhantomJS in JavaScript"
canonical: "https://docs.getxray.app/space/XRAYCLOUD/44564773/Testing%20using%20CasperJS%20and%20PhantomJS%20in%20JavaScript"
format: markdown
---
# Overview

In this tutorial, we will create some tests in JavaScript using casperjs.

# Requirements

- phantomjs
- casperjs


> ❌ **Please note**
> ❌ 
> ❌ As of 2019, CasperJS seems to no longer be maintained.

# Description


##### **google_testing.js**

```javascript
casper.test.begin('Google search retrieves 10 or more results', 5, function suite(test) {
    casper.start("http://www.google.fr/", function() {
        test.assertTitle("Google", "google homepage title is the one expected");
        test.assertExists('form[action="/search"]', "main form is found");
        this.fill('form[action="/search"]', {
            q: "casperjs"
        }, true);
    });
    casper.then(function() {
        test.assertTitle("casperjs - Recherche Google", "google title is ok");
        test.assertUrlMatch(/q=casperjs/, "search term has been submitted");
        test.assertEval(function() {
            return __utils__.findAll("h3.r").length >= 10;
        }, "google search for \"casperjs\" retrieves 10 or more results");
    });
    casper.run(function() {
        test.done();
    });
});


```


After running the tests and generating the JUnit XML report (e.g., ), it can be imported to Xray (by using either the REST API or the **Import Execution Results** action within the Test Execution).

```
casperjs test google_testing.js --xunit=log.xml
```


JUnit's Test Case is mapped to a Generic Test in Jira, and the **Generic Test Definition** field contains the name of the test concatenated with the alias of each test case "assert" statement.


![image](media://d27ae71a-e67c-410b-a857-e8c6a100d972)

The Execution Details of the Generic Test contains information about the Test Suite, which in this case corresponds to the name of the test case.

![image](media://768d9ed9-29ca-4c02-a477-463e7dc7361d)

# References

- ~~http://docs.casperjs.org/en/latest/testing.html~~