Skip to content

Commit

Permalink
Cleaned up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Xewdy444 committed Jan 28, 2023
1 parent 5a91039 commit 557e48f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 34 deletions.
16 changes: 4 additions & 12 deletions tests/test_async_recaptchav2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


@pytest.mark.asyncio
@pytest.mark.xfail(raises=RecaptchaRateLimitError)
async def test_solver() -> None:
"""Test the solver with a normal browser."""
async with async_playwright() as playwright:
Expand All @@ -17,15 +18,11 @@ async def test_solver() -> None:
await page.goto("https://www.google.com/recaptcha/api2/demo")

async with recaptchav2.AsyncSolver(page) as solver:
try:
token = await solver.solve_recaptcha()
except RecaptchaRateLimitError:
return

assert token is not None
await solver.solve_recaptcha()


@pytest.mark.asyncio
@pytest.mark.xfail(raises=RecaptchaRateLimitError)
async def test_solver_with_slow_browser() -> None:
"""Test the solver with a slow browser."""
async with async_playwright() as playwright:
Expand All @@ -34,12 +31,7 @@ async def test_solver_with_slow_browser() -> None:
await page.goto("https://www.google.com/recaptcha/api2/demo")

async with recaptchav2.AsyncSolver(page) as solver:
try:
token = await solver.solve_recaptcha()
except RecaptchaRateLimitError:
return

assert token is not None
await solver.solve_recaptcha()


@pytest.mark.asyncio
Expand Down
6 changes: 2 additions & 4 deletions tests/test_async_recaptchav3.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ async def test_solver() -> None:
await page.goto("https://antcpt.com/score_detector/")

async with recaptchav3.AsyncSolver(page) as solver:
token = await solver.solve_recaptcha()
assert token is not None
await solver.solve_recaptcha()


@pytest.mark.asyncio
Expand All @@ -30,8 +29,7 @@ async def test_solver_with_slow_browser() -> None:
await page.goto("https://antcpt.com/score_detector/")

async with recaptchav3.AsyncSolver(page) as solver:
token = await solver.solve_recaptcha()
assert token is not None
await solver.solve_recaptcha()


@pytest.mark.asyncio
Expand Down
16 changes: 4 additions & 12 deletions tests/test_sync_recaptchav2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
)


@pytest.mark.xfail(raises=RecaptchaRateLimitError)
def test_solver() -> None:
"""Test the solver with a normal browser."""
with sync_playwright() as playwright:
Expand All @@ -16,14 +17,10 @@ def test_solver() -> None:
page.goto("https://www.google.com/recaptcha/api2/demo")

with recaptchav2.SyncSolver(page) as solver:
try:
token = solver.solve_recaptcha()
except RecaptchaRateLimitError:
return

assert token is not None
solver.solve_recaptcha()


@pytest.mark.xfail(raises=RecaptchaRateLimitError)
def test_solver_with_slow_browser() -> None:
"""Test the solver with a slow browser."""
with sync_playwright() as playwright:
Expand All @@ -32,12 +29,7 @@ def test_solver_with_slow_browser() -> None:
page.goto("https://www.google.com/recaptcha/api2/demo")

with recaptchav2.SyncSolver(page) as solver:
try:
token = solver.solve_recaptcha()
except RecaptchaRateLimitError:
return

assert token is not None
solver.solve_recaptcha()


def test_recaptcha_not_found() -> None:
Expand Down
14 changes: 8 additions & 6 deletions tests/test_sync_recaptchav3.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def test_solver() -> None:
page.goto("https://antcpt.com/score_detector/")

with recaptchav3.SyncSolver(page) as solver:
token = solver.solve_recaptcha()
assert token is not None
solver.solve_recaptcha()


def test_solver_with_slow_browser() -> None:
Expand All @@ -28,8 +27,7 @@ def test_solver_with_slow_browser() -> None:
page.goto("https://antcpt.com/score_detector/")

with recaptchav3.SyncSolver(page) as solver:
token = solver.solve_recaptcha()
assert token is not None
solver.solve_recaptcha()


def test_recaptcha_not_found() -> None:
Expand All @@ -39,7 +37,9 @@ def test_recaptcha_not_found() -> None:
page = browser.new_page()
page.goto("https://www.google.com/")

with pytest.raises(RecaptchaTimeoutError), recaptchav3.SyncSolver(page, timeout=10) as solver:
with pytest.raises(RecaptchaTimeoutError), recaptchav3.SyncSolver(
page, timeout=10
) as solver:
solver.solve_recaptcha()


Expand All @@ -50,5 +50,7 @@ def test_recaptcha_version_error() -> None:
page = browser.new_page()
page.goto("https://cobra.ehr.com/ESS/Home/Login.aspx")

with pytest.raises(RecaptchaVersionError), recaptchav3.SyncSolver(page) as solver:
with pytest.raises(RecaptchaVersionError), recaptchav3.SyncSolver(
page
) as solver:
solver.solve_recaptcha()

0 comments on commit 557e48f

Please sign in to comment.