0

I use a Maven project:

    <dependency>
        <groupId>net.lightbody.bmp</groupId>
        <artifactId>browsermob-core</artifactId>
        <version>2.1.5</version>
    </dependency>

I want go to html site with different user (by headers).

example:

  • 1: get home page with header user:foo
  • 2: get home page with header user:bar
  • 3: get home page with header user:goo

I try with this code but my chrome is open with a white page only:

Here is my code

    import org.junit.After;
    import org.junit.Assert;
    import org.junit.Before;
    import org.junit.Test;
    import org.openqa.selenium.By;
    import org.openqa.selenium.Proxy;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    import org.openqa.selenium.remote.CapabilityType;

    import net.lightbody.bmp.BrowserMobProxy;
    import net.lightbody.bmp.BrowserMobProxyServer;
    import net.lightbody.bmp.client.ClientUtil;

    public class Sof {

        WebDriver driver;

        @Before
        public void setUp() {

            // start the proxy
            BrowserMobProxy proxy = new BrowserMobProxyServer();

            // put our custom header to each request
            proxy.addRequestFilter((request, contents, messageInfo) -> {
                request.headers().add("my-test-header", "my-test-value");
                System.out.println("addRequestFilter: " + request.headers().entries().toString());
                return null;
            });

            proxy.start();

            // get the Selenium proxy object
            Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);

            // Setting up Proxy for chrome
            ChromeOptions opts = new ChromeOptions();
            opts.setCapability(CapabilityType.PROXY, seleniumProxy);
            System.setProperty("webdriver.chrome.driver", "robot\\src\\test\\resources\\drivers\\windows\\googlechrome\\64bit\\chromedriver.exe");
            driver = new ChromeDriver(opts);
        }

        @Test
        public void testProxifying() {
            driver.get("https://noraui.github.io/demo/logogame/v1/");
            Assert.assertEquals(driver.findElement(By.xpath("//body")).getText(), "{\"SUCCESS\"}");
        }

        @After
        public void tearDown() {
            if (driver != null) {
                driver.quit();
                System.out.println("Driver was instantiated. Quitting..");
            } else {
                System.out.println("Driver was null so nothing to do");
            }
        }

    }

My result is: enter image description here

supputuri
  • 13,644
  • 2
  • 21
  • 39
Stéphane GRILLON
  • 11,140
  • 10
  • 85
  • 154

0 Answers0