RiotJS and headless webkit

697 views Asked by At

Currently using RiotJS and Mocha for unit testing. Was wanting to know if I can use a headless browser webkit like PhantomJS & CasperJS to do additional tests on my RiotJS tags/pages. Up to now all my attempts to load the tags/pages and perform queries on the document have failed. Would appreciate any samples/links.

Thanks

Updated: querySelector fails for '#testId', but succeeds for 'testId2'.

Extract from my unit test:

  page.open('http://localhost/src/default.html', function (status) {
   var test = document.querySelector("#testId"); // returns undefined
  }

<!-- html page -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Riot.js Example</title>
</head>
<body>

<!-- mount points -->

<spinner data-url="./data.json" data-sourceId="instance1" data-model="myModel" id="testId"></spinner>
<imageoutput data-sourceId="instance1" data-model="myModel"></imageoutput>

<div id="testId2">this content</div>

<!-- mount the same way -->
<!--[if lt IE 9]>
<script src="../dist/scripts/es5-shim.js"></script>
 <script src="ie-stuff.js"></script>
<![endif]-->

<script src="../dist/scripts/require.js" data-main="./main"></script>

</body>
</html>
2

There are 2 answers

1
Diego Borges On

Patrick,

It would be nice you better specify which test objectives you want to do, what to do on each page to see if the CasperJS / PhantomJS realize do it!

The CasperJS, working with the PhantomJS can work independently and I confess that today, any automation project pages or testing, I use them only and give the trick!

For a layout test (images, fonts, CSS), you can study the PhantomCSS, but if your goal is to navigate, click, test elements and even download archive (assuming avoid URLs with Silverlight, Java ... the CasperJS will give account to do anything you want ... and the returns you can get at log.xml to treat it in any other tool or system.

I'm finishing my new site and it, post several tutorials and tips regarding the CasperJS and PhantomJS ... and in the future, perhaps a course ... If you want you can find me on facebook, twitter, github ... post there when everything is online.

0
Simon On

I have had some success with using Protractor and Karma with riotjs. Granted we used RiotTS for the project, but the principles remain the same.

Although Karma and Protractor are typically used for commonly used testing angular applications they are agnostic. There is tons of information out there, and is widely supported.

From the source I can see you are probably doing something asynchronous, (data-url="./data.json") which will mean you need to raise a flag in your app that the data is loaded or page is ready.

You can always introspect riot by doing document.querySelector('imageoutput')._tag to the investigate the state of your riot tags.