Best Python code snippet using uiautomator
api_hh_vacancies_text_tests.py
Source:api_hh_vacancies_text_tests.py  
1import requests, lorem2url_base = "https://api.hh.ru/vacancies?text="3token = input( "ÐведиÑе Ñокен: " )4headers = {5  'Authorization': 'Bearer ' + token6}7def get_response_with_testing_param(test):8	return requests.request("GET", url_base + test, headers=headers)9def find_if_next_symbols_after_sub_diff(main_str, sub):10	answer = False11	start = main_str.find(sub, 0)12	if start == -1: return answer13	a = main_str[start + len(sub)]	14	while True:15		start = main_str.find(sub, start)16		if start == -1: return17		if a != main_str[start  + len(sub)]: 18			answer = True19			break20		start += len(sub)21	return answer22# general tests in 'text' param:23def test_wrong_spelling_Status_code_equals_200():24	test_text = 'моÑкÑва'25	response = get_response_with_testing_param(test_text)26	assert response.status_code == 20027def test_wrong_spelling_Get_right_answer():28	test_text = 'моÑкÑва'29	response = get_response_with_testing_param(test_text)30	assert response.text.find('ÐоÑква') != -131def test_magic_several_params_Status_code_equals_200():32	test_text = 'бÑÑ
галÑÐµÑ Ð¾Ð¼Ñк 15000'33	response = get_response_with_testing_param(test_text)34	assert response.status_code == 20035def test_magic_several_params_Magic_works():36	test_text = 'бÑÑ
галÑÐµÑ Ð¾Ð¼Ñк 15000'37	response = get_response_with_testing_param(test_text)38	# if we got separate params in alternate_url then magic works39	assert response.json()['alternate_url'].find('salary=15000') != -1 and response.json()['alternate_url'].find('text=%D0%B1%D1%83%D1%85%D0%B3%D0%B0%D0%BB%D1%82%D0%B5%D1%80') != -1 and response.json()['alternate_url'].find('area=68') != -140def test_too_many_symbols_Status_code_equals_502():41	test_text = lorem.return_lorem(4500)42	response = get_response_with_testing_param(test_text)43	assert response.status_code == 502 # 502 - OK for too long text.44def test_text_equals_null_Status_code_equals_200():45	test_text = 'null'46	response = get_response_with_testing_param(test_text)47	assert response.status_code == 20048def test_text_empty_two_quotes_Status_code_equals_200():49	test_text = ''50	response = get_response_with_testing_param(test_text)51	assert response.status_code == 20052def test_text_non_ASCII_Status_code_equals_200():53	test_text = 'à¤à¤¾à¤°à¤¤'54	response = get_response_with_testing_param(test_text)55	assert response.status_code == 20056def test_text_correct_Status_code_equals_200():57	test_text = 'ÑбоÑÑик'58	response = get_response_with_testing_param(test_text)59	assert response.status_code == 20060def test_text_correct_Get_right_answer():61	test_text = 'ÑбоÑÑик'62	response = get_response_with_testing_param(test_text)63	assert response.text.find('ÑбоÑÑик') != -164# search language tests:65def test_text_synonym_Get_right_answer():66	test_text = 'пиаÑÑик'67	response = get_response_with_testing_param(test_text)68	assert response.text.find('PR') != -169def test_text_part_of_word_Get_right_answer():70	test_text = 'Ðео*'71	response = get_response_with_testing_param(test_text)72	assert find_if_next_symbols_after_sub_diff(response.text, 'Ðео')73def test_text_AND_Get_right_answer():74	test_text = '!ÑбоÑÑик AND !клинеÑ'75	response = get_response_with_testing_param(test_text)76	first_item = str(response.json()['items'][0]).lower()77	assert first_item.find('ÑбоÑÑик') != -1 and first_item.find('клинеÑ') != -178def test_text_NOT_Get_right_answer():79	test_text = 'клининг NOT ÑбоÑÑик'80	response = get_response_with_testing_param(test_text)81	assert response.text.lower().find('ÑбоÑÑик') == -182def test_text_OR_Get_right_answer():83	test_text = 'клининг OR ÑбоÑÑик'84	response = get_response_with_testing_param(test_text)85	assert response.text.lower().find('ÑбоÑÑик') != -1 and response.text.find('клининг') != -186def test_text_find_phrase_Get_right_answer():87	test_text = 'Ñ
олоднÑе звонки'88	response = get_response_with_testing_param(test_text)89	assert response.text.lower().find('Ñ
олоднÑе звонки') != -190# search by fields tests:91#!ID:92def test_ID_equals_null_Status_code_equals_200():93	test_text = '!ID:null'94	response = get_response_with_testing_param(test_text)95	assert response.status_code == 20096def test_ID_empty_two_quotes_Status_code_equals_200():97	test_text = '!ID:""'98	response = get_response_with_testing_param(test_text)99	assert response.status_code == 200100def test_ID_negative_num_Status_code_equals_200():101	test_text = '!ID:-1'102	response = get_response_with_testing_param(test_text)103	assert response.status_code == 200104def test_ID_positive_num_incorrect_Status_code_equals_200():105	test_text = '!ID:100'106	response = get_response_with_testing_param(test_text)107	assert response.status_code == 200108def test_ID_positive_num_correct_Status_code_equals_200():109	test_text = '!ID:41029616'110	response = get_response_with_testing_param(test_text)111	assert response.status_code == 200112def test_ID_russian_text_Status_code_equals_200():113	test_text = '!ID:админ'114	response = get_response_with_testing_param(test_text)115	assert response.status_code == 200116def test_ID_english_text_Status_code_equals_200():117	test_text = '!ID:admin'118	response = get_response_with_testing_param(test_text)119	assert response.status_code == 200120# next test fails, we can see 121def test_ID_non_ASCII_Status_code_equals_200():122	test_text = '!ID:à¤à¤¾à¤°à¤¤'123	response = get_response_with_testing_param(test_text)124	assert response.status_code == 200125def test_ID_no_exclamation_mark_Status_code_equals_502():126	test_text = 'ID:41029616'127	response = get_response_with_testing_param(test_text)128	assert response.status_code == 502129# !COMPANY_ID:130def test_COMPANY_ID_equals_null_Status_code_equals_200():131	test_text = '!COMPANY_ID:null'132	response = get_response_with_testing_param(test_text)133	assert response.status_code == 200134def test_COMPANY_ID_empty_two_quotes_Status_code_equals_200():135	test_text = '!COMPANY_ID:""'136	response = get_response_with_testing_param(test_text)137	assert response.status_code == 200138def test_COMPANY_ID_negative_num_Status_code_equals_200():139	test_text = '!COMPANY_ID:-1'140	response = get_response_with_testing_param(test_text)141	assert response.status_code == 200142def test_COMPANY_ID_positive_num_incorrect_Status_code_equals_200():143	test_text = '!COMPANY_ID:100'144	response = get_response_with_testing_param(test_text)145	assert response.status_code == 200146def test_COMPANY_ID_positive_num_correct_Status_code_equals_200():147	test_text = '!ID:2067747'148	response = get_response_with_testing_param(test_text)149	assert response.status_code == 200150def test_COMPANY_ID_russian_text_Status_code_equals_200():151	test_text = '!COMPANY_ID:админ'152	response = get_response_with_testing_param(test_text)153	assert response.status_code == 200154def test_COMPANY_ID_english_text_Status_code_equals_200():155	test_text = '!COMPANY_ID:admin'156	response = get_response_with_testing_param(test_text)157	assert response.status_code == 200158def test_COMPANY_ID_non_ASCII_Status_code_equals_200():159	test_text = '!COMPANY_ID:à¤à¤¾à¤°à¤¤'160	response = get_response_with_testing_param(test_text)161	assert response.status_code == 200162# NAME:163def test_NAME_equals_null_Status_code_equals_200():164	test_text = 'NAME:null'165	response = get_response_with_testing_param(test_text)166	assert response.status_code == 200167def test_NAME_empty_two_quotes_Status_code_equals_200():168	test_text = 'NAME:""'169	response = get_response_with_testing_param(test_text)170	assert response.status_code == 200171def test_NAME_non_ASCII_Status_code_equals_200():172	test_text = 'NAME:à¤à¤¾à¤°à¤¤'173	response = get_response_with_testing_param(test_text)174	assert response.status_code == 200175def test_NAME_correct_Status_code_equals_200():176	test_text = 'NAME:ÑбоÑÑик'177	response = get_response_with_testing_param(test_text)178	assert response.status_code == 200179def test_NAME_correct_Get_right_answer():180	test_text = 'NAME:!ÑбоÑÑик'181	response = get_response_with_testing_param(test_text)182	first_item_name = str(response.json()['items'][0]['name']).lower()183	assert first_item_name.find('ÑбоÑÑик') != -1184# COMPANY_NAME185def test_COMPANY_NAME_equals_null_Status_code_equals_200():186	test_text = 'COMPANY_NAME:null'187	response = get_response_with_testing_param(test_text)188	assert response.status_code == 200189def test_COMPANY_NAME_empty_two_quotes_Status_code_equals_200():190	test_text = 'COMPANY_NAME:""'191	response = get_response_with_testing_param(test_text)192	assert response.status_code == 200193def test_COMPANY_NAME_non_ASCII_Status_code_equals_200():194	test_text = 'COMPANY_NAME:à¤à¤¾à¤°à¤¤'195	response = get_response_with_testing_param(test_text)196	assert response.status_code == 200197def test_COMPANY_NAME_correct_Status_code_equals_200():198	test_text = 'COMPANY_NAME:ÐазпÑом'199	response = get_response_with_testing_param(test_text)200	assert response.status_code == 200201def test_COMPANY_NAME_correct_Get_right_answer():202	test_text = 'COMPANY_NAME:ÐазпÑом'203	response = get_response_with_testing_param(test_text)204	first_item_company_name = str(response.json()['items'][0]['employer']['name']).lower()205	assert first_item_company_name.find('газпÑом') != -1	206# DESCRIPTION207def test_DESCRIPTION_equals_null_Status_code_equals_200():208	test_text = 'DESCRIPTION:null'209	response = get_response_with_testing_param(test_text)210	assert response.status_code == 200211def test_DESCRIPTION_empty_two_quotes_Status_code_equals_200():212	test_text = 'DESCRIPTION:""'213	response = get_response_with_testing_param(test_text)214	assert response.status_code == 200215def test_DESCRIPTION_non_ASCII_Status_code_equals_200():216	test_text = 'DESCRIPTION:à¤à¤¾à¤°à¤¤'217	response = get_response_with_testing_param(test_text)218	assert response.status_code == 200219def test_DESCRIPTION_correct_Status_code_equals_200():220	test_text = 'DESCRIPTION:ÐомпаниÑ'221	response = get_response_with_testing_param(test_text)...test_function.py
Source:test_function.py  
1from src.RunProcessClass import RunTest2# from src.BuildClass import column3from selenium import webdriver4from selenium.webdriver.common.by import By5import time6Column_Position_list = ['jss81', 'jss87', 'jss93', 'jss99', 'jss130', 'jss145']7Reaction_Position_first = '//*[@id="gatsby-focus-wrapper"]/div/div/div[1]/div/div/div/div/div[2]/div/div/div[2]/div/div/form/div[4]/span'8Reaction_Position_middle = '//*[@id="gatsby-focus-wrapper"]/div/div/div[1]/div/div/div/div/div[2]/div/div/div[2]/div/div/form/div[5]/span'9Reaction_Position_last = '//*[@id="gatsby-focus-wrapper"]/div/div/div[1]/div/div/div/div/div[2]/div/div/div[2]/div/div/form/div[6]/span'10Reaction_Position_email = '//*[@id="gatsby-focus-wrapper"]/div/div/div[1]/div/div/div/div/div[2]/div/div/div[2]/div/div/form/div[7]/span'11Reaction_Position_phone = '//*[@id="gatsby-focus-wrapper"]/div/div/div[1]/div/div/div/div/div[2]/div/div/div[2]/div/div/form/div[8]/div[1]/div/div[2]/div/span'12Reaction_Position_ma = '//*[@id="gatsby-focus-wrapper"]/div/div/div[1]/div/div/div/div/div[2]/div/div/div[2]/div/div/form/div[8]/div[2]/div/div/div[2]/div/span'13Reaction_Position_list = [Reaction_Position_first, Reaction_Position_middle, Reaction_Position_last,14                          Reaction_Position_email, Reaction_Position_phone, Reaction_Position_ma]15web_address = "https://acy.com/en/open-live-account"16PATH = "/Users/hsinyulin/chromedriver"  # chromedriveréåå·è¡æªçæå¨ä½ç½®17driver = webdriver.Chrome(PATH)18driver.get(web_address)  # open the website19driver.implicitly_wait(8)  # è®ç¶²é ãå½è·³è¦çªè·ä¸ä¸20LanguageXPath = '//*[@id="gatsby-focus-wrapper"]/div[1]/div[2]/div[2]/div[2]/div[1]'21EnglishXPath = '//*[@id="gatsby-focus-wrapper"]/div[1]/div[2]/div[2]/div[2]/div[2]/div/div[1]'22driver.find_element(By.XPATH, LanguageXPath).click()  # é»éèªè¨é¸å®23driver.find_element(By.XPATH, EnglishXPath).click()  # é»é¸English24driver.find_element(By.CLASS_NAME, 'button').click()  # 黿confirm25def test_FirstName():26    # driver = webdriver.Chrome(PATH)27    # driver.get(web_address)  # open the website28    #29    # driver.implicitly_wait(8)  # è®ç¶²é ãå½è·³è¦çªè·ä¸ä¸30    # LanguageXPath = '//*[@id="gatsby-focus-wrapper"]/div[1]/div[2]/div[2]/div[2]/div[1]'31    # EnglishXPath = '//*[@id="gatsby-focus-wrapper"]/div[1]/div[2]/div[2]/div[2]/div[2]/div/div[1]'32    # driver.find_element(By.XPATH, LanguageXPath).click()  # é»éèªè¨é¸å®33    # driver.find_element(By.XPATH, EnglishXPath).click()  # é»é¸English34    #35    # driver.find_element(By.CLASS_NAME, 'button').click()  # 黿confirm36    col_position = Column_Position_list[0]37    reaction_position = Reaction_Position_list[0]38    test_text = ["", "123", "Simon"]39    FirstName = RunTest(driver, col_position, reaction_position, test_text)40    Result = FirstName.run()41    assert Result[test_text[0]] == 'This field is required*'42    assert Result[test_text[1]] == 'Invalid first name.(max length 40)'43    assert Result[test_text[2]] == ''44def test_MiddleName():45    col_position = Column_Position_list[1]46    reaction_position = Reaction_Position_list[1]47    test_text = ["", "123", "Simon"]48    MiddleName = RunTest(driver, col_position, reaction_position, test_text)49    Result = MiddleName.run()50    assert Result[test_text[0]] == ''51    assert Result[test_text[1]] == ''52    assert Result[test_text[2]] == ''53def test_LastName():54    col_position = Column_Position_list[2]55    reaction_position = Reaction_Position_list[2]56    test_text = ["", "123", "Simon"]57    LastName = RunTest(driver, col_position, reaction_position, test_text)58    Result = LastName.run()59    assert Result[test_text[0]] == 'This field is required*'60    assert Result[test_text[1]] == 'Invalid last name.(max length 80)'61    assert Result[test_text[2]] == ''62def test_Email():63    col_position = Column_Position_list[3]64    reaction_position = Reaction_Position_list[3]65    test_text = ['', '123', '123@gmail.com']66    Email = RunTest(driver, col_position, reaction_position, test_text)67    Result = Email.run()68    assert Result[test_text[0]] == 'This field is required*'69    assert Result[test_text[1]] == 'The email format is wrong'70    assert Result[test_text[2]] == ''71def test_Phone():72    col_position = Column_Position_list[4]73    reaction_position = Reaction_Position_list[4]74    test_text = ['', '29290740#123', '(02)29202920']75    Phone = RunTest(driver, col_position, reaction_position, test_text)76    Result = Phone.run()77    assert Result[test_text[0]] == 'This field is required*'78    assert Result[test_text[1]] == 'The phone format is wrong'79    assert Result[test_text[2]] == ''80def test_MobileAuthentication():81    col_position = Column_Position_list[5]82    reaction_position = Reaction_Position_list[5]83    test_text = ['', '@@', '123']84    MA = RunTest(driver, col_position, reaction_position, test_text)85    Result = MA.run()86    assert Result[test_text[0]] == 'This field is required*'87    assert Result[test_text[1]] == 'The authentication code is wrong'...test_file.py
Source:test_file.py  
1import sys2import os3parent_dir = os.path.dirname(os.path.realpath(__file__)) + "/../"4sys.path.append(parent_dir) # a bit of a hack, but it makes the import the same5from objects.file import File6def get_file_path(path):7    return os.path.dirname(os.path.realpath(__file__)) + "/" + path8class TestFileMethods:9    def test_init(self):10        test_file = open(get_file_path("files/file/init.skel"))11        test_text = test_file.read()12        file_object = File(test_text)13        assert file_object.text == test_text14        assert file_object.init_text == test_text15    def test_init_replacements(self):16        test_file = open(get_file_path("files/file/init.skel"))17        test_text = test_file.read()18        replacements = [19            ["replace_text", "key", "value"],20            ["replace_file", "key2", get_file_path("files/file/init.inc")]21        ]22        file_object = File(test_text, replacements)23        result = test_text.replace("<<<key>>>", "value").replace("<<<key2>>>", open(get_file_path("files/file/init.inc")).read())24        assert file_object.text == result25    def test_insert_text(self):26        test_file = open(get_file_path("files/file/insert.skel"))27        test_text = test_file.read()28        file_object = File(test_text)29        file_object.insert_text("insert", "test")30        result = open(get_file_path("files/file/insert_result.skel")).read()31        assert file_object.text == result32    def test_insert_file(self):33        test_file = open(get_file_path("files/file/insert.skel"))34        test_text = test_file.read()35        file_object = File(test_text)36        file_object.insert_file("insert", get_file_path("files/file/insert.inc"))37        result = open(get_file_path("files/file/insert_file_result.skel")).read()38        assert file_object.text == result39    def test_remove_modelines(self):40        test_file = open(get_file_path("files/file/modelines.skel"))41        test_text = test_file.read()42        result = "\n".join(test_text.split("\n")[5:])43        file_object = File(test_text, remove_modelines=0)44        file_object.remove_modelines()45        assert file_object.text == result46    def test_remove_modelines_custom_number(self):47        test_file = open(get_file_path("files/file/modelines.skel"))48        test_text = test_file.read()49        result = ""50        file_object = File(test_text, remove_modelines=0)51        file_object.remove_modelines(n=10)52        assert file_object.text == result53    def test_remove_modelines_by_default(self):54        test_file = open(get_file_path("files/file/modelines.skel"))55        test_text = test_file.read()56        result = "\n".join(test_text.split("\n")[5:])57        file_object = File(test_text)...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!!
