aerokube / selenoid

Selenium Hub successor running browsers within containers. Scalable, immutable, self hosted Selenium-Grid on any platform with single binary.
https://aerokube.com/selenoid/latest/
Apache License 2.0
2.6k stars 324 forks source link

How to connect selenoid browser with proxy when the tests are executed on CI instance I don't control #1044

Closed AnatoliiHanziuk closed 8 months ago

AnatoliiHanziuk commented 3 years ago

It's not an issue but a question on how to connect Selenoid and Selenide and proxy running on remote hosts.

I have the setup where the tests are executed as a part of AWS CodePipeline during the CodeBuild stage. It means that I don't control the instances where the execution on CodeBuild step happens and I cannot adjust the network settings there. Tests are executed inside the Docker container.
I use Selenide to start the proxy server and specify these properties

Configuration.proxyEnabled = true;
// GGR and multiple Selenoid instances are inside of the same AWS account in the same region as the CodePipeline is executed in.
Configuration.remote = <ggrHost>;
Configuration.proxyHost = ???;

I want the responses sent by the server of my application to be intercepted and overridden by the proxy to see the same pre-defined data in the browser during each execution of the test.
The browser should be able to access the host with the proxy to receive stubbed responses.

Which value do I need to specify for the Configuration.proxyHost in this setup?

If I specify, for example, InetAddress.getLocalHost().getHostAddress(); or new NetweorkUtils().getNotLoopbackAddressOfThisMachine() I receive The site cannot be reached. ERR_TIMED_OUT error in the browser. So it looks like the browser is trying to connect the proxy server to pass the command through it but it doesn't have access to proxy.

vania-pooh commented 3 years ago

@AnatoliiHanziuk I would suggest using Chrome Developer Tools Protocol to mock responses inside the browser. https://github.com/aerokube/chrome-developer-tools-protocol-java-example/blob/master/src/test/java/com/aerokube/selenoid/ChromeDevtoolsTest.java#L171

AnatoliiHanziuk commented 3 years ago

@vania-pooh , it's a good idea I also had in my mind but in this case I'm limiting the selection of the browsers. At least until Firefox adds the suport of CDP. Also proposed solution works quite well if everything is on localhost. In case of the remote execution the problem is similar - you need to know the address of the browser in advance to initiate web socket session.

I thought that the problem I have should be quite common (people execute their tests on CircleCI, TravicCI, GitlabCI, etc) and there should be an easy way to establish visibility between the place of the test execution, proxy and browser in Selenoid container started on the different host.

vania-pooh commented 3 years ago

@AnatoliiHanziuk I would ask in Selenide support then.

github-actions[bot] commented 9 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.