robotframework / robotframework/SeleniumLibrary

Switch Window sporadically fails with TypeError

Aperta
#1,964 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
1.5k
Fork
787
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Observed with

Python 3.13.0
SeleniumLibrary 6.7.1

Scenario

I have the following scenario in a test which fails sporadically:

  1. Link in an (internal) application is clicked which opens a different URL in a new tab
  2. Switch Window is called with the expected URL as locator and 10 s as a timeout
Expected behaviour

The new window is switched to. If the window is not immediately available/ready when this keyword is started, it should wait until the window can be switched to, within the given timeout limits.

Error

This works just fine most of the time, but occasionally I get the following error:
TypeError: cannot unpack non-iterable NoneType object
This error shows up pretty much instantly (within a few hundred ms), so the timeout is not taken into account.
However, in the associated screenshots, the expected page is always shown.

Analysis

I looked into the library's code and added some extra logging, which showed the error was coming from this line:
https://github.com/robotframework/SeleniumLibrary/blob/ce9d0ec510bd99c5a1b1cd114f767c7feeae1208/src/SeleniumLibrary/locators/windowmanager.py#L199

The call to self.driver.execute_script("return [ window.id, window.name ];") returns None, thus the assignment to the two variables fails with the above error.

Adding a 1 s sleep right before the call to execute_script makes the error no longer occur (even with many iterations of the test), so it does seem to be somehow timing related.
I guess there's a short timeframe where the window is there but not fully ready and this makes the function call fail? But I wasn't able to understand the exact nature of this presumed 'not ready' state so far.

Proposed solution

The TypeError could be added to the already present except, which successfully avoided failures due to this in my scenario.
Adding this would be trivial, but I'm not sure about the implications:

  • does anything depend on the current behaviour that raises an error in this case (seems not, but I'm not super familiar with the library's codebase)?
  • would it be appropriate to suppress this error in the library, given it is not fully understood what exactly the nature of the actual, underlying error is?
    Do you have any guidance how to proceed here?

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in src/SeleniumLibrary/locators/windowmanager.py, alla riga che destruttura il risultato di execute_script("return [ window.id, window.name ];"). Riproduci lo scenario Switch Window con una nuova scheda aperta con un ritardo e analizza la gestione delle eccezioni esistente e il flusso del timeout. Il lavoro è completo quando il TypeError intermittente è stato risolto senza compromettere il cambio di finestra o il comportamento di timeout richiesto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
testing-qa
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.