1

这是我的问题:

使用QC10我的 groovy 脚本OK并且能够创建错误:

import org.codehaus.groovy.scriptom.*
import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.*;
import org.apache.log4j.Logger;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

def QC_Summary = context.getProperty("QC_Summary");
def QC_Description = context.getProperty("QC_Description");
def QC_Severity = context.getProperty("QC_Severity");
def QC_RefAnomalie = context.getProperty("QC_RefAnomalie");
def QC_DetectionDate = context.getProperty("QC_DetectionDate");

def tdc = new ActiveXObject ('TDApiOle80.TDConnection')
tdc.InitConnectionEx('http://xxxx:8080/qcbin')
tdc.Login(context.getProperty("QCUserName"), context.getProperty("QCPassword"));
tdc.Connect(context.getProperty("QCDomain"),context.getProperty("QCProject"));

def newDefect= tdc.BugFactory.AddItem("");

newDefect.AutoPost = false;
//newDefect.AssignedTo = "tga"; /*inutile*/
newDefect.DetectedBy = "wdi_testeurs"; /*fixe=test_wdi*/
newDefect.Status = "Transféré";
log.info "QC_Summary : " + QC_Summary;
//newDefect.Summary = QC_Summary;
newDefect._setField("BG_SUMMARY",QC_Summary.toString());

newDefect._setField("BG_DESCRIPTION",QC_Description);
newDefect._setField("BG_SEVERITY",QC_Severity);
newDefect._setField("BG_USER_01",QC_RefAnomalie);
newDefect._setField("BG_USER_02","jira"); /*fixe=jira*/
newDefect._setField("BG_USER_04","jira"); /*fixe=jira*/
newDefect._setField("BG_USER_05","Recette");
newDefect._setField("BG_DETECTION_DATE",QC_DetectionDate);

newDefect.Post();

def AddBug = newDefect.ID;

log.info "AddBug : " + AddBug;

tdc.Disconnect();
tdc = null;

但是现在ALM12,方法BugFactory.AddItem("")不再起作用,发送错误类型的参数之类的错误。我尝试"", 0, -10, System.DBNull.Value作为参数,但它不起作用。

你有什么问题吗?也许使用调度类?


我懂了 :

import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.*;
import org.apache.log4j.Logger;

public static void setIndexedProperty(Dispatch activex, String name, Variant[] indexes, Variant value)
{
    Variant[] variants = new Variant[indexes.length + 1];            
    for(int i=0; i<indexes.length; i++) {
        variants[i] = indexes[i];
    }
    variants[variants.length-1] = value;
    Dispatch.invoke(activex, name, Dispatch.Put, variants, new int[variants.length]);
}

Calendar currentDate = Calendar.getInstance();
SimpleDateFormat formatter =  new SimpleDateFormat("MM/dd/yyyy");
String dateNow = formatter.format(currentDate.getTime());


ActiveXComponent QCObj = null;
QCObj = new ActiveXComponent("TDApiOle80.TDConnection");
Dispatch.call(QCObj,"initConnectionEx","http://xxxxx:8080/qcbin");
Dispatch.call(QCObj,"login","login","password");
Dispatch.call(QCObj,"connect","domain" , "projet");

Dispatch bugF = null;
bugF = Dispatch.call(QCObj ,"bugFactory").toDispatch();
Variant paramVal = new Variant();
paramVal.putNull();

Dispatch theBug = null;
theBug = Dispatch.call(bugF , "AddItem",paramVal).toDispatch();
Dispatch.put(theBug,"Summary","summary");
Dispatch.put(theBug,"status", "Nouveau");
Dispatch.put(theBug,"DetectedBy", "xxxxxx");

List<Variant> parm1 = new ArrayList<Variant>();
parm1.add(new Variant("BG_SEVERITY"));
Variant value1 = new Variant("2-Major");
setIndexedProperty(theBug, "Field", parm1.toArray(new Variant[1]), value1);

List<Variant> parm2 = new ArrayList<Variant>();
parm2.add(new Variant("BG_DETECTION_DATE"));
Variant value2 = new Variant(dateNow);
setIndexedProperty(theBug, "Field", parm2.toArray(new Variant[1]), value2);

List<Variant> parm3 = new ArrayList<Variant>();
parm3.add(new Variant("BG_DESCRIPTION"));
Variant value3 = new Variant("description");
setIndexedProperty(theBug, "Field", parm3.toArray(new Variant[1]), value3);

Dispatch.call(theBug,"Post");

这是 groovy 中的解决方案!

4

0 回答 0