|
1 |
| -<h2>Методы-проверки в Page Object</h2> |
| 1 | +<h2>Verification methods in Page Object</h2> |
2 | 2 |
|
3 |
| -<p>Давайте теперь автоматизируем другой тест-кейс и посмотрим на его примере, как делать методы-проверки. </p> |
| 3 | +<p>Let's now automate another test case and see, through an example, how to create verification methods. </p> |
4 | 4 |
|
5 |
| -<p>Допустим, нам нужно проверять такой сценарий: </p> |
| 5 | +<p>Suppose we need to check the following scenario: </p> |
6 | 6 |
|
7 | 7 | <ol>
|
8 |
| - <li>Открыть главную страницу </li> |
9 |
| - <li>Проверить, что есть ссылка, которая ведет на логин </li> |
| 8 | + <li>Open the main page. </li> |
| 9 | + <li>Check if there is a link leading to login. </li> |
10 | 10 | </ol>
|
11 | 11 |
|
12 |
| -<p>Для этого в классе MainPage нужно реализовать метод, который будет проверять наличие ссылки. Обычно все такие методы-проверки называются похожим образом, мы будем называть их should_be_(название элемента). </p> |
| 12 | +<p>For this, in the MainPage class, we need to implement a method that will check the presence of the link. Typically, all such verification methods are named similarly; we will call them should_be_(element name). </p> |
13 | 13 |
|
14 |
| -<p>Итак, в классе MainPage создайте метод <code>should_be_login_link</code>. </p> |
| 14 | +<p>So, in the MainPage class, create the method <code>should_be_login_link</code>. </p> |
15 | 15 |
|
16 |
| -<p>Для первой пробы можно реализовать его самым примитивным образом: </p> |
| 16 | +<p>For the first attempt, you can implement it in the simplest way: </p> |
17 | 17 |
|
18 | 18 | <pre><code>def should_be_login_link(self):
|
19 | 19 | self.browser.find_element(By.CSS_SELECTOR, "#login_link_invalid")</code></pre>
|
20 | 20 |
|
21 |
| -<p>Сейчас мы намеренно сделали селектор неправильным, чтобы посмотреть, что именно выдаст тест, если поймает баг. Это хорошая практика: писать сначала красные тесты и только потом делать их зелеными. </p> |
| 21 | +<p>Currently, we intentionally made the selector incorrect to see what the test will report when it catches a bug. This is a good practice: writing red tests first and only then making them green. </p> |
22 | 22 |
|
23 |
| -<p>Добавляем в файл с тест-кейсами новый тест: </p> |
| 23 | +<p>Let's add a new test to the test case file: </p> |
24 | 24 |
|
25 | 25 | <pre><code class="language-python">def test_guest_should_see_login_link(browser):
|
26 | 26 | link = "http://selenium1py.pythonanywhere.com/"
|
27 | 27 | page = MainPage(browser, link)
|
28 | 28 | page.open()
|
29 | 29 | page.should_be_login_link()</code></pre>
|
30 | 30 |
|
31 |
| -<p>Запустите получившийся тест: </p> |
| 31 | +<p>Run the resulting test: </p> |
32 | 32 |
|
33 | 33 | <pre><code>pytest -v --tb=line --language=en test_main_page.py</code></pre>
|
34 | 34 |
|
35 |
| -<p>Вывод об ошибке не очень понятный, правда? Разобраться, что именно пошло не так, довольно тяжело. Поэтому в следующем шаге нам нужно будет обработать исключение, которое выбрасывает WebDriver. </p> |
| 35 | +<p>The error output is not very clear, right? It's quite challenging to understand what went wrong exactly. Therefore, in the next step, we will need to handle the exception thrown by the WebDriver. </p> |
0 commit comments