Skip to content

Commit ea86265

Browse files
authored
Merge pull request #54 from jetbrains-academy/stephen-hero-patch-47
Update task.md
2 parents a1d8163 + 0985873 commit ea86265

File tree

1 file changed

+12
-12
lines changed
  • page_object/first_tests_with_po/assert_method

1 file changed

+12
-12
lines changed
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
<h2>Проверка элемента на странице</h2>
1+
<h2>Checking an element on a page</h2>
22

3-
<p>Чтобы выводить адекватное сообщение об ошибке, мы будем все проверки осуществлять с помощью assert и перехватывать исключения.</p>
3+
<p>To display an appropriate error message, we will perform all checks using assert and catch the exceptions.</p>
44

5-
<p>Для этого напишем вспомогательный метод поиска элемента в нашей базовой странице BasePage, который будет возвращать нам <code>True</code> или <code>False</code>. Можно сделать это по-разному (с настройкой явных или неявных ожиданий). Сейчас воспользуемся неявным ожиданием.</p>
5+
<p>For this purpose, let's write a helper method to find an element on our BasePage, which will return either <code>True</code> or <code>False</code>. This can be done in various ways (with explicit or implicit waits). For now, let's use implicit waiting.</p>
66

7-
<p>1. В конструктор BasePage добавим команду для неявного ожидания со значением по умолчанию в 10:</p>
7+
<p>1. In the constructor of BasePage, let's add a command for implicit waiting with a default value of 10:</p>
88

99
<pre><code class="language-python">def __init__(self, browser, url, timeout=10):
1010
self.browser = browser
1111
self.url = url
1212
self.browser.implicitly_wait(timeout)</code></pre>
1313

14-
<p>2. Теперь в этом же классе реализуем метод <code>is_element_present</code>, в котором будем перехватывать исключение. В него будем передавать два аргумента: <em>как </em>искать (css, id, xpath и тд) и собственно <em>что </em>искать (строку-селектор). </p>
14+
<p>2. Now, in the same class, we'll implement the <code>is_element_present</code> method, where we will catch the exception. We will pass two arguments to it: <em>how </em>to search (css, id, xpath, etc.) and <em>what </em>to search for (the selector string). </p>
1515

16-
<p>Чтобы перехватывать исключение, нужна конструкция <code>try/except</code>: </p>
16+
<p>To catch the exception, we need a <code>try/except</code> construct: </p>
1717

1818
<pre><code class="language-python">def is_element_present(self, how, what):
1919
try:
2020
self.browser.find_element(how, what)
21-
except (имя исключения):
21+
except (name of exception):
2222
return False
2323
return True</code></pre>
2424

25-
<p>Чтобы импортировать нужное нам исключение, в самом верху файла нужно указать: </p>
25+
<p>To import the required exception, you need to specify the following at the very top of the file: </p>
2626

27-
<pre><code>from selenium.common.exceptions import имя_исключения</code></pre>
27+
<pre><code>from selenium.common.exceptions import exception_name</code></pre>
2828

29-
<p>Отлично! Теперь для всех проверок, что элемент действительно присутствует на странице, мы можем использовать этот метод. </p>
29+
<p>Great! Now, we can use this method for all checks on the presence of an element on the page. </p>
3030

31-
<p>3. Теперь модифицируем метод проверки ссылки на логин так, чтобы он выдавал адекватное сообщение об ошибке: </p>
31+
<p>3. Now, let's modify the method for checking the login link so that it provides an appropriate error message: </p>
3232

3333
<pre><code>def should_be_login_link(self):
3434
assert self.is_element_present(By.CSS_SELECTOR, "#login_link_invalid"), "Login link is not presented"</code></pre>
3535

36-
<p>Запустите тесты и посмотрите, что вывод об ошибке стал более понятным: </p>
36+
<p>Run the tests and see that the error output has become more understandable: </p>
3737

3838
<pre><code>pytest -v --tb=line --language=en test_main_page.py</code></pre>

0 commit comments

Comments
 (0)