J'utilise actuellement actionnaz pour automatiser les tests d'un add-on pour Powerpoint que je développe (un peu de pub, c'est ici : http://www.accelplugins.com )
Pour cela, j'ai écrit une petite librairie .acod. Il y a quelques spécificités liées à mon projet, mais ça reste suffisamment générique, je pense, pour être utilisable ailleurs ou pour servir d'exemple
La librairie part du principe que votre projet est organisé comme ceci :
Code: Select all
acDir -Source
+--VERSION
|
+-Release
+-release-v<xxx>-<yyy>
+--tests
Le fichier VERSION contient la version courante avec en ligne 1 la version <xxx> et en ligne 2 le build <yyy>, par exemple:
Code: Select all
2.3
4
la librairie est exécuté à partir d'un script actionaz, un script représentant un test. Le lancement d'une série de tests est une campagne. Une campagne se termine par le script test-lib-final.ascr, qui génère le rapport de fin (minimal pour l'instant!)
Voici le code de la librairie library.acod:
Code: Select all
var acReleaseDir;
var acCampainId;
var acCampainFile = new File();
var failureTest=0 ;
var acCampainFilename;
var acDefaultInstallDir = "C:\\Program Files\\Accelerate\\";
var acPPTExecName= "POWERPNT.EXE";
var currentPPT;
function premiertest() {
Console.print("Salut ! ici la librairie...");
}
function getVersionBuild() {
Stdio.print("Coucou from version build. Dossier de travail : " + acDir);
var vFile = new File();
var buffer = new String();
if (accelVersion == "") {
vFile.open(acDir + "/source/VERSION", File.ReadOnly);
buffer = vFile.readText();
var tempo = buffer.split("\n");
accelVersion = tempo[0].trim();
accelBuild = tempo[1].trim();
}
Console.print("Testing version v" +accelVersion + " b" + accelBuild);
acReleaseDir = acDir + "Release/release-v" + accelVersion + "-" + accelBuild + "/";
}
function buildAcCFileName() {
return "campain-" + acCampainId + ".log";
}
function getValueFile(filename) {
var incFile = new File();
var value
incFile.open(filename,File.ReadWrite|File.Text);
var buf = incFile.readText();
if (buf == "") {
value = 0
} else {
value = parseInt(buf);
}
incFile.close();
return value;
}
function incrementFile(filename) {
var incFile = new File();
var value
value = getValueFile(filename) + 1;
incFile = new File();
incFile.open(filename, File.WriteOnly | File.Truncate | File.Text);
incFile.writeText(value);
incFile.close();
return value;
}
function acLog(mytext) {
Console.print(mytext);
acCampainFile.writeText(mytext +"\n");
}
function acLogTestSuccess(testNumber,text) {
acLog(testNumber+ ", sucess :" + text );
}
function acLogOK(testNumber,text) {
acLog(testNumber+ ", sucess :" + text );
}
function initCampain () {
var nom = acReleaseDir + "tests/CURRENTTEST";
acCampainId = incrementFile(nom);
acCampainFilename = acReleaseDir + "tests/" + buildAcCFileName() ;
acCampainFile.open(acCampainFilename ,File.WriteOnly | File.Truncate | File.Text);
acLog("*** Beginning of campain\n");
acLog("--------------------------------------\n");
}
function initTest(name) {
var nom = acReleaseDir + "tests/CURRENTTEST";
acCampainId = getValueFile(nom);
acCampainFilename = acReleaseDir + "tests/" + buildAcCFileName();
Console.print("Logging into " + acCampainFilename );
acCampainFile.open(acCampainFilename , File.Append | File.Text);
if (name != undefined) acLog("Begin of test <" + name + ">");
}
function statusTest(isOk) {
if (isOk) {
acLog("test is OK");
} else {
failureTest = 1;
acLog("--> Test FAILURE !");
}
}
function closeTest() {
if (!failureTest) statusTest(1);
acLog("End of test");
acLog(" ");
acLog("--------------------------------------\n");
acCampainFile.close();
var filename ;
if (failureTest) {
filename = acReleaseDir + "tests/failcount-" + acCampainId + ".txt";
} else {
filename = acReleaseDir + "tests/successcount-" + acCampainId + ".txt";
}
incrementFile(filename);
}
function closeCampain() {
acLog("*** End of campain");
acCampainFile.close();
var source = acReleaseDir + "tests/" + buildAcCFileName();
var dest= acDir + "source/tests/current.log";
acCampainFile.copy(dest, {noConfirmDialog: true});
}
function displayCampainFile() {
var process = new Process();
var phandle = process.start("c:\\windows\\system32\\notepad.exe",acCampainFilename);
Console.print("process status : " + process.state());
Console.print("process error : " + process.error());
}
function displayCampainStatus() {
var countFail = getValueFile(acReleaseDir + "tests/failcount-" + acCampainId + ".txt");
var countSuccess = getValueFile(acReleaseDir + "tests/successcount-" + acCampainId + ".txt");
var myDialog
var myRet = 0
if (countFail == 0) {
myDialog= new MessageBox({
title: "Campain " + acCampainId + " status...",
icon: MessageBox.Information,
text: "GREAT ! tests in success : " + countSuccess + " and 0 failed.\n Open campain file ?",
buttons: MessageBox.Ok | MessageBox.Cancel
});
} else {
myDialog = new MessageBox({
title: "Campain " + acCampainId + " status...",
icon: MessageBox.Critical,
text: "PROBLEM : tests in success : " + countSuccess + ", " + countFail + " failed.\n Open campain file ?",
buttons: MessageBox.Ok| MessageBox.Cancel
});
}
myDialog.onClosed = function(result) {
if(result == 1024) {
Console.print("coché ok");
myRet = 1;
}
};
myDialog.showModal();
return myRet;
}
function setAccelIniKey(section,key, value) {
var myIni = new IniFile();
var name = acDefaultInstallDir + "Accelerate.ini"
myIni.load(name);
myIni.setSection(section);
myIni.setKeyValue(key,value);
myIni.save();
}
function getAccelIniKey(section,key) {
var myIni = new IniFile();
var name = acDefaultInstallDir + "Accelerate.ini"
myIni.load(name);
myIni.setSection(section);
return myIni.keyValue(key);
}
function getInstalledPPTVersion() {
var reg = new Registry();
var ppPath ;
var ver;
try {
ppPath=reg.openKey(Registry.LocalMachine,"SOFTWARE\\Microsoft\\Office\\12.0\\PowerPoint\\InstallRoot")
ver = "12.0";
} catch (OpenKeyError) {
}
if (ppPath == undefined) {
try {
ppPath=reg.openKey(Registry.LocalMachine,"SOFTWARE\\Microsoft\\Office\\14.0\\PowerPoint\\InstallRoot")
ver = "14.0";
} catch (OpenKeyError) {
;
}
}
return ver;
}
function getPowerpointPath(){
var reg = new Registry();
var ppPath ;
var ret ;
var ver;
ver = getInstalledPPTVersion();
switch (ver) {
case "12.0": {
ppPath=reg.openKey(Registry.LocalMachine,"SOFTWARE\\Microsoft\\Office\\12.0\\PowerPoint\\InstallRoot")
break;
}
case "14.0": {
ppPath=reg.openKey(Registry.LocalMachine,"SOFTWARE\\Microsoft\\Office\\14.0\\PowerPoint\\InstallRoot")
break;
}
}
if (ppPath != undefined) {
ret = ppPath.value("Path").toString() ;
// problem with last character.. ?
return ret.substr(0,ret.length-1)+ acPPTExecName;
} else {
return "un problème...";
}
}
function launchPP() {
var path = getPowerpointPath();
var okContinue = false;
var comb = 0;
while ((!okContinue) && (comb <= 20)) {
var test = Process.list();
//Console.print("dans la boucle " + comb);
comb++;
okContinue = true;
for (var idx = 1; idx < test.length; idx ++) {
try {
if (test[idx].command().toString().indexOf(acPPTExecName) != -1) {
okContinue = false;
//Console.print("found : " + test[idx].command().toString());
Execution.pause(500);
}
} catch (OpenProcessError) {
continue;
}
}
}
if (comb <= 20) {
currentPPT = Process.startDetached(path);
Execution.pause(2000);
Console.print("Powerpoint Launched");
}
else {
acLog("Timeout - Could'nt launch Powerpoint !");
throw {
name: "System Error",
level: "Show Stopper",
message: "No Powerpoint"
}
}
}
function stopPPT() {
if (typeof(currentPPT) != "undefined") {
currentPPT.kill(ProcessHandle.GracefulThenForceful,5000);
Console.print("Powerpoint stopped");
}
}
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<scriptfile>
<settings program="actionaz" version="3.5.0" scriptVersion="1.0.0" os="Windows"/>
<actions>
<action name="ActionWindow" version="1.0.0"/>
<action name="ActionNoop" version="1.0.0"/>
<action name="ActionEndProcedure" version="1.0.0"/>
<action name="ActionVariable" version="1.0.0"/>
<action name="ActionCode" version="1.0.0"/>
<action name="ActionBeginProcedure" version="1.0.0"/>
<action name="ActionStop" version="1.0.0"/>
</actions>
<parameters>
<parameter name="acDir" code="0" type="0">f:/Accelerate/</parameter>
<parameter name="accelBuild" code="0" type="0"></parameter>
<parameter name="accelVersion" code="0" type="0"></parameter>
</parameters>
<script pauseBefore="400" pauseAfter="0">
<action name="ActionBeginProcedure" comment="------------------------------------- Test en erreur">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
<parameter name="name">
<subParameter name="value" code="0">error</subParameter>
</parameter>
</action>
<action name="ActionWindow" label="error">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
<exception id="32" action="1" line=""/>
<exception id="33" action="1" line=""/>
<parameter name="title">
<subParameter name="value" code="0">Microsoft PowerPoint*</subParameter>
</parameter>
<parameter name="resizeHeight">
<subParameter name="value" code="0">0</subParameter>
</parameter>
<parameter name="action">
<subParameter name="value" code="0">close</subParameter>
</parameter>
<parameter name="movePosition">
<subParameter name="value" code="0">:</subParameter>
</parameter>
<parameter name="useBorders">
<subParameter name="value" code="0">true</subParameter>
</parameter>
<parameter name="resizeWidth">
<subParameter name="value" code="0">0</subParameter>
</parameter>
</action>
<action name="ActionCode" label="110">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
<parameter name="code">
<subParameter name="value" code="1">statusTest(0);
closeTest();</subParameter>
</parameter>
</action>
<action name="ActionStop">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
</action>
<action name="ActionEndProcedure" comment="------------------------------------- Fin Test en erreur">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
</action>
<action name="ActionVariable" comment="------------------------------------ Entrer le nom du test">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
<exception id="32" action="0" line=""/>
<parameter name="colorValue">
<subParameter name="value" code="0">::</subParameter>
</parameter>
<parameter name="variable">
<subParameter name="value" code="0">acTestName</subParameter>
</parameter>
<parameter name="type">
<subParameter name="value" code="0">string</subParameter>
</parameter>
<parameter name="value">
<subParameter name="value" code="0"><Please name me></subParameter>
</parameter>
<parameter name="positionValue">
<subParameter name="value" code="0">:</subParameter>
</parameter>
</action>
<action name="ActionCode" comment="initTest">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
<parameter name="code">
<subParameter name="value" code="1">
Console.print("début");
var ret = include(acDir + "source/tests/integration/library/library.acod");
getVersionBuild();
initTest(acTestName);
</subParameter>
</parameter>
</action>
<action name="ActionCode" comment="Lancement PPT">
<exception id="0" action="0" line=""/>
<exception id="1" action="2" line="error"/>
<exception id="2" action="1" line=""/>
<parameter name="code">
<subParameter name="value" code="1">launchPP();</subParameter>
</parameter>
</action>
<action name="ActionNoop" comment="--------------------- Début du test ---------------------------------">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
</action>
<action name="ActionCode" comment="Fermer PPT">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
<parameter name="code">
<subParameter name="value" code="1">stopPPT()</subParameter>
</parameter>
</action>
<action name="ActionNoop" comment="--------------------- Fin du test ---------------------------------">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
</action>
<action name="ActionCode" comment="closeTest">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
<parameter name="code">
<subParameter name="value" code="1">closeTest();</subParameter>
</parameter>
</action>
</script>
</scriptfile>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<scriptfile>
<settings program="actionaz" version="3.5.0" scriptVersion="1.0.0" os="Windows"/>
<actions>
<action name="ActionNoop" version="1.0.0"/>
<action name="ActionEndProcedure" version="1.0.0"/>
<action name="ActionVariable" version="1.0.0"/>
<action name="ActionCode" version="1.0.0"/>
<action name="ActionDetachedCommand" version="1.0.0"/>
<action name="ActionVariableCondition" version="1.0.0"/>
<action name="ActionConsole" version="1.0.0"/>
<action name="ActionPause" version="1.0.0"/>
<action name="ActionBeginProcedure" version="1.0.0"/>
</actions>
<parameters>
<parameter name="acDir" code="0" type="0">f:/Accelerate/</parameter>
<parameter name="accelBuild" code="0" type="0"></parameter>
<parameter name="accelVersion" code="0" type="0"></parameter>
</parameters>
<script pauseBefore="0" pauseAfter="0">
<action name="ActionBeginProcedure" comment="------------------------------------- displayStatusFile">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
<parameter name="name">
<subParameter name="value" code="0">displayStatusFile</subParameter>
</parameter>
</action>
<action name="ActionDetachedCommand">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
<exception id="32" action="0" line=""/>
<parameter name="processId">
<subParameter name="value" code="0"></subParameter>
</parameter>
<parameter name="parameters">
<subParameter name="value" code="1">acCampainFilename</subParameter>
</parameter>
<parameter name="command">
<subParameter name="value" code="0">C:/WINDOWS/system32/notepad.exe</subParameter>
</parameter>
<parameter name="workingDirectory">
<subParameter name="value" code="0"></subParameter>
</parameter>
</action>
<action name="ActionConsole">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
<parameter name="output">
<subParameter name="value" code="0">information</subParameter>
</parameter>
<parameter name="text">
<subParameter name="value" code="0">on est dans displaystatus</subParameter>
</parameter>
</action>
<action name="ActionEndProcedure">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
</action>
<action name="ActionCode" comment="initTest">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
<parameter name="code">
<subParameter name="value" code="1">
Console.print("début");
var ret = include(acDir + "source/tests/integration/library/library.acod");
getVersionBuild();
initTest();
</subParameter>
</parameter>
</action>
<action name="ActionDetachedCommand" comment="Lancement Powerpoint" enabled="false">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
<exception id="32" action="2" line="100"/>
<parameter name="processId">
<subParameter name="value" code="0"></subParameter>
</parameter>
<parameter name="parameters">
<subParameter name="value" code="0"></subParameter>
</parameter>
<parameter name="command">
<subParameter name="value" code="0">C:/Program Files/Microsoft Office/Office12/POWERPNT.EXE</subParameter>
</parameter>
<parameter name="workingDirectory">
<subParameter name="value" code="0"></subParameter>
</parameter>
</action>
<action name="ActionNoop" comment="--------------------- Début du test ---------------------------------" enabled="false">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
</action>
<action name="ActionPause" comment="ceci est mon test ! " enabled="false">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
<parameter name="duration">
<subParameter name="value" code="0">1</subParameter>
</parameter>
<parameter name="unit">
<subParameter name="value" code="0">seconds</subParameter>
</parameter>
</action>
<action name="ActionNoop" comment="--------------------- Fin du test ---------------------------------" enabled="false">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
</action>
<action name="ActionCode" comment="closeTest">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
<parameter name="code">
<subParameter name="value" code="1">//closeTest();
closeCampain();
</subParameter>
</parameter>
</action>
<action name="ActionVariable" comment="displayStatus">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
<exception id="32" action="0" line=""/>
<parameter name="colorValue">
<subParameter name="value" code="0">::</subParameter>
</parameter>
<parameter name="variable">
<subParameter name="value" code="0">displayStatus</subParameter>
</parameter>
<parameter name="positionValue">
<subParameter name="value" code="0">:</subParameter>
</parameter>
<parameter name="value">
<subParameter name="value" code="1">displayCampainStatus()</subParameter>
</parameter>
<parameter name="type">
<subParameter name="value" code="0">integer</subParameter>
</parameter>
</action>
<action name="ActionVariableCondition" comment="si displayStatus = 1 afficher le status">
<exception id="0" action="0" line=""/>
<exception id="1" action="0" line=""/>
<exception id="2" action="1" line=""/>
<parameter name="ifEqual">
<subParameter name="line" code="0">displayStatusFile</subParameter>
<subParameter name="action" code="0">call_procedure</subParameter>
</parameter>
<parameter name="comparison">
<subParameter name="value" code="0">equal</subParameter>
</parameter>
<parameter name="variable">
<subParameter name="value" code="0">displayStatus</subParameter>
</parameter>
<parameter name="ifDifferent">
<subParameter name="line" code="0"></subParameter>
<subParameter name="action" code="0">do_nothing</subParameter>
</parameter>
<parameter name="value">
<subParameter name="value" code="0">1</subParameter>
</parameter>
</action>
</script>
</scriptfile>
Code: Select all
@ECHO OFF
REM Lancement des tests
set AC_REP=C:\Program Files\Actionaz
set AC_EXEC=actexec.exe
echo running test1...
start /WAIT %AC_EXEC% .\scripts\<montest 1>.ascr
echo running test2...
start /WAIT %AC_EXEC% .\scripts\<montest 2>.ascr
...
echo finalizing...
start /WAIT %AC_EXEC% .\scripts\test-lib-final.ascr