Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
Highlighted
RaghunandanJP Valued Contributor.
Valued Contributor.
399 views

Restrict Ending test run when attachment is not added to the test case

Hi All,

We have a requirement where we have to restrict completion of a Manual run if an attachment is not added to to the test case currently being run. We need to alert the user to add the attachment if it isnt added. Can you please share the customization code if this has been done Or please let us know if we can achive this any other way?

Regards,

Raghu

0 Likes
3 Replies
Knowledge Partner
Knowledge Partner

Re: Restrict Ending test run when attachment is not added to the test case

Hi Raghu,

Please wait for other Peers inputs as well. Below are my inputs:

If my understaing is correct , your requirement is that after clicking on "END RUN" button a verification check has to be performed on whether atleat one attachment has been already added to the executed run steps or run, if added stop the run gracefully or else we need to force user to add attachment.

Question: Why do you want to perform this check only when user click on end run?

                 Cant we do it at step level during each run step execution?

For Example:

                 We can add a user field called "Attachment Required" say UDF "ST_USER_01" of type looklist pointed to "Yes/No" list at Step Level.

 "Attachment Required" user field can be set to value "Yes" , for design steps to which attachments has to be added.

During test execution before providing status( Pass/Fail etc ) to each step , we can check for the Value of "Attachment Required" , if attachments are present then no problem you can continue to next step or else we can force the user to add attchment and then change the status of the step.

Here is the sample code I tried:

Sub Step_FieldChange(FieldName)
  On Error Resume Next
     if FieldName="ST_STATUS" and Step_Fields.Field("ST_USER_01").Value = "Y" then
        if not Step_Fields.Field("ST_ATTACHMENT").Value = "Y" then
            temp = ""
            temp = LastValue("ST_STATUS", "Step")
            MsgBox "Operation Prevented! Add attachments to change Step Status", vbExclamation + vbSystemModal
            set objStep = TDConnection.StepFactory.Item(Step_Fields("ST_ID").Value)
            Step_Fields("ST_STATUS").Value = temp
            objStep.Refresh
            'objStep.Post
            'Step_FieldCanChange = False
        end if
   end if

  On Error GoTo 0
End Sub

Code for LastValue function is as below:

Function LastValue(FieldName, Entity)
'This function returns the value of the field before the user changes it.
'FieldName - Name of field for which you are looking
'Entity - Name of the Entity affected
On Error Resume Next

dim com
dim rec
dim td

'If the Entity is a Defect entity
if Entity = "Defects" then
   'If the bug is new then the previous value is Null
    if Bug_Fields("BG_BUG_ID").IsNull then
      LastValue =""
      exit function
   end if
end if

set td = TDConnection
set com = td.Command

'Run SQL query to return the previous value
select case Entity

   case "Requirements"
      com.CommandText = "select " & FieldName & " from REQ where RQ_REQ_ID=" & Req_Fields("RQ_REQ_ID").Value
   case "Test"
      com.CommandText = "select " & FieldName & " from TEST where TS_TEST_ID=" & Test_Fields("TS_TEST_ID").Value
   case "Design Steps"
      com.CommandText = "select " & FieldName & " from DESSTEPS where DS_TEST_ID=" & DesignStep_Fields("DS_TEST_ID").Value & _
   " and DS_STEP_ID=" & DesignStep_Fields("DS_STEP_ID").Value
   case "Test Set"
      com.CommandText = "select " & FieldName & " from CYCLE where CY_CYCLE_ID=" & TestSet_Fields("CY_CYCLE_ID").Value
   case "Test in Test Set"
      com.CommandText = "select " & FieldName & " from TESTCYCL where TC_CYCLE_ID=" & TestSetTest_Fields("TC_CYCLE_ID").Value & _
   " and TC_TEST_ID=" & TestSetTest_Fields("TC_TEST_ID").Value & _
   " and TC_TEST_INSTANCE=" & TestSetTest_Fields("TC_TEST_INSTANCE").Value
   case "Run"
      com.CommandText = "select " & FieldName & " from RUN where RN_RUN_ID=" & Run_Fields("RN_RUN_ID").Value
    case "Steps"
       com.CommandText = "select " & FieldName & " from STEP where ST_RUN_ID=" & Step_Fields("ST_RUN_ID").Value & _
   " and ST_ID=" & Step_Fields("ST_ID").Value
   case "Defects"
      com.CommandText = "select " & FieldName & " from BUG where BG_BUG_ID=" & Bug_Fields("BG_BUG_ID").Value
