func StartWebDriverWithProxy(proxy string, port int) (*WebDriverSession, error) {
	driverPath := os.Getenv("CHROMEDRIVER_PATH")
	if driverPath == "" {
		driverPath = "/usr/bin/chromedriver"
	}
	if _, err := os.Stat(driverPath); os.IsNotExist(err) {
		logrus.Panicf("Driver %s does not exist, make sure you installed chrome driver", driverPath)
	}
	service, err := selenium.NewChromeDriverService(driverPath, port)
	if err != nil {
		return nil, err
	}
	browserPath := os.Getenv("BROWSER_PATH")
	if browserPath == "" {
		browserPath = "/usr/bin/chromium-browser"
	}
	if _, err := os.Stat(browserPath); os.IsNotExist(err) {
		logrus.Panicf("Browser %s does not exist, set BROWSER_PATH environment variable to use your own browser or install chromium", driverPath)
	}
	chromeCaps := chrome.Capabilities{
		Path: browserPath,
	}
	chromeCaps.Args = append(chromeCaps.Args, "--ignore-certificate-errors")
	if os.Getenv("HEADLESS") != "" {
		chromeCaps.Args = append(chromeCaps.Args, "--headless")
		chromeCaps.Args = append(chromeCaps.Args, "--no-sandbox")
	}
	if proxy != "" {
		chromeCaps.Args = append(chromeCaps.Args, fmt.Sprintf("--proxy-server=%s", proxy))
	}
	caps := selenium.Capabilities{}
	caps.AddChrome(chromeCaps)
	wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", port))
	if err != nil {
		_ = service.Stop()
		log.Fatal(err)
	}
	return &WebDriverSession{
		service:   service,
		WebDriver: wd,
	}, nil
}
StartWebDriverWithProxy create a selenium session.
package tests
import (
	"context"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"strconv"
	"strings"
	"testing"
	"time"
	"github.com/sirupsen/logrus"
	"github.com/stretchr/testify/require"
	"github.com/tebeka/selenium"
	"github.com/tebeka/selenium/chrome"
)
const defaultChromeDriverPort = "4444"
type WebDriverSession struct {
	service   *selenium.Service
	WebDriver selenium.WebDriver
}
func GetWebDriverPort() int {
	driverPort := os.Getenv("CHROMEDRIVER_PORT")
	if driverPort == "" {
		driverPort = defaultChromeDriverPort
	}
	p, _ := strconv.Atoi(driverPort)
	return p
}