[英]Running Mocha tests from selenium builder in a browser
如何在瀏覽器中運行測試?
我使用selenium builder記住步驟,然后導出file.js
並在mocha中運行它(npm測試)。 測試成功,但是我無法調用瀏覽器。
如果我導出file.java
並在eclipse中運行,一切正常,但是在mocha中,我無法調用任何瀏覽器。
我已經將驅動程序(例如FF的geckodriver)放在給定的文件夾中,通過npm安裝了硒服務器,依此類推,在file.js
用於瀏覽器,命令等的不同設置。但是當我打開瀏覽器時,不會出現在摩卡咖啡中運行測試。 (我正在使用Windows)。
我可以運行由selenium builder(.json)編寫的測試。 先前已經在命令行中啟動了硒服務器; 我可以通過SeInterpreter(沒有selenium builder)運行測試(.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);
});
});
});
提前致謝!!!
您可以通過file-> export(在selenium builder插件中-記錄腳本后)將測試用例導出為'Node.JS-Selenium-WebDriver',並確保將其保存為'somefile.js'(javascript)。在命令提示符下將其執行為“ node filename.js”,並在運行中查看它。希望對您有所幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.