lundi 25 mai 2020

Running Test Modules in CANoe Using Python

I developed a Python based CANOE Automation Code, wherein I launch CANOE, Open the Configuration and load the Test Specification and run it.

Now i want to wait till the Test Module execution is completed to note the Verdict. But not sure on how to do it. Any help would be appreciated.

"""Execute XML Test Cases without a pass verdict"""
from time import sleep
import win32com.client as win32
import configparser
import time
from pandas.core.computation.expressions import set_test_mode
import pythoncom


testComplete = False

class TestModuleEvents(object):
    def OnReportGenerated(self,Success, SourceFullName, GeneratedFullName):
        print("Report Generated")
        testComplete = True
    def OnStop(self, value):
        print("Test Module Stopped")
        testComplete = True

    def OnStart(self):
        print("Test Module Started")
        testComplete = True

class TestConfigurationEvents(object):
    def OnStart(self):
        print("Measurement Started")
        testComplete = False

    def OnStop(self):
        print("Measurement Stopped")
        testComplete = True

config = configparser.RawConfigParser()
config.read('usecase02_configuration.properties')
configurationPath = config.get('TESTCONFIGURATION', 'configurationpath')
testspec = config.get('TESTCONFIGURATION', 'testspecification')

CANoe = win32.DispatchEx("CANoe.Application")
CANoe.Open(configurationPath)

testSetup = CANoe.Configuration.TestSetup
testSetup.TestEnvironments.Add(testspec)
test_env = testSetup.TestEnvironments.Item('Test Environment')
test_env = win32.CastTo(test_env, "ITestEnvironment2")


print(report.FullName)

# Get the XML TestModule (type <TSTestModule>) in the test setup
test_module = test_env.TestModules.Item('Tester')
CANoe.Measurement.Start()
sleep(5)   # Sleep because measurement start is not instantaneous

win32.WithEvents(test_module, TestModuleEvents)
test_module.Start()

# sleep(60)

while test_module.Verdict==0:
    time.sleep(1)

# test_module.Stop()
print(test_module.Verdict)

1 commentaire: