Forum Discussion

ballard123's avatar
ballard123
Occasional Contributor
7 years ago

script assertion - Output the assertion and result to file

Im looking for advice on how I can output a script assertion's asserts result into a csv.

 

I am using

 

testStep.getAssertionList()

 

to get the non script assertions, but against the script assertion it just outputs null but I would like to retrieve the Assertion status from inside the assertion script

 

snippet from assertion script

 

123141 = holder.getNodeValue('//Results/ResultSet/Row['+count+']/182kasff')
             
  
   if (Medium == 'fasfafa')
   {
   
   12312 = holder.getNodeValue('//Results/ResultSet/Row['+count+']/fsafasf')
   purpose = holder.getNodeValue('//Results/ResultSet/Row['+count+']/saffsafsa')
actSecDate = holder.getNodeValue('//Results/ResultSet/Row['+count+']/asffsfsafsa')
 assert actSecDate.toString() == qeqwqfa
  if (purpose == 'fsafsa'){
   
  
   if (12312.toInteger() == 1){
    type = holder.getNodeValue('//Results/ResultSet/Row['+count+']/saffsafsa')
   assert type.toString() == propTestStep.getPropertyValue("qwttqyy").toString()
   

   }
   else if (12312.toInteger() == 3){
    type = holder.getNodeValue('//Results/ResultSet/Row['+count+']/saffsafsa')
    assert type.toString() == propTestStep.getPropertyValue("qwerqwrqw").toString()
    

   }

 

I want to extract the status of each assert and report into a csv.

  • You could define your own assertion list for the scripts.

    For example like this, here you will get a list of true/false values, depending on the result.

     

    def assertionList = []
    assertionList.add(testValues(45, "GB"))
    assertionList.add(testValues(45, 45))
    assertionList.add(testValues(45, 12))
    assertionList.add(testValues(true, "ad"))
    
    log.info assertionList
    
    
    def testValues(valueA, valueB) {
    	try {
    		assert valueA == valueB
    		return true
    	} catch(AssertionError e) {
    		return false
    	}
    }

    The output will look like this: Sat Oct 27 23:06:04 CEST 2018:INFO:[false, true, false, false]

     

    For your script example it could look like this:

     

    if(Medium == 'fasfafa') {
    	12312 = holder.getNodeValue('//Results/ResultSet/Row['+count+']/fsafasf')
    	purpose = holder.getNodeValue('//Results/ResultSet/Row['+count+']/saffsafsa')
    	actSecDate = holder.getNodeValue('//Results/ResultSet/Row['+count+']/asffsfsafsa')
    	assertionList.add(testValues(actSecDate.toString(), qeqwqfa))
    
    	if(purpose == 'fsafsa') {
    		if(12312.toInteger() == 1) {
    			type = holder.getNodeValue('//Results/ResultSet/Row['+count+']/saffsafsa')
    			assertionList.add(testValues(type.toString(), propTestStep.getPropertyValue("qwttqyy").toString()))
    
    		} else if (12312.toInteger() == 3) {
    			type = holder.getNodeValue('//Results/ResultSet/Row['+count+']/saffsafsa')
    			assertionList.add(testValues(type.toString(), propTestStep.getPropertyValue("qwerqwrqw").toString()))
    		}
    	...
    ...
    
    //writeout the assertionList to a csv here