PiratProxies

Automation and testing

Sending Robot Framework traffic through a proxy

Robot Framework tests are written in keywords. Where the proxy goes depends on the library: the Browser library takes it when the browser is opened, and RequestsLibrary takes it when a session is created.

The right proxy type for Robot Framework

Residential proxies suit automation that acts like a visitor, with a sticky session for anything that logs in. For testing your own site from other countries, any plan with the right country works; Residential Lite is the cheapest.

The values to enter in Robot Framework

Every PiratProxies plan comes down to four values: host, port, username and password. Here they are for Residential; your own username and password are on your plan page.

Hostresi.piratproxies.com
HTTP port8080
SOCKS5 port1080
UsernameUSERNAME
Passwordshown on your plan page

There is no separate country or session field: both are part of the username. Your plan page has a generator that writes it, and Targeting and sessions describes each piece.

Setting it up in Robot Framework

  1. With the Browser library, pass proxy to New Browser, with the server, username and password.
  2. With RequestsLibrary, pass a proxies dictionary to Create Session.

Code: Robot Framework through a proxy

Browser library

*** Settings ***
Library    Browser

*** Test Cases ***
Show Exit IP
    New Browser    chromium    proxy={'server': 'http://resi.piratproxies.com:8080', 'username': 'USERNAME', 'password': 'PASSWORD'}
    New Page    https://api.ipify.org
    ${ip}=    Get Text    body
    Log    ${ip}

Put your own login from the plan page in place of USERNAME and PASSWORD. The example calls an IP-check service, so what it prints is the address your request came from.

Should Robot Framework rotate IPs or keep one?

When Robot Framework plays one visitor across several steps, a sticky session keeps the IP address unchanged from start to finish. When every run stands alone, drop the session and each run begins from a new address.

Here is what a sticky username looks like:

USERNAME-country-us-time-600-session-a1b2c3d4

When Robot Framework will not connect

  • SeleniumLibrary drives Chrome through WebDriver, which has no place for a proxy login. Use the Browser library, or a local forwarder.
  • Error 407 means the login was refused. Copy the username and password from your plan page once more, and make sure no space crept in and the username was not cut short.
  • An IP in the wrong country nearly always comes from the username, since the country code lives there. Other fixes.

Robot Framework and proxies: questions

Which PiratProxies plan suits Robot Framework best?

Residential proxies suit automation that acts like a visitor, with a sticky session for anything that logs in. For testing your own site from other countries, any plan with the right country works; Residential Lite is the cheapest.

Words used in this guide: headless browser, rotating proxy, sticky session, proxy authentication.

Robot Framework belongs to its own developers, and PiratProxies has no connection with them; we name it only to say what this guide covers. Follow the rules of the sites you visit and our acceptable use policy.