Ahhhh這讓我瘋狂。Selenium npm自動測試跑步者
我有我的Windows機器設置與selenium-webdriver
從npm。
我有我的第一次測試運行很好,但然後明顯的下一步是將所有的測試分割成不同的文件和文件夾,以允許增長,然後突然你需要一個測試賽跑者......但似乎有是100名測試選手,摩卡,柴,硒測試賽跑者,硒摩卡......名單不斷涌現。
我希望有人可能會指出我正確的方向。
什麼是最常用的堆棧使用?我只是希望能夠建立一個測試文件夾並在我的本地機器上運行遠程網站。例如,通過npm開始在本地機器上運行單個文件,然後依次逐個測試文件夾中的每個測試。一。
任何提示將非常感激。
我也嘗試將東西一起我自己,每個測試文件是一個module.export
這又裝了一個var webdriver = require('selenium-webdriver');
& var driver = new webdriver.Builder().forBrowser('firefox').build();
但是,即使在每次測試結束時driver.quit()
我留下了多個Firefox窗口打開,直到最後的測試完成後,當測試達到中等劑量的數量時,我猜測這將會殺死我的機器。
//get the test testConstants cached into a var to later pass to the test files.
GLOBAL.testConstants = require('./config/testConstants');
//walk files function
function filesWalk(currentDirPath, callback) {
var fs = require('fs'), path = require('path');
fs.readdirSync(currentDirPath).forEach(function(name) {
var filePath = path.join(currentDirPath, name);
var stat = fs.statSync(filePath);
if (stat.isFile()) {
callback(filePath, stat);
} else if (stat.isDirectory()) {
walk(filePath, callback);
}
});
}
//build up list of test files
var testFunctions = [];
filesWalk('tests/', function(filePath, stat) {
// do something with "filePath"...
if(filePath.slice(-3) == '.js'){
//pass function to testFiles array which would include the test then run the file
console.log('pushing test to array: ' + filePath);
//this array of functions will get passed onto waterfall
testFunctions.push(function(callback){
console.log('Running test: '+ filePath);
require('./' + filePath.substring(0, filePath.length - 3))(callback);
});
}
});
//now pass the array of test function to waterfall async
var waterfall = require('async-waterfall');
waterfall(testFunctions , function(err,result){
console.log(err);
console.log(result);
});
用一個例子測試看起來像:
module.exports = function(nextTest){
//Load up the rel modules and call the By and until into easily accessible variables
var webdriver = require('selenium-webdriver');
//start the driver
var driver = new webdriver.Builder().forBrowser('firefox').build();
//Load up the rel modules and call the By and until into easily accessible variables
var By = webdriver.By,
until = require('selenium-webdriver').until,
testConstants = GLOBAL.testConstants;
driver.get(testConstants.url);
driver.findElement(By.css('.map-submit-button')).click();
driver.wait(function() {
return driver.isElementPresent(By.css("a#map-tab"));
}, testConstants.timeout).then(function(){
driver.findElement(By.css(".search-tab-container .selected")).click().then(function(){
driver.quit();
if(typeof nextTest == 'function'){
nextTest(webdriver, driver);
}
});
});
};