Automazione Web con SeleniumBase, Test E2E e Stealth

SeleniumBase: Automazione Web, Test E2E e Stealth (13K stelle)

Automazione Web con SeleniumBase Browser Automation, End-to-End Testing, and Stealth in one library. Effortlessly handle bot-detection and CAPTCHAs with SeleniumBase CDP Mode. Includes an MCP server, web scraping features, and integrations such as Stealthy Playwright Mode. https://github.com/seleniumbase/SeleniumBase

Here’s a quick example of SeleniumBase’s Pure CDP Mode (fills in some website data and bypasses the CAPTCHA with sb.solve_captcha() if it wasn’t bypassed automatically):

from seleniumbase import sb_cdp

sb = sb_cdp.Chrome() # Launches a stealth browser
sb.goto(“https://www.planetminecraft.com/account”)
sb.type(‘[name=”email”]’, “Test123″)
sb.type(‘[name=”password”]’, “Pass”)
sb.click(“input#autologin”) # Unchecks a checkbox
sb.solve_captcha() # (as backup if not automatic)
sb.assert_element(‘input[name=”login”]’)
sb.assert_element_not_visible(“input[disabled]”)
sb.sleep(1) # (only to slow down the live demo)
sb.quit() # (otherwise quits automatically at end)

SeleniumBase unisce automazione browser, test E2E e funzionalità anti-rilevamento in un unico framework Python basato su Pytest.

1.Installazione rapida:

Installa il pacchetto principale e i driver necessari con un unico comando pip:

pip install seleniumbase

2.Configurazione del primo test:

Crea un file di test ed eredita dalla classe BaseCase per sfruttare i metodi di asserzione e navigazione integrati:

Python

from seleniumbase import BaseCase

class MyTest(BaseCase):
def test_automation(self):
self.open(“https://example.com”)
self.assert_text(“Example Domain”, “h1”)
self.update_text(“#search-input”, “seleniumbase”)

3.Esecuzione in modalità Stealth:

Avvia i test aggirando i sistemi anti-bot e Cloudflare attivando le opzioni di mascheramento:

pytest test_file.py –uc

FunzionalitàVantaggio principaleUndetected Mode (–uc)Bypassa Cloudflare, Akamai e CAPTCHA simulando un utente realeSFS (SeleniumBase Page Object)Struttura i test in modo pulito separando la logica di pagina dai casi di testDriver Manager integratoGestisce automaticamente i download e gli aggiornamenti di ChromeDriver, GeckoDriver e EdgeConfronto visivoCattura schermate e confronta le differenze grafiche tra i test di regressione

L’articolo Automazione Web con SeleniumBase, Test E2E e Stealth proviene da emediaparma.