How to use remove_proxy method in Airtest

Best Python code snippet using Airtest

test_proxy_selector.py

Source:test_proxy_selector.py Github

copy

Full Screen

...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"...

Full Screen

Full Screen

sender.py

Source:sender.py Github

copy

Full Screen

...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散列表
...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...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()...

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 Airtest 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