screenshot function for functional test with internjs Framework doens't work

158 Views Asked by At

I'm using the intern framework for functional testing and running browser locally (Firefox version 39). Is there a way to capture screenshot png-file? I tried the following example How to take a screenshot with local browser (FF) and write to file in intern javascript but I get this error

" node_modules/intern/node_modules/dojo/dojo.js:757 throw new Error('Failed to load module ' + module.mid + ' from ' + url + ".

I'm a beginner to this intern js framework and leadfood.

Thank you very much for looking in.

Here is what I have:

 define([
            'intern!object',
            'intern/chai!assert',
            'require',
            'tests/support/personas'
        ], function (registerSuite, assert, require, personas) {

            registerSuite({
                name: 'index',
                'greeting form': function () {
                    var persona = personas[0]
                    return this.remote
                        .get(require.toUrl('https://www.google.de/'))
                        .setFindTimeout(5000)
                        //.setFindTimeout(5000)
                      .findByCssSelector('input[id="billingAddress.zip"]')
                              .click()
                              .type('50800')
                              .end()

                    .getCurrentUrl()
                    .takeScreenshot
                    .then(function (data) {
                    fs.writeFileSync('/tmp/myCapture', data,'base64');
                    )}
1

There are 1 best solutions below

0
On

OK you're seeing an error here because of the way in which you're telling intern to navigate to the URL.

You are using .get(require.toUrl('https://www.google.de/')) which is incorrect. You only use .get(require.toUrl('...')) with intern version 3 and only if you are asking intern to open a static web page from a file on your local machine.

So if / when you're using the .get(require.toUrl('...')) method, you should be sending it a location to a HTML file from your local machine rather than a URL.

What you should use instead is:

.get('https://www.google.de/')

This will resolve that error for you!

Just for the record - the use of .get(require.toUrl()) is no longer used in intern version 4. With version 4, you use .get() regardless of whether you're using a URL or a file.