ATF - Problem su Cloud Runner
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hi everyone,
i am running a test using both a local test runner and a cloud runner. It completes successfully in the first case, but not in the second. In the cloud environment, an error occurs during the step that involves opening a pop-up window to select a record. The script is provided below.
await (async function executeStep(screen, user, sn_atf, expect, waitFor, within, steps, params) {
var buttonId = "lookup.x_intes_dora_legal_entity_function_process_extra_campaign.process_level_1";
var lookupButton = null;
// 1. Cerca il pulsante nei vari iframe
lookupButton = document.getElementById(buttonId);
if (!lookupButton) {
var iframe = document.getElementById('gsft_main') || document.querySelector('iframe');
if (iframe && iframe.contentWindow) {
lookupButton = iframe.contentWindow.document.getElementById(buttonId);
}
}
if (!lookupButton) {
var iframes = document.querySelectorAll('iframe');
for (var i = 0; i < iframes.length; i++) {
try {
lookupButton = iframes[i].contentWindow.document.getElementById(buttonId);
if (lookupButton) break;
} catch(e) {}
}
}
if (!lookupButton) {
throw new Error("Impossibile trovare il pulsante della lente d'ingrandimento con ID: " + buttonId);
}
// Forza il tracciamento delle nuove finestre sovrascrivendo temporaneamente window.open
var lastOpenedWindow = null;
var originalWindowOpen = window.open;
var contextWindow = window;
// Applichiamo il monitoraggio sia sulla finestra corrente che su gsft_main se esiste
if (iframe && iframe.contentWindow) {
contextWindow = iframe.contentWindow;
originalWindowOpen = contextWindow.open;
contextWindow.open = function(url, name, specs) {
lastOpenedWindow = originalWindowOpen.apply(contextWindow, arguments);
return lastOpenedWindow;
};
} else {
window.open = function(url, name, specs) {
lastOpenedWindow = originalWindowOpen.apply(window, arguments);
return lastOpenedWindow;
};
}
// Clicca il pulsante per attivare il pop-up
lookupButton.focus();
lookupButton.click();
// Attesa asincrona per dare tempo al pop-up nativo di caricare il DOM
await new Promise(resolve => setTimeout(resolve, 4000));
// Ripristina immediatamente la funzione originale per non rompere ServiceNow
contextWindow.open = originalWindowOpen;
var targetDoc = null;
// Strategia A: Finestra intercettata dal nostro wrapper
if (lastOpenedWindow && lastOpenedWindow.document) {
targetDoc = lastOpenedWindow.document;
}
// Strategia B: Cerchiamo tramite il gestore globale dei popup di ServiceNow (UI16)
if (!targetDoc && top.g_popup_manager) {
try {
var popups = top.g_popup_manager.getPopups();
if (popups && popups.length > 0) {
targetDoc = popups[popups.length - 1].window.document;
}
} catch(e) {}
}
// Strategia C: Se non abbiamo la finestra, cerchiamo un iframe "nascosto" o iniettato con la lista
if (!targetDoc) {
var allDocs = [document];
var frames = document.querySelectorAll('iframe');
for (var m = 0; m < frames.length; m++) {
try { if (frames[m].contentWindow.document) allDocs.push(frames[m].contentWindow.document); } catch(e){}
}
for (var d = 0; d < allDocs.length; d++) {
// Cerca un iframe specifico di lookup generato da UI16 dentro la pagina
var inlineFrame = allDocs[d].querySelector('iframe[src*="sys_search_reference"]') ||
allDocs[d].querySelector('iframe[id*="lookup"]') ||
allDocs[d].getElementById('dialog_frame');
if (inlineFrame && inlineFrame.contentWindow && inlineFrame.contentWindow.document) {
targetDoc = inlineFrame.contentWindow.document;
break;
}
}
}
// Se abbiamo trovato il documento del pop-up, cerchiamo il primo record
if (targetDoc) {
var firstRecordLink = targetDoc.querySelector('a.glide_ref_item_link') ||
targetDoc.querySelector('tr[data-type="list_row"] a') ||
targetDoc.querySelector('.list_row a') ||
targetDoc.querySelector('a[sys_id]'); // Fallback basato sull'attributo sys_id dei record
if (firstRecordLink) {
firstRecordLink.focus();
firstRecordLink.click();
return; // Successo
}
}
throw new Error("Impossibile accedere al contenuto del pop-up o trovare il primo record. Verificare i blocchi pop-up del browser in ATF.");
}(screen, user, sn_atf, expect, waitFor, within, steps, params));
in the second case, I get an error "Impossibile accedere al contenuto del pop-up o trovare il primo record. Verificare i blocchi pop-up del browser in ATF."
thank you
in the second case, I get an error "Impossibile accedere al contenuto del pop-up o trovare il primo record. Verificare i blocchi pop-up del browser in ATF."
thank you
0 REPLIES 0