Help: Testing using Robot Framework and PhantomJS browser behind a PROXY.

1,664 views
Skip to first unread message

Kevin Tran

unread,
Jun 17, 2013, 10:37:47 AM6/17/13
to robotframe...@googlegroups.com
Hello,
 
I am behind a proxy and I am having trouble trying to run tests using the PhantomJS browser. I was having problems with Firefox before but I created a custom profile with the proper proxy settings and it worked fine. How would I be able to set the proxy settings for the webdriver when opening the PhantomJS browser? Any help would be greatly appreciated. I get the browser to open just fine but I get this page when trying to navigate to any URL.
 
I tried setting desired_capabilities
 
Open Browser  ${URL}  ${BROWSER}  desired_capabilities=proxyType:manual,httpProxy:hostname.com:1234
 
Thank you,
Kevin

Markus Bernhardt

unread,
Jun 17, 2013, 4:09:30 PM6/17/13
to kvnt...@gmail.com, robotframe...@googlegroups.com
Hi Kevin,

I'm not 100% sure, but I think this will not work, because the proxy item is a nested JSON object inside the desired capabilities. Could you please test to set the http_proxy and HTTP_PROXY environment variables. They should be picked up by WebDriver.

Cheers,
Markus

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Kevin Tran

unread,
Jun 17, 2013, 4:44:53 PM6/17/13
to robotframe...@googlegroups.com
I tried doing that and I am still getting the same error. This is the page it goes to.
 

Kevin Tran

unread,
Jun 17, 2013, 4:46:26 PM6/17/13
to robotframe...@googlegroups.com, kvnt...@gmail.com
I used the command: set http_proxy=http://USERNAME:P...@hostname.com:80/

On Monday, June 17, 2013 3:09:30 PM UTC-5, Markus Bernhardt wrote:
Hi Kevin,

I'm not 100% sure, but I think this will not work, because the proxy item is a nested JSON object inside the desired capabilities. Could you please test to set the http_proxy and HTTP_PROXY environment variables. They should be picked up by WebDriver.

Cheers,
Markus
Am 17.06.2013 um 16:37 schrieb Kevin Tran <kvnt...@gmail.com>:

Hello,
 
I am behind a proxy and I am having trouble trying to run tests using the PhantomJS browser. I was having problems with Firefox before but I created a custom profile with the proper proxy settings and it worked fine. How would I be able to set the proxy settings for the webdriver when opening the PhantomJS browser? Any help would be greatly appreciated. I get the browser to open just fine but I get this page when trying to navigate to any URL.
 
I tried setting desired_capabilities
 
Open Browser  ${URL}  ${BROWSER}  desired_capabilities=proxyType:manual,httpProxy:hostname.com:1234
 
Thank you,
Kevin

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

Kevin Tran

unread,
Jun 20, 2013, 12:10:17 PM6/20/13
to robotframe...@googlegroups.com, kvnt...@gmail.com
I still have not been able to fix this problem. Please help. I need to be able to test UI at work.

Kevin O.

unread,
Jun 20, 2013, 4:06:11 PM6/20/13
to robotframe...@googlegroups.com, kvnt...@gmail.com
Supporting the proxy via DesiredCapabilities is marked TODO. Also setting the command line arguments via DesiredCapabilities (phantomjs.cli.args) is only implemented in the Java bindings. The only way currently to set the proxy AFAIK is via the command line.
You can either launch phantomjs outside of Selenium2Library and use the remote_url to connect to it or you can get your hands a little dirty and make a custom library. Writing your own keyword allows you to expose some browser-specific arguments that are not exposed by Open Browser.  The custom library approach is demonstrated below (it worked for me phantomJS 1.9.1/RF 2.8.1/Se 1.2/Py 2.7/Win7):

*** Settings ***
Library           Selenium2Library
Library           Se2LibExtensions.py

*** Test Cases ***
PhantomJS Proxy
    ${service args}=    Create List    --proxy=192.168.132.104:8888
    Open Phantomjs    http://www.google.com/    service_args=${service args}
    [Teardown]    Close All Browsers


# contents of Se2LibExtensions.py
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from robot.libraries.BuiltIn import BuiltIn
from robot.api import logger
    
class Se2LibExtensions(object):

    def open_phantomjs(self, url, alias=None, service_args=None, desired_capabilities=DesiredCapabilities.PHANTOMJS, service_log_path=None, executable_path="phantomjs", port=0):
        """Open the PhantomJS browser to the given `url`."""
        s2l = BuiltIn().get_library_instance('Selenium2Library')
        browser = webdriver.PhantomJS(service_args=service_args, desired_capabilities=desired_capabilities, service_log_path=service_log_path, executable_path=executable_path, port=port)
        browser.get(url)
        logger.debug('Opened browser with session id %s'
                    % browser.session_id)
        return s2l._cache.register(browser, alias)
Reply all
Reply to author
Forward
0 new messages