Site icon Vinsguru

Best Practices – Inspecting Selenium Tests Code Quality Using SonarQube

Overview:

In the good old days, automation scripts were mostly record and playback! That was because most of the people who were doing automation were manual testers turned into automation engineers. It was rare to see a a good framework for automated testing. Now situation is completely different. Thanks to DevOps process – everyone understands the importance of automated testing. Nowadays, automation engineers use most of the tools available for Dev/SysAdmin to improve the QA process. We use Jenkins, Git, Docker etc.

We follow all the design principles and patterns for writing our selenium scripts to keep our maintenance effort under control and ensure that our test scripts are following certain standards.

In this article, we are going to take a look at SonarQube – a tool continuously inspects the code we push to GitHub/Version control to ensure that our test script quality is good! Using SonarQube for inspecting our automation scripts brings several advantages. Some of them are listed here.

Setting Up SonarQube:

You can visit the official site and check the install instruction if you do not use Docker. I am going to use Docker! Setting up any tool is now easy with Docker.

version: "3"
 
services:
  sonarqube:
    image: sonarqube:6.7.1
    container_name: sonarqube
    restart: always
    environment:
      - SONARQUBE_JDBC_USERNAME=sonar
      - SONARQUBE_JDBC_PASSWORD=password1
      - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonarqube
    ports:
      - "9000:9000"
      - "9092:9092"
    volumes:
      - sonarqube_conf:/opt/sonarqube/conf
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions
      - sonarqube_bundled-plugins:/opt/sonarqube/lib/bundled-plugins
 
  db:
    image: postgres:10.1
    container_name: db
    restart: always
    environment:
      - POSTGRES_USER=sonar
      - POSTGRES_PASSWORD=password1
      - POSTGRES_DB=sonarqube
    volumes:
      - sonarqube_db:/var/lib/postgresql
      - postgresql_data:/var/lib/postgresql/data
 
volumes:
  postgresql_data:
  sonarqube_bundled-plugins:
  sonarqube_conf:
  sonarqube_data:
  sonarqube_db:
  sonarqube_extensions:
docker-compose up -d

mvn clean compile \ 
   sonar:sonar \
  -Dsonar.host.url=http://10.11.12.13:9000 \
  -Dsonar.login=4f20ed69e698b9039354e73dd3d81c785eb7fa63
  -Dsonar.test.inclusions=**/*Test*/**

 

//itemPrice list should not be empty
Assert.assertFalse(itemPrice.isEmpty());

Summary:

Our selenium test scripts might not go to production! But it ensures that only high quality product is shipped into Production. As our selenium scripts have big responsibility of verifying the code created by developers, It is important for our test scripts to meet industry quality standards 🙂 SonarQube helps us to meet the code quality.

Happy Testing and Subscribe 🙂

 

 

Share This:

Exit mobile version