简体   繁体   中英

Running automated Selenium web driver UI tests using JAVA in Azure Devops CI/CD pipelines

I have a JAVA spring boot application. I have JUnit unit tests and functional tests using Selenium Web Driver in the same project. I want to automate these tests in Azure DevOps pipelines.

What I have done so far is: Setup a Maven task in build pipeline to automate the unit tests.

Problem statement: How do I setup the Selenium UI tests in Release pipeline.

The Microsoft documentation talks about VsTest task. But this task is not supported for Java projects. What am I missing?

Problem statement: How do I setup the Selenium UI tests in Release pipeline.

You can still use Maven task to run the Selenium UI Tests in release pipeline. There's no task available to achieve what you want directly. But as one workaround, you can consider use Copy task and Publish Build Artifacts task in your build, and then use the second Maven task to run those Selenium UI Tests.

You may get useful info from this similar issue .

All you need in Azure DevOps Pipeline is Maven Task. Make sure you have all dependencies and plugins added in your pom.xml .

For a specific Test class edit Goal(s) in Maven Task:

package -Dtest=NAMEOFYOURTESTCLASS test -f pom.xml

Before you create a pipeline you can test it out in your studio. In IntelliJ IDEA you can create a Run Configuration and paste the same command above in the command line section.

Also, this Article is explaining very nice how to setup Maven Project correctly.

In the Release pipeline, you can use bash script task to perform selenium UI automation testing with headless chrome .

1) First, install the chrome browser and web driver in a build or release agent . You can use Microsoft hosted agents or self-hosted agents. All your pipelines need at least one agent to complete the job.

2) Clone the functional test repository from source control.

3) Run MVN test command

Make sure you have the same version of the chrome web driver and chrome web browser installed on the build agent.

The following property will be required to run the functional tests in headless mode.

ChromeOptions options = new ChromeOptions();
options.addArguments("headless");

And add path to web driver,

System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");

Here you can follow the sample script for Azure pipeline bash task

apt-get update
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install
wget https://chromedriver.storage.googleapis.com/84.0.4147.30/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/bin/chromedriver
sudo chmod +x /usr/bin/chromedriver
git clone https://repo_url/functionalTests
cd functionalTests
mvn test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM