2

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 ?

4

1 回答 1

0

由于您使用的是 webdriverjs 的 chaning 功能,因此在waitFor函数中使用回调是错误的。

函数saveScreenshot也是链式的。所以正确的方法如下:

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);
});
于 2015-03-16T12:30:13.583 回答