-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sample.py
More file actions
40 lines (32 loc) · 1.29 KB
/
test_sample.py
File metadata and controls
40 lines (32 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import unittest
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
"""
Пример теста.
Вcе тесты запускаются из файлов вида test_*.py или *_test.py.
Перед выполнение тестов надо поднять контейнеры с сервисами selenium и nginx.
"""
class TestSample(unittest.TestCase):
def setUp(self):
"""
Инициализация теста, делаем соединение с selenium.
"""
self.driver = webdriver.Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME
)
def test_sample(self):
"""
Простой тест, переходим на страницу приметствия nginx и проверяем заголовок.
"""
driver = self.driver
driver.get('http://nginx')
self.assertIn('Welcome to nginx!', driver.title)
def tearDown(self):
"""
Деструктор теста, убиваем соединение с selenium.
"""
self.driver.close()
# для совместимости с unittest
if __name__ == '__main__':
unittest.main()