Best Python code snippet using SeleniumLibrary
Test_Picture.py
Source: Test_Picture.py
...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):...
Swapi_tests.py
Source: Swapi_tests.py
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...
test_setup_teardown_demo.py
Source: test_setup_teardown_demo.py
...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):...
test_allure_demo.py
Source: test_allure_demo.py
...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å®ä¹ç¨æ·åºæ¯...
Check out the latest blogs from LambdaTest on this topic:
To understand the agile testing mindset, we first need to determine what makes a team “agile.” To me, an agile team continually focuses on becoming self-organized and cross-functional to be able to complete any challenge they may face during a project.
Dries Buytaert, a graduate student at the University of Antwerp, came up with the idea of developing something similar to a chat room. Moreover, he modified the conventional chat rooms into a website where his friends could post their queries and reply through comments. However, for this project, he thought of creating a temporary archive of posts.
The purpose of developing test cases is to ensure the application functions as expected for the customer. Test cases provide basic application documentation for every function, feature, and integrated connection. Test case development often detects defects in the design or missing requirements early in the development process. Additionally, well-written test cases provide internal documentation for all application processing. Test case development is an important part of determining software quality and keeping defects away from customers.
Have you ever struggled with handling hidden elements while automating a web or mobile application? I was recently automating an eCommerce application. I struggled with handling hidden elements on the web page.
In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!