-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathtest_examples.py
More file actions
130 lines (96 loc) · 3.53 KB
/
test_examples.py
File metadata and controls
130 lines (96 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import os
from contextlib import contextmanager
from unittest import TestCase, skipIf
import pytest
from retry import retry
def missing_key(*args, **kwargs):
return skipIf(
"ANTICAPTCHA_API_KEY" not in os.environ,
"Missing ANTICAPTCHA_API_KEY environment variable. Unable to connect Anti-captcha.com",
)(*args, **kwargs)
def missing_proxy(*args, **kwargs):
return skipIf("PROXY_URL" not in os.environ, "Missing PROXY_URL environment variable")(*args, **kwargs)
@pytest.mark.e2e
@missing_key
class AntiGateTestCase(TestCase):
@retry(tries=3)
def test_process_antigate(self):
from examples import sync_antigate
solution = sync_antigate.process()
for key in ["url", "domain", "localStorage", "cookies", "fingerprint"]:
self.assertIn(key, solution)
@pytest.mark.e2e
@missing_key
@missing_proxy
class FuncaptchaTestCase(TestCase):
# CI Proxy is unstable.
# Occasionally fails, so I repeat my attempt to have others selected.
@retry(tries=3)
def test_funcaptcha(self):
from examples import sync_funcaptcha_request
self.assertIn("Solved!", sync_funcaptcha_request.process())
@pytest.mark.e2e
@missing_key
class RecaptchaRequestTestCase(TestCase):
# Anticaptcha responds is not fully reliable.
@retry(tries=6)
def test_process(self):
from examples import sync_recaptcha_request
self.assertIn(sync_recaptcha_request.EXPECTED_RESULT, sync_recaptcha_request.process())
@pytest.mark.e2e
@missing_key
@skipIf(True, "Anti-captcha unable to provide required score, but we tests via proxy")
class RecaptchaV3ProxylessTestCase(TestCase):
# Anticaptcha responds is not fully reliable.
@retry(tries=3)
def test_process(self):
from examples import sync_recaptcha3_request
self.assertTrue(sync_recaptcha3_request.process()["success"])
@contextmanager
def open_driver(*args, **kwargs):
from selenium.webdriver import Chrome
driver = Chrome(*args, **kwargs)
try:
yield driver
finally:
driver.quit()
@pytest.mark.e2e
@missing_key
class RecaptchaSeleniumtTestCase(TestCase):
# Anticaptcha responds is not fully reliable.
@retry(tries=6)
def test_process(self):
from selenium.webdriver.chrome.options import Options
from examples import sync_recaptcha_selenium
options = Options()
options.headless = True
options.add_experimental_option("prefs", {"intl.accept_languages": "en_US"})
with open_driver(
options=options,
) as driver:
self.assertIn(sync_recaptcha_selenium.EXPECTED_RESULT, sync_recaptcha_selenium.process(driver))
@pytest.mark.e2e
@missing_key
class TextTestCase(TestCase):
def test_process(self):
from examples import sync_text
self.assertEqual(sync_text.process(sync_text.IMAGE).lower(), sync_text.EXPECTED_RESULT.lower())
@pytest.mark.e2e
@missing_key
@skipIf(True, "We testing via proxy for performance reason.")
class HCaptchaTaskProxylessTestCase(TestCase):
@retry(tries=3)
def test_process(self):
from examples import sync_hcaptcha_request
self.assertIn(sync_hcaptcha_request.EXPECTED_RESULT, sync_hcaptcha_request.process())
@pytest.mark.e2e
@missing_key
@missing_proxy
class HCaptchaTaskTestCase(TestCase):
@retry(tries=3)
def test_process(self):
from examples import sync_hcaptcha_request_proxy
self.assertIn(
"Your request have submitted successfully.",
sync_hcaptcha_request_proxy.process(),
)