Running Selenium Tests from the Delegate

I’ve had some conversations around Test Automation and realized that many companies are looking to have a better test adoption across the teams and have it standartized across their pipelines. The good news: Harness is here to help you in this journey and our delegate can handle your tests! :star_struck:

In the example below you will see how easy is to templatize and run Selenium tests straight from the Delegate.

Selenium is an open-source automated testing framework that use real browsers to validate Web Applications across multiple platforms.

The tests scripts can be written in many different languages like Python, Java and others. The fastest way to create a test script or at least speed up your development cycle is to use a Chrome Extension like Katalon or Selenium IDE that allows you to record a real Webpage navigation and export the scripts.

Selenium allows you to run the tests with the headless mode, this means that no UI is needed, being a perfect case to run it inside the delegate.


Create and apply a profile to your delegate (I’m using a K8s delegate):

apt-get update
apt-get install -y unzip xvfb libxi6 libgconf-2-4 wget python-pip git
pip install -U selenium
pip install -U pytest
pip install -U unittest
mv chromedriver /usr/bin/chromedriver
dpkg -i google-chrome-stable_current_amd64.deb
apt-get -fy install
google-chrome --version && which google-chrome

Create your Selenium tests and store it in a repository like Github. This is a “Hello World” test for Chrome that exemplifies the use of headless mode:

from selenium import webdriver

# ChromeOptions
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox') # required if running as root user. 

# Test
driver = webdriver.Chrome(options=chrome_options)

Templatizing and executing the tests

If you want to reuse the workflow across different services and teams, you can create Workflow variables with the script name, configuration, URL, etc.

To execute your test script, just create a ShellScript step in your workflow, clone your repo and execute the test. In the example below my script is using an environment variable to get the URL to be tested:

export TESTURL=${workflow.variables.URL}
rm -rf harness-selenium
git clone
python harness-selenium/${workflow.variables.TEST_SCRIPT}

Don’t forget to check “Execute on Delegate” and use the correct Delegate selector. Your configuration will look like this:

It’s simple as that. Now you have your Selenium tests standartized and handled by our Delegate!


How were the credentials passed for git clone to work? Is it possible to obtain from git connector configuration?


Hi Asood,

In my case I used a public repository but you can obtain secrets dynamically using ${secrets.getValue(“secret-name”)}

Let me know if you have further questions.


1 Like

Hi luisredda,

I was getting error obtaining the secret dynamically the way you have mentioned but I could obtain it by providing configuration variable at service level. Another observation I found that if I was using the same repo used in terraform provisioner I did not need to clone it in shell script. But I am running into a strange issue where with branch set to be master I do not see specific folder when list files in script. I can see another folder in directory structure but not the one named ‘terratest’. Have you encountered something like this?

Thank You

Hi Arti,

Let’s connect offline to review this further. I’ve sent out the invite for tomorrow. Chat with you soon.