MachinePublishers / jBrowserDriver

A programmable, embeddable web browser driver compatible with the Selenium WebDriver spec -- headless, WebKit-based, pure Java
Other
809 stars 143 forks source link

Bind to network interface? #262

Closed arya6000 closed 7 years ago

arya6000 commented 7 years ago

Does jBrowserDriver have the ability to bind to a specific network interface? My computer has two NICs and I would like to tell jBrowserDriver which one to use.

hollingsworthd commented 7 years ago

Not currently but it's using Apache HttpComponents which can do that

arya6000 commented 7 years ago

If it's using HttpComponents then it should be easy to implement. Do you think this is something that will get added soon?

hollingsworthd commented 7 years ago

There are a number of higher priority things right now. I think the main work for this would be in https://github.com/MachinePublishers/jBrowserDriver/blob/master/src/com/machinepublishers/jbrowserdriver/StreamConnectionClient.java and https://github.com/MachinePublishers/jBrowserDriver/blob/master/src/com/machinepublishers/jbrowserdriver/Settings.java

arya6000 commented 7 years ago

I did some digging and I think the relevant file would be

https://github.com/MachinePublishers/jBrowserDriver/blob/master/src/com/machinepublishers/jbrowserdriver/StreamConnection.java

Because the bind setting would be passed to "RequestConfig" I will try to implement it and post my progress.

hollingsworthd commented 7 years ago

Makes sense. Would be happy to merge a PR. Let me know if you need anything.

arya6000 commented 7 years ago

I started working on it, I think everything is done but there is only one part of the code which I don't understand. In the Settings class there is a section called

private Settings(Settings.Builder builder, Map properties) {
     .........
    }

I think the above method is responsible for setting the final data members am I right? all the other parts are done. I will try to understand what is going on with the method above.

hollingsworthd commented 7 years ago

That class has become a little unwieldy. Yes, it's taking the mutable properties and making them final.

The complexity in that method is due to the ability to construct a Settings object not just from Settings.Builder but also from Selenium Capabilities and also have System properties control the settings.

Not every setting can be controlled by Capabilities or System properties. It's fine to not handle that part. Thus it could be as simple as this.fooSetting = builder.fooSetting. The typical line in that method looks like this.fooSetting = parse(properties, PropertyName.FOO_SETTING, builder.fooSetting); so that it can pull Selenium Capabilities or System properties out of that properties object.

arya6000 commented 7 years ago

I just tested it and it works flawlessly. Let me know how you want me to give you the changes. I have never used git, but I can learn. Or I can paste the changes here

hollingsworthd commented 7 years ago

Great. Thanks! Can you can go here and "sign" the contributor's license agreement (it's short/simple): https://github.com/MachinePublishers/jBrowserDriver/blob/master/CLA-rev2-digital.txt ... you don't need git for that just click the edit button.

You can use the edit button to change the other files pasting in your version or attaching them to a comment here.

arya6000 commented 7 years ago

I added my name to that file, I will double check everything and post my code soon.

arya6000 commented 7 years ago

I manually edited the files and I added the methods and method calls. Let me know if there are any issues. It's my first time using github.

hollingsworthd commented 7 years ago

Thanks again for contributing this! Note I renamed setLocalIp to localIp. This is now released in v0.17.6 on Maven Central repo.