Skip to content
This repository has been archived by the owner on Nov 18, 2019. It is now read-only.

Example - Setup proxy in Firefox with Marionette driver. #114

Merged
merged 3 commits into from
Jan 12, 2017

Conversation

smatei
Copy link
Contributor

@smatei smatei commented Oct 25, 2016

Hi @lukeis,

As you told me here

SeleniumHQ/selenium#2963

I have marked the old example as deprecated for Marionette and added my new example (only Java). When I have time I will try to write a python one too.

Please tell me if that needs any changes so that the pull request is accepted.

Best Regards,
Stefan Matei

@smatei smatei changed the title Setup proxy in Firefox with Marionette driver. Example - Setup proxy in Firefox with Marionette driver. Oct 25, 2016
@@ -286,11 +286,12 @@ As of this writing it is unknown how to set the proxy programmatically.
.. #literalinclude:: /examples/Chapter4/ruby/ProxySetupChrome.rb
.. :language: ruby

Firefox
Firefox up to version 46
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

47.0.1

also rst is finicky... you need to make the ++++ below match up to the length of the line (we get warnings when building)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, got it!

@@ -304,6 +305,25 @@ that is created on the fly as is shown in the following example.
.. literalinclude:: /examples/Chapter4/ruby/ProxySetupFirefox.rb
:language: ruby

Firefox version 47 and newer - Marionette driver
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

48 and call it GeckoDriver (not marionette driver)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, got it!

+++++++
Firefox maintains its proxy configuration in a profile. You can preset the
proxy in a profile and use that Firefox Profile or you can set it on profile
that is created on the fly as is shown in the following example.
that is created on the fly as is shown in the following example -
deprecated, no longer working with Marionette driver.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Marionette/Gecko

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, got it!

Firefox maintains its proxy configuration in a profile. You can preset the
proxy in a profile and use that Firefox Profile or you can set it on profile
that is created on the fly as is shown in the following example. With
Marionette driver the proxy has to be passed through the required capabilities.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Marionette/Gecko

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, got it!

DesiredCapabilities required = new DesiredCapabilities();
required.setCapability("proxy", json);

driver = new FirefoxDriver(desired, required);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only difference between this and the other is to pass in required capabilities...

So, why don't we just change that example to pass in the 'cap' to both desired and required and just put a comment like this:

// GeckoDriver currently needs the Proxy set in RequiredCapabilities, this will work for both 
// GeckoDriver and Selenium's Firefox extension webdriver.xpi
WebDriver driver = new FirefoxDriver(cap, cap);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @lukeis,

You are right about this, but there is more. This example does not work with the constructor new FirefoxDriver(desired, required). It passes the capabilities through FirefoxDriver.extractProfile, that is calling populateProfile, that is adding "firefoxOptions" to capabilities.

desiredCapabilities=Capabilities [{marionette=true, firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions@10dba097, browserName=firefox, version=, platform=ANY}]...

The response from the other side is

org.openqa.selenium.SessionNotCreatedException: Not all requiredCapabilities could be met: ["[object Object] does not equal undefined"]

It works with the service constructor

FirefoxDriver(GeckoDriverService driverService, Capabilities desiredCapabilities, Capabilities requiredCapabilities)

This does not change the capabilities, and it works.

So I will change the example to

GeckoDriverService service =new GeckoDriverService.Builder() .usingDriverExecutable(new File("path to geckodriver")) .usingAnyFreePort() .usingAnyFreePort() .build(); service.start(); WebDriver driver = new FirefoxDriver(service, cap, cap);

@LordPato
Copy link

@lukeis , is it possible to add something like

json.addProperty("noProxy", noProxy);

I need to ignore some urls from the tests.

Thanks!

@lukeis lukeis merged commit 18672e3 into SeleniumHQ:master Jan 12, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants