Pregunta

Here is my full first working test:

var expect = require('chai').expect;
var assert = require('assert');
var webdriverjs = require('webdriverjs');
var client = {};
var webdriverOptions = {
    desiredCapabilities: {
       browserName: 'phantomjs'
    },
    logLevel: 'verbose'
};

describe('Test mysite', function(){
    before(function() {
        client = webdriverjs.remote( webdriverOptions );
        client.init();
    });
    var selector = "#mybodybody";
    it('should see the correct title', function(done) {
       client.url('http://localhost/mysite/')
             .getTitle( function(err, title){
                expect(err).to.be.null;
                assert.strictEqual(title, 'My title page' );
             })
             .waitFor( selector, 2000, function(){ 
                client.saveScreenshot( "./ExtractScreen.png" );
             })
             .waitFor( selector, 7000, function(){ })
             .call(done);
    });
    after(function(done) {
       client.end(done);
    });
});

Ok, it does not do much, but after working many hours to get the environement correctly setup, it passed. Now, the only way I got it working is by playing with the waitFor() method and adjust the delays. It works, but I still do not understand how to surely wait for a png file to be saved on disk. As I will deal with tests orders, I will eventually get hung up from the test script before securely save the file.

Now, How can I improve this screen save sequence and avoid loosing my screenshot ?

¿Fue útil?

Solución

Since you are using chaning feature of webdriverjs it is wrong to use callback in waitFor function.

Function saveScreenshot is also chained. So the proper way would be the following:

it('should see the correct title', function(done) {
   client.url('http://localhost/mysite/')
         .getTitle( function(err, title){
            expect(err).to.be.null;
            assert.strictEqual(title, 'My title page' );
         })
         .waitFor( selector, 2000) 
         .saveScreenshot( "./ExtractScreen.png" )
         .call(done);
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top