hjwp / hjwp/Book-TDD-Web-Dev-Python

ch11l032 - Typo in the test / issue with wait_for + truthiness

未关闭
#116 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
514
派生
175
PR 合并指标
30 天内没有已合并 PR

描述

In `ch11l032`, this is introduced, to test the HTML5 validation:

```python
self.wait_for(lambda: self.browser.find_elements_by_css_selector(
'#id_text:invalid'
))
```

However, it isn't testing anything.

Because we are using `find_elementS_by_css_selector(...)` if the element is not found an empty list will be returned and no exception will be raised. Therefore our `wait_for` immediately returns after the first try and we didn't test anything (try making it fail on purpose by looking for a different id, it won't fail).

To fix that, the solution is simple, remove the `S`. That way it'll either find that one element, or raise a `NoSuchElementException`, which is a `WebDriverException`, so our `wait_for` works as expected 🙂

贡献指南

这个仓库没有索引到贡献指南

调研方向

在章节的测试中找到 ch11l032,并检查使用 find_elements_by_css_selector 的 wait_for 调用。将选择器查找改为单数形式,然后运行相关的 ch11l032 测试,并验证缺少无效元素时等待会失败,而不是立即返回。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
testing
Issue 类型
缺陷
难度
1/5
预计耗时
1 小时以内
活跃度
停滞
描述清晰度
描述清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。