Best Python code snippet using Airtest
test_proxy_selector.py
Source: test_proxy_selector.py
...69 self.proxy_list = ["8.8.8.8:1", "8.8.8.8:2"]70 def test_remove_inputs(self):71 selector = ProxySelector(self.user_proxy)72 # Test with invalid proxy73 self.assertFalse(selector.remove_proxy(123456))74 self.assertIsNotNone(selector._proxy)75 # Test with valid proxy76 # Proxy not exist77 self.assertFalse(selector.remove_proxy("127.0.0.1:1337"))78 self.assertIsNotNone(selector._proxy)79 # Proxy exist80 self.assertTrue(selector.remove_proxy("8.8.8.8:1337"))81 self.assertIsNone(selector._proxy)82 def test_remove_with_single_proxy(self):83 selector = ProxySelector()84 selector._proxy = self.user_proxy85 self.assertTrue(selector.remove_proxy(self.user_proxy))86 self.assertIsNone(selector._proxy)87 def test_remove_with_multiple_proxies(self):88 selector = ProxySelector()89 selector._proxy_list = self.proxy_list90 self.assertTrue(selector.remove_proxy(self.proxy_list[1]))91 self.assertEqual(selector._proxy_list, ["8.8.8.8:1"])92 self.assertTrue(selector.remove_proxy(self.proxy_list[0]))93 self.assertEqual(selector._proxy_list, [])94 def test_remove_with_single_proxy_fallback_prevention(self):95 selector = ProxySelector(prevent_fallback=True)96 selector._proxy = self.user_proxy97 self.assertFalse(selector.remove_proxy(self.user_proxy))98 self.assertEqual(selector._proxy, self.user_proxy)99 def test_remove_with_multiple_proxies_fallback_prevention(self):100 selector = ProxySelector(prevent_fallback=True)101 selector._proxy_list = self.proxy_list102 self.assertTrue(selector.remove_proxy(self.proxy_list[1]))103 self.assertEqual(selector._proxy_list, ["8.8.8.8:1"])104 self.assertFalse(selector.remove_proxy(self.proxy_list[0]))105 self.assertEqual(selector._proxy_list, ["8.8.8.8:1"])106 def test_remove_with_multiple_proxies_overwrite(self):107 selector = ProxySelector()108 selector._proxy = self.user_proxy109 selector._proxy_list = self.proxy_list110 self.assertTrue(selector.remove_proxy(self.proxy_list[0]))111 self.assertEqual(selector._proxy, self.user_proxy)112 self.assertEqual(selector._proxy_list, ["8.8.8.8:2"])113 self.assertTrue(selector.remove_proxy(self.user_proxy))114 self.assertIsNone(selector._proxy)115 self.assertEqual(selector._proxy_list, ["8.8.8.8:2"])116 self.assertTrue(selector.remove_proxy(self.proxy_list[0]))117 self.assertIsNone(selector._proxy)118 self.assertEqual(selector._proxy_list, [])119 def test_remove_with_multiple_proxies_overwrite_fallback_prevention(self):120 selector = ProxySelector(prevent_fallback=True)121 selector._proxy = self.user_proxy122 selector._proxy_list = self.proxy_list123 self.assertTrue(selector.remove_proxy(self.proxy_list[0]))124 self.assertEqual(selector._proxy, self.user_proxy)125 self.assertEqual(selector._proxy_list, ["8.8.8.8:2"])126 self.assertTrue(selector.remove_proxy(self.user_proxy))127 self.assertIsNone(selector._proxy)128 self.assertEqual(selector._proxy_list, ["8.8.8.8:2"])129 self.assertFalse(selector.remove_proxy(self.proxy_list[0]))130 self.assertIsNone(selector._proxy)131 self.assertEqual(selector._proxy_list, ["8.8.8.8:2"])132 selector._proxy = self.user_proxy133 self.assertTrue(selector.remove_proxy(self.proxy_list[0]))134 self.assertEqual(selector._proxy, self.user_proxy)135 self.assertEqual(selector._proxy_list, [])136 self.assertFalse(selector.remove_proxy(self.user_proxy))137 self.assertEqual(selector._proxy, self.user_proxy)138 self.assertEqual(selector._proxy_list, [])139 def test_remove_reset_counter(self):140 selector = ProxySelector()141 selector._proxy_list = ["A", "B", "C"]142 selector._proxy_counter = 1 # Point the counter to 'B'143 selector.remove_proxy("A")144 self.assertEqual(selector._proxy_counter, 0)145 selector._proxy_list = ["A", "B", "C"]146 selector._proxy_counter = 1147 selector.remove_proxy("B")148 self.assertEqual(selector._proxy_counter, 1)149 selector._proxy_list = ["A", "B", "C"]150 selector._proxy_counter = 1151 selector.remove_proxy("C")152 self.assertEqual(selector._proxy_counter, 1)153 selector._proxy_list = ["A", "B", "C"]154 selector._proxy_counter = 0155 selector.remove_proxy("A")156 self.assertEqual(selector._proxy_counter, 0)157@mock.patch.object(ProxySelector, "is_valid_proxy")158@mock.patch("google_translate.selectors.load_from_file")159class TestProxySelectorInit(unittest.TestCase):160 """docstring for TestObjectState"""161 def setUp(self):162 self.proxy_list = [163 "127.0.0.1:3030", # duplicate164 "127.0.0.1:3030", # duplicate165 "127.0.0.1:8080",166 "127.0.0.2:5050",167 "127.0.0.9:1337"168 ]169 self.proxy = "1.1.1.1:8080"...
sender.py
Source: sender.py
...42 return True43 except (ConnectionError,ReadTimeout):44 return False45 46 def remove_proxy(self):47 """48 移é¤ä»£ç49 :return:None50 """51 self.redis = RedisClient()52 self.redis.remove(CLIENT_NAME)53 print('Successfully Removed Proxy')54 55 def set_proxy(self,proxy):56 """57 设置代ç58 :param proxy:代ç59 :return: None60 """61 self.redis = RedisClient()62 if self.redis.set(CLIENT_NAME,proxy):63 print('Successfully Set Proxy',proxy)64 65 def adsl(self):66 """67 æ¨å·ä¸»è¿ç¨68 :return:None69 """70 while True:71 print('ADSL Start, Remove Proxy, Please wait')72 # å°è¿ç¨Redisæ£å表ä¸çæ¬æºå¯¹åºç代ç移é¤ï¼é¿å
æ¨å·æ¶æ¬ä¸»æºçæ®ç代ç被åå°73 try:74 self.remove_proxy()75 except:76 while True:77 (status,output) = subprocess.getstatusoutput(ADSL_BASH)78 if status == 0:79 self.remove_proxy()80 break81 # æ¨å·èæ¬ï¼stopä¹ååstart82 (status,output) = subprocess.getstatusoutput(ADSL_BASH)83 if status == 0:84 print('ADSL Successfully')85 ip = self.get_ip()86 if ip:87 print('Now IP',ip)88 print('Testing Proxy,Please wait')89 proxy = '{ip}:{port}'.format(ip=ip,port=PROXY_PORT)90 print('proxy info:',proxy)91 if self.test_proxy(proxy):92 print('Valid Proxy')93 # 代çæææ¶ï¼æ´æ°Redisæ£å表
...
main.py
Source: main.py
...14 '--proxy=' + proxy_string.strip(),15 '--proxy-type=http',16 ]17 return proxy18def remove_proxy(proxy):19 proxies = open(PROXIES_FILENAME, 'r').readlines()20 proxies.remove(proxy)21 with open(PROXIES_FILENAME, 'w') as proxies_file:22 proxies_file.writelines(proxies)23 print('remove:', proxy)24def target(url, proxy):25 try:26 with Browser('phantomjs', service_args=proxy) as browser:27 try:28 browser.visit(url)29 if not 'Real Academia Española' in browser.html:30 remove_proxy(proxy_string)31 else:32 with open('rae_crawl.txt', 'a') as output:33 output.write(browser.html + '\n')34 except (TimeoutException, WebDriverException) as e:35 remove_proxy(proxy_string)36 except OSError:37 pass38 39while True:40 proxy_string = get_proxy_string()41 proxy = get_proxy(proxy_string)42 p = multiprocessing.Process(target=target, args=(url, proxy))43 p.start()...
Check out the latest blogs from LambdaTest on this topic:
Unit testing is typically software testing within the developer domain. As the QA role expands in DevOps, QAOps, DesignOps, or within an Agile team, QA testers often find themselves creating unit tests. QA testers may create unit tests within the code using a specified unit testing tool, or independently using a variety of methods.
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.
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.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
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!!