TestProject Forum
Powered by leading experts in the test automation community

If I run SDK tests from a container, can they find the Docker host's TP agent?

I’d like to add TestProject SDK tests to our automated Jenkins pipeline. Jenkins is running on an Ubuntu server. There would hypothetically be a TestProject agent installed on the server, or in a Docker container running on that server; we haven’t decided yet.

Supposing we used the C# SDK to write the tests, I was thinking of running that pipeline stage using a Docker agent, something like:

        stage('UI Tests') {
            agent {
                docker {
                    image 'mcr.microsoft.com/dotnet/core/sdk:2.2'
                }
            }
            steps {
                sh 'dotnet test --logger "trx;LogFileName=UITestResults.trx" "tests/MyService.Tests.Ui/MyService.Tests.Ui.csproj"'
            }

I haven’t tried this yet, but I wanted to ask first: if we run the SDK tests using that Docker agent (so that the tests could have the proper .NET Core execution environment), would the tests be able to “find” the TestProject agent installed on the Ubuntu host?

Hi, yes it will. here is the link that explains how to do it, please let us know if more clarifications are needed https://docs.testproject.io/testproject-sdk/using-testproject-scripted-tests-within-ci-cd#c-test-example

In the linked example, the C# code is running directly in the Jenkins host - using the following agent declaration: agent { label 'master' }.

In my hypothetical example, the C# code would itself be running in a container. So I’m asking if that makes a difference in whether the C# code would be able to find the TestProject agent in that case.

What I’m really getting at here, which I did not find in the TestProject documentation is how exactly the SDK code looks for a TestProject agent. If I understood that, I could probably answer my own question.

Ok - I finally did find the relevant bit of the documentation. I think this snippet from the docs on Python SDK answers my question:

By default, drivers communicate with the local Agent listening on http://localhost:8585. This value can be overridden by setting the TP_AGENT_URL environment variable to the correct Agent address.

NOTE: I’m assuming it’s not just the Python SDKs but all SDKs that find the agent this way…

So: this means that as long as the Docker Jenkins agent can access the host’s 8585 port, then the SDK tests running in that Docker Jenkins agent can find the local TestProject agent.

And I think that is doable according to the Docker docs.

Hi @zblocker

You are right, you can either set the TP_AGENT_URL environemnt variable or specify the URL of the Agent in the driver’s constructor first argument - URL.

Note that on the contrary to Selenium/Appium drivers constructors, this URL parameter is for the Agent’s API and not the Selenium/Appium server URL.

Also, your Agent docker will require additional configuration as described here: https://hub.docker.com/r/testproject/agent in the TestProject SDK and Docker Agent section to allow the SDK running in your Jenkins container to communicate with the Agent.

1 Like

Very very helpful, thank you!