
PyTest+Selenium for automated testing? Don't let IP blocking become a roadblock
Recently, a lot of test guys complained to me that using PyTest+Selenium to do automation testing always encounters IP blocking. Especially when testing the pricing strategy of an e-commerce site or a ticket system, the script will be blocked just half an hour after running. At this time, we have to offer our killer app - theProxy IP ServiceHere crack recommended to use ipipgo home services, their dynamic IP pool is large enough, pro-test can carry high concurrency test.
Why are your test scripts always recognized?
Many newbies think that as long as you use Selenium to simulate the browser operation, everything will be fine, in fact, now the site's anti-climbing mechanism of the thief fine. They will catch you through these features:
- High frequency visits from the same IP (e.g. 50 requests in 1 minute)
- Browser fingerprinting anomalies (missing mouse tracks and such)
- Traces of automation tools hidden in request headers
At this time with ipipgo's proxy IP is like giving the script to wear a cloak of invisibility, each request for a new IP, the site simply can not distinguish between a real person or a robot.
Hands-on with Selenium Vests
Add this configuration to pytest's conftest.py file, and remember to replace the account password with the one you got from the ipipgo backend:
def chrome_options(): options = webdriver.ChromeOptions()
options = webdriver.ChromeOptions()
proxy = "http://用户名:密码@gateway.ipipgo.com:9020"
options.add_argument(f'--proxy-server={proxy}')
return options
Here's a pitfall to be aware of: ipipgo's proxy address should be selectedLong-lasting session typeOtherwise, a sudden disconnection during the test would cause the car to roll over. Their tech support guy said that this kind of agent can keep disconnecting for up to 30 minutes, which is enough to run most of the test cases.
Real-world pitfall avoidance memo
| take | Recommended Agent Type | Configuration Tips |
|---|---|---|
| Price Monitoring Test | City-level dynamic IP | Automatic IP change every 5 minutes |
| Login Function Test | Dedicated Static IP | Binding the fingerprints of the fixtures |
| stress test | polled IP pool | Setting the 200ms request interval |
A collection of QA's you're sure to encounter
Q: The script runs slower after using a proxy IP?
A:八成是选了低质量的代理服务,ipipgo的BGP线路实测在80ms左右。要是还觉得慢,可以让他们开专属代理ip通道。
Q: How to verify if the proxy IP is effective?
A: add a checkpoint in the test case, use requests.get('http://ip.ipipgo.com') to see if the returned IP is a proxy IP or not
Q: What should I do if my test data is interfered with by website backcrawling?
A: with ipipgo'sBrowser Fingerprint Disguisefunction, which turns details like canvas fingerprints and WebGL parameters into normal user mode
Finally, to tell the truth, don't be greedy for cheap proxy services. I've seen people use free proxies before, but the test data was mixed with fake data from competitors, and the whole project was almost ruined. ipipgo has done a more reliable job in this regard, they have aIP purity testingfunction that automatically filters contaminated IP segments.

