07 CI Integrations
Right now, you are the sole ruler of your testing kingdom. You write the code, you press the green “Run” button in your IDE, and you watch the browser pop up on your screen. If it works, you give a thumbs up.
But here is the harsh truth: If a test passes on your laptop but nobody else sees it, did it really pass?
Software isn’t built by one person on one laptop. It’s built by teams. And it runs on servers, not on your gaming PC. “Continuous Integration” (CI) is the industrial revolution of software. It’s the difference between a bespoke tailor hand-stitching a suit (Manual/Local Execution) and a factory assembly line producing thousands of perfect suits automatically (CI Pipelines).
In this module, we are taking your code off “Works on My Machine” Island and sending it to the cloud, where it will run automatically, reliably, and visibly for the entire team.
7.1 Version Control for QA: The Time Machine
Before we can automate the running of tests, we must automate the sharing of code. You cannot email test_script_final_v2.java to your team. You need Git.
7.1.1 Git Workflows: The Parallel Universes
Imagine you are writing a collaborative novel with 10 other authors. If everyone tries to write on Page 1 at the same time, it’s chaos. Git solves this by creating “Parallel Universes” called Branches.
- The “Main” Branch (The Sacred Timeline): This is the version of the code that works. It is the published book. You never mess with this directly.
- The Feature/Bugfix Branch (The Draft): When you want to add a new test, you create a branch:
feature/login-tests. This is your private sandbox. You can break things here, delete files, and experiment. It doesn’t affect the Main branch. - Pull Requests (The Editor’s Review): Once your test works in your sandbox, you don’t just shove it into the Main branch. You open a “Pull Request” (PR). This is you saying to the team: “Hey, I wrote this new chapter. Can you read it and see if it makes sense?”
- Code Review: Your peers check your logic. “Why did you use a hard wait here?” “This selector looks brittle.” This is where quality control happens on the code itself.
- Merge Conflicts (The Collision): Sometimes, two people edit the same sentence at the same time. Git panics and says: “I don’t know which version to keep!” This is a Merge Conflict.
- The Fix: It’s not a technical error; it’s a communication error. You have to manually sit down, look at both versions, and decide which one wins.
7.1.2 .gitignore: The “Do Not Disturb” Sign
When you take a snapshot of your project to send to GitHub, you don’t want to include your trash.
- The Problem: Your automation project generates a lot of junk files every time you run it.
- Compiled Binaries: The
.classor.exefiles. (The server will build these itself). - Test Reports: The HTML files from your last run. These are outdated the moment they are generated.
- System Files: That annoying
.DS_Storefile on Macs. - Secrets: Crucial. Never, ever commit a file with your passwords or API keys.
- Compiled Binaries: The
- The Solution: The
.gitignorefile is a bouncer at the club. You give it a list of names (file patterns), and it stops them from entering the Git repository.- Best Practice: If a file is generated by running the code (reports, logs, binaries), ignore it. If a file is needed to run the code (scripts, configs), commit it.
7.2 Headless Execution: The Ghost Driver
You’ve set up your pipeline. The server is ready to run your tests. But wait—servers are usually Linux machines sitting in a rack in a cold data center. They don’t have monitors. They don’t have a mouse. They don’t have a graphics card.
How does a browser run without a screen?
7.2.1 Running Tests Without a UI
Enter Headless Mode.
- The Metaphor: Imagine driving a car, but you are not sitting in the driver’s seat looking out the window. Instead, you are plugged directly into the car’s computer. You receive data: “Obstacle 10 meters ahead.” You send commands: “Brake.” You don’t see the road, but you navigate it perfectly.
- The Tech: Chrome and Firefox have a “Headless” argument. When you pass this flag (
--headless), the browser launches, renders the DOM (Document Object Model), executes JavaScript, and clicks buttons, all within the computer’s memory. No window ever pops up. - Why use it?
- Speed: Rendering graphics is heavy. Without drawing pixels, tests run 15-30% faster.
- Necessity: CI environments (Linux agents) strictly do not have a GUI (Graphical User Interface). Headless is the only way to run there.
7.2.2 The “Invisible Window” Trap (Resolution Issues)
Here is the most common rookie mistake in CI. Your test works perfectly on your laptop. You push it to Jenkins. It fails. Error: Element ‘Submit Button’ is not clickable.
Why?
- The Explanation: When you open Chrome on your laptop, it usually opens “Maximized” or at a standard resolution (e.g., 1920x1080).
- The Headless Default: When Headless Chrome starts on a server, it often defaults to a tiny, mobile-sized viewport (e.g., 800x600) because it has no monitor to detect.
- The Bug: In that tiny 800x600 window, your website might switch to “Mobile View,” collapsing the menu into a “Hamburger Icon.” Your script is looking for the “Logout” button, but it’s now hidden inside the menu.
- The Fix: Always explicitly set the window size in your Headless configuration.
- Code:
options.addArguments("--window-size=1920,1080"); - Metaphor: Even though the painter is working in the dark, you must tell them the size of the canvas, or they will paint on the floor.
- Code:
7.3 Pipeline Configuration: The Robot Butler
Now we have the code (Git) and the capability to run without a screen (Headless). We need the coordinator. We need the Robot Butler who listens for your command and does the work for you.
This is your CI Tool (Jenkins, GitHub Actions, GitLab CI).
7.3.1 Creating a Job/Workflow (The Recipe)
A pipeline is just a recipe card you hand to the robot. It tells the server exactly what steps to take to bake your software cake.
- The “YAML” File: Most modern CI tools use a YAML file to define the recipe. It usually looks like this:
- Checkout: “Go to GitHub and download the latest code.”
- Setup: “Install Java/Python and the browser drivers.”
- Build: “Compile the code.”
- Test: “Run the command
mvn test.” - Report: “Save the results folder so the human can see it.”
[Image of CI Pipeline Steps Diagram]
- Note: If any step fails (e.g., the code doesn’t compile), the pipeline stops immediately. This is the “Stop the Line” culture. We don’t want to test broken code.
7.3.2 Parameterized Builds (The “Make it Your Way” Menu)
Sometimes you don’t want the standard order. You want customization.
- Hardcoded vs. Parameterized:
- Hardcoded: Your script says
String browser = "Chrome";. To test Firefox, you have to rewrite the code. Bad. - Parameterized: Your script says
String browser = System.getProperty("browser");. Now, the CI pipeline can inject the value from the outside.
- Hardcoded: Your script says
- Usage in CI: You can set up your Jenkins job to have a dropdown menu.
- Choice: “Select Browser: [Chrome, Firefox, Edge]”
- Choice: “Select Environment: [QA, Staging, Prod]”
- Text: “Filter Tags: [@Smoke, @Regression]”
- The Benefit: This empowers Manual Testers and PMs. They don’t need to know how to code. They just go to Jenkins, select “Staging” and “Firefox,” and hit “Build.” You have turned your code into a self-service tool.
7.3.3 Triggers: “When do we eat?”
How often should this robot run?
- Cron Jobs (The Night Watch):
- Concept: Time-based execution. “Run the full Regression Suite every night at 2:00 AM.”
- Why? Regression takes a long time (1-2 hours). We can’t run it during the day because it clogs up the servers. We run it while we sleep. When we wake up, we have a fresh report on the health of the system.
- Syntax:
0 2 * * *(This is “Cron” speak for 2:00 AM).
- Event Triggers (The Bodyguard):
- Concept: Action-based execution. “Run the Smoke Tests every time a developer creates a Pull Request.”
- The “Gatekeeper”: This is the ultimate power of CI. If a developer tries to merge broken code, your tests run automatically on their PR. If the tests fail, GitHub blocks the merge.
- Metaphor: You have installed a metal detector at the entrance of the codebase. No bugs are allowed to carry weapons into the Main branch.
Summary: The Continuous Confidence Cycle
By the end of this module, you are no longer just writing scripts. You are building infrastructure.
- Git keeps your team in sync and safe from overriding each other’s work.
- Headless Mode allows your tests to run anywhere, anytime, without needing a human screen.
- Pipelines turn your tests into a 24/7 guardian that watches the codebase even when you are on holiday.
You have moved from “I hope it works” to “The pipeline says it works.” That is the professional standard.