2017-09-01 64 views
1

我怎麼能運行在瀏覽器中測試?硒建設者運行摩卡測試在瀏覽器

我用硒建設者要記住的步驟,然後我導出file.js和摩卡(NPM測試)運行它。測試成功,但我無法調用瀏覽器。

如果我導出file.java並在eclipse中運行它,一切正常,但在摩卡我不能調用任何瀏覽器。

我已經把驅動程序(例如geckodriver for FF)放在給定文件夾中,通過npm安裝selenium服務器等等,對於瀏覽器,命令等,file.js有不同的設置,但瀏覽器不會出現當我在摩卡運行測試。 (我正在使用Windows)。

我可以運行它是由硒製造商(以.json)編寫了測試。先前在命令行中啓動了硒服務器;我可以通過SeInterpreter(不含硒建造者)運行測試(.json)。但是,我怎樣才能調用瀏覽器並觀看我以前寫過的步驟?

下面是代碼示例:

var assert = require('assert'); 
var wd = require('wd'); 
    chai = require('chai'), 
    expect = chai.expect, 
    _ = require('underscore'), 
    fs = require('fs'), 
    path = require('path'), 
    uuid = require('uuid-js'); 
var VARS = {}; 

// This assumes that selenium is running at http://127.0.0.1:4444/wd/hub/ 
var noop = function() {}, 
    b = wd.promiseChainRemote(); 

describe('Selenium Test Case', function() { 

    this.timeout(60000); 

    it('should execute test case without errors', function(done) { 

    b.chain(function(err) { 
     done(err); 
    }) 
    .init({ 
     browserName: 'firefox' 
    }) 
    .get("https://google.com") 
    .elementById("lst-ib", function(err, el) { 
     b.next('clear', el, function(err) { 
     b.next('type', el, "приветик", noop); 
     }); 
    }) 
    .elementById("lst-ib", function(err, el) { 
     b.next('clear', el, function(err) { 
     b.next('type', el, "приветик", noop); 
     }); 
    }) 
    .elementByLinkText("Картинки", function(err, el) { 
     b.next('clickElement', el, noop); 
    }) 
    .close(function(err) { 
     done(err); 
    }); 

    }); 
}); 

在此先感謝!

回答

0

你可以通過file-> export(在selenium builder addon--錄製腳本後)將你的測試用例導出爲'Node.JS - Selenium-WebDriver',並確保將其保存爲'somefile.js'(javascript )。你可以在命令提示符下執行它作爲'node filename.js',並在action中看到它。希望它有幫助!

+0

非常感謝你的建議!一切正常,當我使用它!但是,當我嘗試導出爲'Node.JS - Mocha'時,在這種情況下,由於某種原因它將不起作用!我不能在命令提示符下將它作爲'npm filename.js'來執行,並且出於某種原因在行動中看到它! –

相關問題