Infinity Loop with `Capture ** Screenshot` when using `{{index}}` (escaped) while file exists
@emanlove がすでに取り組んでいます。
2024年1月20日 から。
評価
この issue はまだ評価されていません。
説明
The following atest should be updated to this, so that the screenshot is taken twice.
Capture page screenshot with escaped braces
${file} = Capture Page Screenshot ${OUTPUTDIR}/screenshot-and-index/brackets-{{index}}-name.png
File Should Exist ${OUTPUTDIR}/screenshot-and-index/brackets-{index}-name.png
${file} = Capture Page Screenshot ${OUTPUTDIR}/screenshot-and-index/brackets-{{index}}-name.png # this line is new!
Should Be Equal ${file} ${OUTPUTDIR}${/}screenshot-and-index${/}brackets-{index}-name.png
${file} = Capture Page Screenshot ${OUTPUTDIR}/screenshot-and-index/brackets-{{index-name.png
File Should Exist ${OUTPUTDIR}/screenshot-and-index/brackets-{index-name.png
The problem is, that the code of _get_screenshot_path() does increment the index and then checks if either the (original) filename is equal to the formatted filename, which would mean that there was no {index} in it, or the file does not exists.
So that mean if the filename is before and after formatting the same, it does not matter if it exists, it will be overwritten.
BUT there is one special feature, that you can include {index} in the final file name, by doubling the braces.
So filename-{{index}}.png will be filename-{index}.png in the filesystem.
The problem now is, that the original filename (filename-{{index}}.png) is not equal with the formatted filename filename-{index}.png and therefore the index is increased. But there is no replaceable index in the original name, so the while loop is infinit.
The fix would be to compare not the original with the formatted, but two formatted with different index numbers with each other.
This is the fixed code:
def _get_screenshot_path(self, filename):
if self._screenshot_root_directory != EMBED:
directory = self._screenshot_root_directory or self.log_dir
else:
directory = self.log_dir
filename = filename.replace("/", os.sep)
index = 0
while True:
index += 1
formatted = _format_path(filename, index)
formatted_control = _format_path(filename, sys.maxsize) # control group with max int
path = os.path.join(directory, formatted)
# filename didn't contain {index} or unique path was found
if formatted == formatted_control or not os.path.exists(path): # two formatted texts are compared.
return path
kind regards
René
- 主要言語
- Python
- スター
- 1.5k
- フォーク
- 787
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
robotframework/SeleniumLibrary のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
robotframework/SeleniumLibrary#1941 · コメント 3 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 65/100
robotframework/SeleniumLibrary#1833 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
robotframework/SeleniumLibrary#1436 · コメント 5 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
robotframework/SeleniumLibrary#1993 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
robotframework/SeleniumLibrary#1992 · コメント 4 件 ·
robotframework/SeleniumLibrary の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
stephrobert/dsoxlab#238 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
sublimehq/package_control#1780 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
nwg-piotr/nwg-displays#145 ·