robotframework / robotframework/SeleniumLibrary

Switch Window sporadically fails with TypeError

オープン
#1,964 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
1.5k
フォーク
787
PR マージ指標
30日以内にマージされた PR はありません

説明

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?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

src/SeleniumLibrary/locators/windowmanager.py の、execute_script("return [ window.id, window.name ];") の結果をアンパックしている行から始めます。新しいタブが遅れて開く状態で Switch Window シナリオを再現し、既存の例外処理と timeout のフローを調べます。断続的に発生する TypeError が、ウィンドウ切り替えや要求された timeout の動作を壊すことなく解消されていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
testing-qa
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。