end select

set rec = com.Execute
rec.First

LastValue = rec.FieldValue(Cstr(FieldName))

set com = nothing
set rec = nothing
On Error GoTo 0
End function

Regards, Srihari

 

0 Likes
RaghunandanJP Valued Contributor.
Valued Contributor.

Re: Restrict Ending test run when attachment is not added to the test case

Hi Srihari,

Thank you for looking into this.

Our requirement is 

1.      If a test step/test case is failed, a defect should always be linked to the test case. Non-compliance of defect attachment, should also not lead to close/end the test case.

2.      Only when all test steps are passed during the Manual Run and user ends the run, there should be a check if an attachment was added to any of the steps. Attachment is not required for each step, it’s required for a test case that has been passed.

We are having difficulties in firts part of the requirement. We have the below code written which is not helping us. Will appreciate if you could give any suggestions here.

Function Step_CanPost

  On Error Resume Next

 

  Step_CanPost=False

  val=Step_Fields("ST_HAS_LINKAGE").value

  msgbox val

if (Step_Fields("ST_HAS_LINKAGE").value="Y" or Step_Fields("ST_STATUS").Value<>"Failed" or  Run_Fields("RN_SUBTYPE_ID").Value <>"MANUAL")    Then

 

      Step_CanPost = True

 

        Elseif(Run_Fields("RN_SUBTYPE_ID").Value="MANUAL" and Step_Fields("ST_STATUS").Value="Failed" and Step_Fields("ST_HAS_LINKAGE").value="N") then

                       msgbox "Defect(s) need to be linked for Failed steps first then change the test step status to failed"

                         Run_Fields("RN_HAS_LINKAGE").IsRequired=true

              Step_CanPost = True

              Run_CanPost = false

 

               End If

  'Step_CanPost = DefaultRes

  On Error GoTo 0

End Function

 

 

0 Likes
RaghunandanJP Valued Contributor.
Valued Contributor.

Re: Restrict Ending test run when attachment is not added to the test case

Hi,

On a further note,

I have the below code added to adress the issues. But, the codes only work when placed indivisually. When i try to add both codes then the code placed first won't work. Do you have any suggestions where we can achive both requirements in a sigle piece of code? 

Function Run_CanPost 
  On Error Resume Next

‘Code to check if attachments are present for all passed test cases.

if Step_Fields("ST_ATTACHMENT").Value="Y" or Run_Fields("RN_ATTACHMENT").Value="Y" or Step_Fields("ST_STATUS").Value<>"Passed" or Run_Fields("RN_SUBTYPE_ID").Value <>"MANUAL"    Then
     Run_CanPost = True
        Else
      msgbox "Please provide an attachment for test run.Attachment is required to proceed with test run"
     Run_CanPost = False
   End If

‘Code for failed test case with linked defect restriction

  if  (Run_Fields("RN_SUBTYPE_ID").Value="MANUAL" and Step_Fields("ST_STATUS").Value="Failed" and Step_Fields("ST_HAS_LINKAGE").value="N") then
   msgbox "Defect(s) need to be linked for Failed steps first then change the test step status to failed"
      Run_Fields("RN_HAS_LINKAGE").IsRequired=true
      Step_CanPost = false
      Run_CanPost = false
Elseif (Step_Fields("ST_HAS_LINKAGE").value="Y" or Step_Fields("ST_STATUS").Value<>"Failed" or  Run_Fields("RN_SUBTYPE_ID").Value <>"MANUAL")    Then
       Run_Fields("RN_HAS_LINKAGE").IsRequired=true
      Run_CanPost = True
      Step_CanPost = True
End If
On Error Goto 0
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.