Create README.md

This commit is contained in:
Ssyleric
2025-11-20 14:09:18 +01:00
committed by GitHub
parent e53169a88c
commit 05981e1620

250
README.md Normal file
View File

@@ -0,0 +1,250 @@
# Robot Framework + Jenkins + Chrome headless (LXC)
Ce projet contient des tests Robot Framework (FrontOffice, BackOffice, End-to-End)
exécutés en **mode headless dans un conteneur LXC Jenkins**.
Lobjectif :
✅ Lancer les tests depuis Jenkins
✅ Utiliser Google Chrome en headless, compatible LXC
✅ Générer les rapports Robot (log.html, report.html)
✅ Pouvoir les visualiser dans Jenkins
---
## 1. Contexte dexécution
- **Machine** : LXC `jenkins` sur Proxmox
- **OS** : Debian 13
- **Jenkins** : installé dans le LXC
- **Chrome** :
```bash
google-chrome --version
# Google Chrome 142.0.7444.162
```
- **Chromedriver** (installé manuellement et/ou via Selenium Manager) :
```bash
CD_VERSION="142.0.7444.162"
cd /tmp
curl -LO "https://storage.googleapis.com/chrome-for-testing-public/${CD_VERSION}/linux64/chromedriver-linux64.zip"
unzip -o chromedriver-linux64.zip
install -m 755 chromedriver-linux64/chromedriver /usr/local/bin/chromedriver-142
ln -sf /usr/local/bin/chromedriver-142 /usr/local/bin/chromedriver
chromedriver --version
# ChromeDriver 142.0.7444.162 ...
```
---
## 2. Structure du projet
Dans le repo `end-to-end` :
```text
.
├── Data
│ └── InputData.robot
├── Resources
│ ├── BackOffice
│ │ ├── BackOfficeApp.robot
│ │ └── PO
│ │ ├── BackOffice.Landing.robot
│ │ └── BackOffice.TopNav.robot
│ ├── Common
│ │ └── CommonWeb.robot <-- config Selenium / Chrome headless
│ └── FrontOffice
│ ├── FrontOfficeApp.robot
│ └── PO
│ ├── About.robot
│ ├── Contact.robot
│ ├── FrontOffice.Landing.robot
│ ├── Portofolio.robot
│ ├── Services.robot
│ └── Team.robot
├── results
│ ├── log.html
│ ├── output.xml
│ └── report.html
└── Tests
├── BackOffice
│ └── Back_Office.robot
├── EndToEnd
│ └── End_to_End.robot
└── FrontOffice
└── Front_Office.robot
```
---
## 3. Configuration Selenium `Resources/Common/CommonWeb.robot`
Cest ici que tout se joue pour lexécution dans Jenkins + LXC.
```robot
*** Settings ***
Library SeleniumLibrary
Resource ../BackOffice/BackOfficeApp.robot
Resource ../FrontOffice/FrontOfficeApp.robot
*** Variables ***
${BROWSER} chrome
${CHROME OPTIONS} add_argument("--headless=new");add_argument("--disable-dev-shm-usage");add_argument("--no-sandbox");add_argument("--window-size=1920,1080")
*** Keywords ***
Begin Web Test
Open Browser about:blank ${BROWSER} options=${CHROME OPTIONS}
Set Selenium Speed 0.3s
Set Selenium Timeout 7s
End Web Test
Close All Browsers
```
Les fichiers de test appellent ce `Begin Web Test` en `Test Setup` :
### Exemple `Tests/FrontOffice/Front_Office.robot`
```robot
*** Settings ***
Documentation Test the Studio Web Page
Resource ../../Resources/FrontOffice/FrontOfficeApp.robot
Resource ../../Resources/Common/CommonWeb.robot
Resource ../../Data/InputData.robot
Test Setup Begin Web Test
Test Teardown End Web Test
```
Idem pour :
- `Tests/BackOffice/Back_Office.robot`
- `Tests/EndToEnd/End_to_End.robot`
---
## 4. Job Jenkins configuration
Dans Jenkins, le job `end-to-end` :
### 4.1. Source Code Management
- **Git repo** : `https://github.com/Ssyleric/end-to-end.git`
- **Branch** : `master`
- Credentials : token GitHub (déjà configuré).
### 4.2. Build Step `Execute shell`
Script utilisé :
```bash
#!/bin/bash
cd "$WORKSPACE"
# Active le venv Robot (déjà créé à lavance)
# /var/lib/jenkins/venv-robot contient robotframework + SeleniumLibrary
/var/lib/jenkins/venv-robot/bin/python -m robot --outputdir results Tests
```
Résultat en sortie :
```text
Tests | PASS |
Tests.BackOffice | PASS |
Tests.EndToEnd | PASS |
Tests.FrontOffice | PASS |
8 tests, 8 passed, 0 failed
```
Les fichiers générés :
- `${WORKSPACE}/results/output.xml`
- `${WORKSPACE}/results/log.html`
- `${WORKSPACE}/results/report.html`
---
## 5. Plugin Robot Framework dans Jenkins
Le plugin Robot Framework est configuré pour :
- **Directory** : `results`
- **Output XML** : `output.xml`
À la fin du build, Jenkins affiche :
- Longlet **Robot** sur la page du job
- Les statistiques de tests (nombre de tests, tags, suites…)
- Des liens vers `log.html` et `report.html`
---
## 6. Déblocage de laffichage `log.html` dans Jenkins (CSP)
Par défaut, Jenkins applique une politique **CSP** stricte → `log.html` de Robot peut donner :
> Opening Robot Framework log failed...
Solution appliquée (via **Manage Jenkins → Script Console**) :
```groovy
import jenkins.model.Jenkins
System.setProperty(
"hudson.model.DirectoryBrowserSupport.CSP",
"sandbox allow-scripts; default-src 'self' 'unsafe-inline' 'unsafe-eval'; " +
"style-src 'self' 'unsafe-inline'; " +
"script-src 'self' 'unsafe-inline' 'unsafe-eval'; " +
"img-src 'self' data:; connect-src 'self';"
)
println("CSP définitivement assouplie. Rechargez le Log Robot.")
```
Après ça :
- La page `log.html` de Robot souvre correctement.
- Plus de page noire / erreur "Opening Robot Framework log failed".
---
## 7. Workflow Git mise à jour des résultats
Depuis la machine de dev :
```bash
cd ~/development/robot-scripts/end-to-end
# Lancer les tests en local si besoin
# robot -d results Tests
# Vérifier les fichiers modifiés
git status
# Ajouter les fichiers de résultats (si tu veux les versionner)
git add results/log.html results/output.xml results/report.html
# Commit
git commit -m "Update Robot Framework test results"
# Push vers GitHub
git push
```
Jenkins récupère ensuite le commit et relance le job automatiquement
(si configuré avec webhook ou polling).
---
## 8. Résumé
- Chrome 142 + Chromedriver 142 installés dans le LXC Jenkins
- Config Selenium unifiée via `CommonWeb.robot` avec `options=${CHROME OPTIONS}`
- Jenkins exécute `robot --outputdir results Tests` via un venv dédié
- Plugin Robot Framework consomme `results/output.xml`
- CSP Jenkins assouplie pour permettre laffichage de `log.html`
Tout est maintenant vert 🟢 pour le projet `end-to-end` dans Jenkins.