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

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

Offen
#116 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
514
Forks
175
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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 🙂

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.