For any action on Git repository for your Selenium Tests, instruct GitHub what to do.
Modern test automation is incomplete without continuous integration. While Jenkins is widely used in enterprise environments, GitHub Actions has become a popular CI/CD solution due to its tight integration with GitHub repositories. In this guide, you will learn how to set up GitHub Actions for Selenium test automation using Maven and TestNG.
What is GitHub Actions?
GitHub Actions is a CI/CD platform provided by GitHub that enables you to automate workflows directly from your repository.
It allows you to:
- Build applications
- Run automated tests
- Deploy applications
- Trigger workflows on events
Why Use GitHub Actions for Selenium?
Without CI/CD:
- Tests run manually
- Feedback is delayed
- Regression risks increase
With GitHub Actions:
- Tests run automatically on every push
- Faster feedback loop
- No external CI tool required
- Tight GitHub integration
GitHub Actions Workflow for Selenium
Code Push / Pull Request ↓ GitHub Repository ↓ GitHub Actions Runner ↓ Maven Build ↓ Selenium Test Suite ↓ Test Reports
Prerequisites
Before setting up GitHub Actions:
- Selenium framework ready (POM + TestNG)
- Maven configured project
- GitHub repository
- Basic understanding of YAML
Step 1: Create GitHub Repository
Push your Selenium project to GitHub:
SeleniumAutomationFramework│├── src├── pom.xml├── testng.xml└── .github/workflows
Step 2: Create GitHub Actions Workflow File
Inside your project, create:
.github/workflows/selenium-tests.yml
Step 3: Define GitHub Actions Workflow
Basic Workflow Example
name: Selenium Test Automationon: push: branches: [ "main" ] pull_request: branches: [ "main" ]jobs: test: runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@v4 - name: Set up Java uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '17' - name: Install Maven Dependencies run: mvn clean install -DskipTests - name: Run Selenium Tests run: mvn test
Step 4: Run Tests Automatically
Once you push code:
- GitHub Actions triggers workflow
- Maven builds project
- Selenium tests execute
- Results are displayed in Actions tab
Step 5: View Execution Results
Navigate to:
- GitHub Repository
- Click Actions tab
- Select workflow run
You will see:
- Passed tests
- Failed tests
- Execution logs
Step 6: Add TestNG Suite Execution
If using TestNG, modify run command:
- name: Run TestNG Suite run: mvn test -DsuiteXmlFile=testng.xml
Step 7: Add Headless Browser Execution
Since GitHub Actions runs in Linux environments, use headless mode.
Chrome Options Example
ChromeOptions options = new ChromeOptions();options.addArguments("--headless");options.addArguments("--disable-gpu");options.addArguments("--no-sandbox");WebDriver driver = new ChromeDriver(options);
Step 8: Store Test Reports (Optional)
You can upload reports as artifacts.
- name: Upload Test Reports uses: actions/upload-artifact@v4 with: name: selenium-reports path: target/surefire-reports
GitHub Actions vs Jenkins
| Feature | Jenkins | GitHub Actions |
|---|---|---|
| Setup | Complex | Simple |
| Maintenance | High | Low |
| Integration | External | Native GitHub |
| Cost | Server required | Free tier available |
| Scalability | High | High |
Real-World Use Cases
GitHub Actions is used for:
- Open-source automation frameworks
- CI validation on pull requests
- Regression testing pipelines
- Smoke test execution
Common Issues in GitHub Actions Selenium
1. Browser Not Launching
Cause:
- Missing Chrome setup
Solution:
- Use headless mode or install Chrome dependencies
2. Tests Failing in CI but Passing Locally
Cause:
- Environment differences
Solution:
- Use stable waits and headless configuration
3. Maven Build Failure
Cause:
- Dependency issues
Solution:
- Run
mvn clean install
4. Timeout Issues
Cause:
- Slow CI environment
Solution:
- Increase explicit wait durations
Best Practices
- Always use headless browser in CI
- Cache Maven dependencies
- Separate test suites (smoke/regression)
- Use parallel execution where possible
- Keep workflows modular
- Store reports as artifacts
- Avoid hard-coded data
GitHub Actions Workflow Strategy
Recommended structure:
Push → Build → Unit Tests → UI Tests → Report → Notification
Why GitHub Actions is Popular for Selenium
- Zero infrastructure setup
- Native GitHub integration
- Easy YAML configuration
- Free for most use cases
- Ideal for modern DevOps workflows
Frequently Asked Questions
Can Selenium run in GitHub Actions?
Yes, using headless browser configuration.
Do I need Jenkins if I use GitHub Actions?
Not necessarily. GitHub Actions can fully replace Jenkins for many use cases.
Is GitHub Actions free?
Yes, within GitHub’s free tier limits.
Can I run parallel Selenium tests?
Yes, using Maven Surefire plugin or TestNG parallel execution.
Why do Selenium tests fail in GitHub Actions?
Usually due to:
- Headless issues
- Timing problems
- Missing dependencies
Conclusion
GitHub Actions provides a modern, lightweight, and powerful way to run Selenium test automation pipelines. It simplifies CI/CD integration by removing the need for external tools while offering seamless GitHub integration.
With GitHub Actions, Selenium frameworks become fully automated, scalable, and production-ready.
This completes your CI/CD automation layer alongside Jenkins, making your framework truly industry-standard.
Related Articles
✓ Jenkins Pipeline for Selenium Tests
✓ Selenium Framework Design
✓ Selenium Grid Explained
✓ Page Object Model in Selenium
✓ Complete Selenium Tutorial
Discover more from Rotebit
Subscribe to get the latest posts sent to your email.
