开发者

Set user-agent in Selenium RC

The main idea of using the Custom Headers in Selenium RC was to add the User-agent and the phone nomber to my HTTP requests. For that purpose, I'm using Selenium Server as a proxy in Firefox (see how-to use addCustomRequestHeader properly)

This is more or less the code I'm using:

@Before
public void setUp() throws Exception {

    setUp(URL, NAVIGATOR);

    selenium.start("addCustomRequestHeader=true");
    Thread.sleep(5000);
    selenium.windowMaximize();
}

@Test
public void testVerifyHomePage() {

    System.out.println("**** testVerifyHomePag开发者_StackOverflow社区e Executing");

    selenium.addCustomRequestHeader("x-Nokia-Msisdn", "525554003650");
    selenium.addCustomRequestHeader("User-Agent","Mozilla/5.0 (iPhone;");

    selenium.open(URL);
    selenium.waitForPageToLoad("30000");

    verifyTextPresentErrorMsg(selenium,"Home Page");

    System.out.println("---- testVerifyHomePage Finished");

}

The x-Nokia-Msisdn is sent correctly but the User-Agent is wrong (it always considers that my User-Agent is Moxilla Firefox and not a mobile phone). I've tried accessing to pages such as YouTube and the mobile version isn't displayed so this means that the User-Agent that I'm sending is not taken into account.

I've search on the internet and I found people with the same issue but no possible solution. What some people suggest is using a particular profile in Firefox + Modify Headers but I don't think this is possible since everytime Selenium starts an instance of Firefox it creates a plain version without addons.

Any suggestions?


Selenium RC : Setting up a Firefox proxy

This was to document setting up proxy arguments inside Firefox with Selenium RC but it describes how to use the Firefox Profile Manager.

Using this, you can invoke Firefox with whatever settings and add-ons you want

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