Estoy usando Webdriver.io/Nodejs/Mocha y cuando trato de cambiar de la pestaña principal a la pestaña secundaria, la mayoría de las veces funciona; sin embargo, hay momentos en que la pestaña tardará mucho en cargarse debido a problemas/anuncios incorrectos en la página y durante esos momentos, aunque obtengo el GUID de la ventana/pestaña, todavía no cambia y permanece en el padre pestaña. No sucede todo el tiempo, pero de vez en cuando no cambia.
¿La página tiene que cargarse por completo para poder cambiar a la pestaña chid? ¿Me estoy perdiendo algo? Cualquier ayuda sería apreciada. ¡Gracias!
Ejecución:
npx mocha --config ./mocharc.json ./test/test.jsArchivo de prueba: test.js
it('Test Case: Switch Tabs', async () => { let parentGUID; let childGUID; // get parent GUID parentGUID = await this.driver.getWindowHandle(); // click element to launch new tab await this.driver.elementClick('//a[@id="test"]'); // wait until new tab loads await this.driver.pause(2000); // get all GUID's const allGUIDs = await this.driver.getWindowHandles(); // check all GUID's and see which one is the child for (let i = 0; i < allGUIDs.length; i++) { if (allGUIDs[i] !== parentGUID) { childGUID = allGUIDs[i]; } } // switch to child tab await this.driver.switchToWindow(childGUID); // assert content on the new page here // ... // ... // ... // close tab await this.driver.closeWindow(); // switch to parent window/tab await this.driver.switchToWindow(parentGUID); }Esto parece un simple error de codificación. Mientras inicia su parentGUID, no le asigna ningún valor. Luego lo está usando para comparar en su bucle for. A veces, el GUID secundario se asigna con el GUID primario. En este caso, el cambio parece no estar sucediendo. Lo he corregido a continuación.
it('Test Case: Switch Tabs', async () => { let childGUID; // get parent GUID const parentGUID = await this.driver.getWindowHandle(); // click element to launch new tab await this.driver.elementClick('//a[@id="test"]'); // wait until new tab loads await this.driver.pause(2000); // get all GUID's const allGUIDs = await this.driver.getWindowHandles(); // check all GUID's and see which one is the child for (let i = 0; i < allGUIDs.length; i++) { if (allGUIDs[i] !== parentGUID) { childGUID = allGUIDs[i]; } } // switch to child tab await this.driver.switchToWindow(childGUID); // assert content on the new page here // ... // ... // ... // close tab await this.driver.closeWindow(); // switch to parent window/tab await this.driver.switchToWindow(parentGUID); }