How to use teardown_function method in SeleniumLibrary

Best Python code snippet using SeleniumLibrary

Test_Picture.py

Source:Test_Picture.py Github

copy

Full Screen

...12 """A setup function to be called by nose at the beginning of every test.13 Creates global variables used in most tests."""14 global pict15 pict = Picture(1, 1)16def teardown_function():17 """A teardown function to be called by nose at the end of every test.18 Destroys global variables created in setup."""19 global pict20 del pict21###############################################################################22# Helper functions23##############################################################################24def ensure_files_equal(filename1, filename2):25 """Raise ValueError if two image files referred to by (filename1,26 filename2) are not identical."""27 p1 = Picture(filename=filename1)28 p2 = Picture(filename=filename2)29 ensure_pictures_equal(p1, p2)30def ensure_pictures_equal(p1, p2):...

Full Screen

Full Screen

Swapi_tests.py

Source:Swapi_tests.py Github

copy

Full Screen

1import requests2import json3import pytest4import swapi5class TestSwapi:6 def test_start_page(self, setup_function, teardown_function):7 """8 Проверка стартовой страницы9 """10 session = requests.session()11 url = "https://swapi.co/api/"12 resp = session.get(url)13 assert resp.status_code == 20014 def test_allowed_methods(self, setup_function, teardown_function):15 """16 Проверка разрешённых методов для запроса и получения данных17 """18 resp_get = requests.get("https://swapi.co/api/planets/1")19 assert resp_get.status_code == 20020 # Приводит к перенаправлению (не соответствует документации)21 resp_head = requests.head("https://swapi.co/api/planets/1")22 assert resp_head.status_code == 20023 resp_options = requests.options("https://swapi.co/api/planets/1", headers={'Content-type': 'application/json'})24 assert resp_options.status_code == 20025 def test_not_allowed_methods(self, setup_function, teardown_function):26 """27 Проверка запрещённых методов для запроса и получения данных28 """29 # Работает (не соответствует документации - метода POST нет среди разрешённых)30 resp = requests.post("https://swapi.co/api/planets/1", headers={'Content-type': 'application/json'},31 json={"name": "Betelgeuse", "diameter": "100000001"})32 assert resp.status_code == 40533 resp = requests.put("https://swapi.co/api/planets/1", json={"name": "Betelgeuse", "diameter": "100000001"})34 assert resp.status_code == 40535 resp = requests.delete("https://swapi.co/api/planets/1")36 assert resp.status_code == 40537 def test_json(self, setup_function, teardown_function):38 """39 Проверка формата получаемых данных (json)40 """41 resp = requests.get("https://swapi.co/api/planets/1")42 assert resp.status_code == 20043 assert 'application/json' in resp.headers['Content-Type']44 def test_number_of_planets(self, setup_function, teardown_function):45 """46 Проверка общего количества планет, соответствие документации47 """48 resp = requests.get("https://swapi.co/api/planets")49 assert resp.status_code == 20050 json_decoded_result = resp.json()51 number_of_planets = json_decoded_result['count']52 assert number_of_planets == 6153 def test_all_planets_attributes(self, setup_function, teardown_function):54 """55 Проверка атрибутов всех планет внутри полученного json56 """57 resp = requests.get("https://swapi.co/api/planets")58 assert resp.status_code == 20059 json_decoded_result = resp.json()60 # Получение количества планет61 number_of_planets = json_decoded_result['count']62 # Атрибуты планет63 planets_attributes = ["name", "rotation_period", "orbital_period", "diameter", "climate",64 "gravity", "terrain", "surface_water", "population", "residents",65 "films", "created", "edited", "url"]66 # Проверка атрибутов в json для каждой из планет67 for planet in range(1, number_of_planets + 1):68 resp = requests.get("https://swapi.co/api/planets/{}".format(planet))69 assert resp.status_code == 20070 json_decoded_result = resp.json()71 for key, value in json_decoded_result.items():72 assert key in planets_attributes...

Full Screen

Full Screen

test_setup_teardown_demo.py

Source:test_setup_teardown_demo.py Github

copy

Full Screen

...14def getFuncargs_Func():15 return tmpFunc16@pytest.fixture(scope="function")17def setup_function(request):18 def teardown_function():19 print("teardown_function")20 request.addfinalizer(teardown_function)21 print("setup_function called.")22@pytest.fixture(scope="module")23def setup_module(request):24 def teardown_module():25 print("teardown_module called.")26 request.addfinalizer(teardown_module)27 print("setup_module called")28@pytest.fixture(scope="function")29def setup_function_Num(request, getFuncargs_Num):30 def teardown_function():31 print("teardown_function, %d" %getFuncargs_Num)32 request.addfinalizer(teardown_function)33 print("setup_function called. %d" %getFuncargs_Num)34@pytest.fixture(scope="function")35def setup_function_Class(request, getFuncargs_Class):36 def teardown_function():37 print("teardown_function called." )38 getFuncargs_Class.hello()39 request.addfinalizer(teardown_function)40 print("setup_function called.")41 getFuncargs_Class.hello()42@pytest.fixture(scope="function")43def setup_function_Func(request, getFuncargs_Func):44 def teardown_function():45 print("teardown_function called." )46 getFuncargs_Func()47 request.addfinalizer(teardown_function)48 print("setup_function called.")49 getFuncargs_Func()50def test_1(setup_function):51 print("Test_1 called.")52def test_2(setup_module):53 print("Test_2 called.")54def test_3(setup_module):55 print("Test_3 called.")56def test_4(setup_function_Num):57 print("Test_4 called.")58def test_5(setup_function_Class):...

Full Screen

Full Screen

test_allure_demo.py

Source:test_allure_demo.py Github

copy

Full Screen

...5@allure.feature('测试用例功能') # feature定义功能6class TestClass(object):7 @pytest.fixture(scope='function')8 def setup_function(request):9 def teardown_function():10 print("teardown_function called.")11 request.addfinalizer(teardown_function) # 此内嵌函数做teardown工作12 print('setup_function called.')13 @pytest.fixture(scope='module')14 def setup_module(request):15 def teardown_module():16 print("teardown_module called.")17 request.addfinalizer(teardown_module)18 print('setup_module called.')19 @allure.story('功能测试用例1') # story定义用户场景20 @pytest.mark.website21 def test_1(setup_function):22 print('Test_1 called.')23 @allure.story('功能测试用例2') # story定义用户场景...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumLibrary automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful