I'm trying to add headers into my HTTP
request for a particular test case. That's very important since I'm trying to test an application meant to be used in mobile phones. I manage to find out about the method addCustomRequestHeader(String arg0, String arg1)
. Unfortunately, it seems I don't know how to use it properly.
This is my Test Suite:
package testscripts;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;
import com.thoughtworks.selenium.Selenium;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TCNewspapers extends SeleneseTestCase {
//Local parameters
private static final String SELENIUM_SERVER_HOST = "localhost";
private static final int SELENIUM_SERVER_PORT = 4444;
private static final String NAVIGATOR = "*firefox";
private String URL = "http://www.marca.com/";
Selenium selenium;
@Before
public void setUp() throws Exception {
super.setUp();
selenium = new DefaultSelenium(SELENIUM_SERVER_HOST,
SELENIUM_SERVER_PORT,
NAVIGATOR,
URL);
setUp(URL, NAVIGATOR);
//selenium.start();
selenium.start("addCustomRequestHeader=true");
//selenium.start("captureNetworkTraffic=true, addCustomRequestHeader=true");
Thread.sleep(5000);
selenium.windowMaximize();
}
@Test
public void testOpenMarcaMobilePage() {
selenium.addCustomRequestHeader("user-agent", "Mozilla/5.0 (iPhone;");
selenium.open(URL);
selenium.waitForPageToLoad("300000");
verifyTrue(selenium.isTextPresent("Golf"));
}
@After
public void stopClient () throws Exception {
selenium.stop();
}
}
The test case is passing, althoug the "Golf" string should not appear in the mobile version of the page. When checking the navigator I see that I'm not in the mobile version.
Also, I'm getting this WARNING:
WARNING: getString(addCustomRequestHeader) saw a bad result OK
The documentation of addCustomRequestHeader
method says:
This only works if the browser is configured to use the built in Selenium proxy
I guess that's the problem. Any idea of how can I do this?