前往: 導覽, 搜尋

Python 呼叫 TestComplete COM元件達到自動執行自動測試的目的

緣起:
既然連 TestComplete 都拿來用了..那就是要開始搞自動測試的說,
既然要搞自動測試就會希望他自動拿最新的程式,然後自動執行
最好還能夠自動報BUG,擺脫人為的因素建立BASE Line 防線,品質從80分起算
下面的範例就是會呼叫 TestComplete 自動載入 ProjectSuit 執行指定Script 裡面的
某個特定的Function,TestComplete 6 有一個BUG那就是 IsRunning() Function 應該要等到目前
所有的動作執行完畢才會return False,但是目前他的作法是只要載入完 Script 就會return False
"可能"會導致下面Function的動作混在一起,必須要自己在寫 monitor 的Function 確定執行下一個 Function
的時機

def ExeCuteFun(sProjectFileName, sProjectName, sUnitName, sRoutineName):
    TCProgID  = "TestComplete.TestCompleteApplication"
    #Creates the application object
    TC = win32com.client.Dispatch(TCProgID)
    # Obtains the integration object
    IntegrationObject = TC.Integration
    # Opens the project
    IntegrationObject.OpenProjectSuite(sProjectFileName)
    # Checks whether the project was opened
    if not IntegrationObject.IsProjectSuiteOpened:
        print "The project suite was not opened."
    #Runs the routine
    IntegrationObject.RunRoutine(sProjectName, sUnitName, sRoutineName)
    print str(IntegrationObject.IsRunning())
    try:
        while IntegrationObject.IsRunning():
            #print ".",
            pass
    except:
        pass
    #使用的方法
    DeskTop = "C:\\Users\\AlarmChang\\Desktop\\work\\TestComplete 6 Projects\\ProjectSuite1\\"
    sProjectFileName = DeskTop + "ProjectSuite1.pjs"
    sProjectName  = "ProjectName"
    sUnitName = "Unite1"
    sRoutineName = "Main"
    ExeCuteFun(sProjectFileName, sProjectName, sUnitName, sRoutineName)