我在nodeJS上使用selenium并且我想打开X chrome实例/标签,并且每个标签都要通过webdriver函数运行脚本 - executeAsyncScript(因为这是我知道函数已经完成的)有没有办法为每个选项卡运行这些脚本togeter,因为即使我通过循环调用executeAsyncScript几次,它仍将一个接一个地运行,而不是所有的tabs / chrome实例一起运行。
startProccess(null , {enviornemt : "staging"});
function startProccess(err,result){
console.log("started proccess");
baseUrl = ENV_MAP[result.enviornemt] || ENV_MAP["local"];
driver.get(baseUrl);
openTabsForTests();
}
function openTabsForTests(){
console.log("start to opened tabs");
driver.executeAsyncScript(openNewTabCommand,TABS_COUNT - 1).then(function(data){
setTimeout(function(){
setTestsForRun();
},1000);
});
}
function setTestsForRun(){
console.log("start to set tests");
tabs = driver.getAllWindowHandles().then(function(tabs){
console.log(tabs);
cleanTabs = tabs;
setTimeout(function(){
startTestsRun();
},1000);
});
}
function startTestsRun(){
console.log(cleanTabs);
for(var i = 0 ; i< cleanTabs.length ; i++){
var tab = cleanTabs[i];
var index = i;
driver.switchTo().window(tab);
driver.executeAsyncScript(functionToRun,index,baseUrl).then(function(data){
console.log(data);
});
}
}
var functionToRun = async function(){
var testCounter = 0;
var callback = arguments[arguments.length - 1];
var currentIndex = arguments[0];
var baseUrl = arguments[1];
setTimeout(function(){
callback(currentIndex);
},6000)
}