webdriver.io で自動化されたスクリプトを作成して、Web ページの入力/選択を入力し、スクリーンショットを撮ります。自動化スクリプトの実行中に、ユーザー アクション (select の値の変更など) によってページが読み込まれた場合はどうなりますか? スクリプトで中断したところから再開する方法はありますか (いくつかの入力がその時点で既に入力されていて、セッション データを介して値を保持しているが、残りの入力を続けたいとします)。
そのページがリロードされると、スクリプトの実行が停止することがわかります。
中断したところから再開する方法がない場合、ページの読み込みを検出してスクリプトを再実行することで、スクリプトを最初からトリガーするにはどうすればよいでしょうか?
コメントへの対応: コードを貼り付ける必要はないと思います (ただし貼り付けます)。問題は、スクリプトの実行中にページの読み込みが発生したときに webdriver.io を介してページの読み込みを検出する方法であり、そうではないからです。スクリプト自体によって開始されます。
更新!!: 私は waitForExist() を使用してこれを解決し、対話する前に各入力/選択が存在するのを待つだけでした。理想的ではありませんが、機能します。誰かがより良い解決策を持っている場合は、私に知らせてください!
コードは次のとおりです。
webdriverio = require('webdriverio');
var tester = {};
tester.iter = 0;
var options = {
desiredCapabilities: {
browserName: 'chrome'
}
};
var params = {
[[I've removed these because it's private info]]
};
var fields = {
deliveryCompany: 'ABC Inc',
deliveryFirstname: 'John',
deliveryLastname: 'Smith',
deliveryStreet1: '123 Main St.',
deliveryCity: 'Boston',
};
var execQueue = [];
var wrapFunction = function(fn, context, params) {
return function() {
fn.apply(context, params);
};
};
var takeScreenshot = function(){
console.log('take screenshot', this);
this.saveScreenshot('./checkout.png')
.click('input.CBSubmit').then(function(value) {
this.waitForExist('#mjPaymentReview').then(function(){
this.saveScreenshot('./review.png').then(function(){
this.click('input.CBSubmit').then(function(){
this.waitForExist('#mjCartFinal').then(function(){
this.saveScreenshot('./confirmation.png').then(function(){
this.end();
});
});//end wait for exists
});//end click.then
});// Save the screenshot to disk
});//end pause.then
});//end click.then
};//end takeScreenshot
function fillFields(driver, fields){
driver.elements('select + .chosen-container').then(function(result){
console.log('how many selects', result.value.length);
tester.totalSelects = result.value.length;
});
//loop through all selects and inputs
for(property in fields){
var p = property;
//closure to preserve value of property
(function(p){
//if chosen input then choose from list
driver.isExisting('div.' + p + ' .chosen-results').then(function(result){
if(result === true){
driver.elements('div.' + p + ' select').then(function(result){
//loop through each select (expiration date has two selections in one container)
for(var i=0;i<result.value.length;i++){
var s = result.value[i].ELEMENT;
//closure
(function(s){
//find the name of each select
driver.elementIdAttribute(s,'name').then(function(result){
//find the chosen container after select
var container = 'select[name=' + result.value + '] + .chosen-container';
var selectName = result.value;
//find corresponding a.chosen-single
//this.debug()
//click on a.chosen-single to activate chosen drop
var qfunction = function(link, value){
console.log('#################in qu function ###########', value);
driver.click(link).then(function(){
this.keys([value, '\uE007']).then(function(){
tester.iter++;
console.log('tester.iter', tester.iter);
console.log('tester.totalSelects', tester.totalSelects);
if(tester.iter == tester.totalSelects-1){
takeScreenshot.call(this, null);
}
execQueue[tester.iter]();
});//end keys.then
});//end click.then
}//end qfunction
execQueue.push(wrapFunction(qfunction, this, [container + ' a.chosen-single', fields[selectName]]));//end push
if(execQueue.length == tester.totalSelects - 1){
console.log('**********equal');
execQueue[tester.iter]();
}//end if equal
console.log('queue so far', execQueue.length);
});//end elementIdAttribute
})(s);//end closure
}//end for selects in container
});//end driver.elements
}else{
driver.addValue('input[name=' + p + ']', fields[p]);
}
})//end driver.isExisting
})(p);
}//end for each field
};//end fillFields
webdriverio
.remote(options)
.init()
.url('https://' + params.domain + '/' + params.clientId + '/?scope=' + params.scope + '&cart=' + params.cart + '&cfg=' + params.cfg + '&progress=' + params.progress + '&language=' + params.language + '¤cyId=' + params.currencyId) // navigate to the web page
.then(function(result) {
fillFields(this, fields);
});