0

Please suggest me how to handle the scenario. Problem is supposed I got an error at statement 2 during execution of the first iteration for Row 1 from excel then how to skip remaining statement and start the execution of statement 1 with excel row 2.

Browser("ABC").Page("ABC").WebEdit("ABC").Set "123"
Dim i
Dim iRow
iRow = datatable.GetRowCount

For i = 1 to iRow

Statement 1- Browser("ABC").Page("").WebEdit("ABC").Set DataTable("DT", dtGlobalSheet)
Statement 2- Browser("ABC").Page("").WebEdit("ABC").Set DataTable("DT", dtGlobalSheet)
Statement 3- Browser("ABC").Page("").WebEdit("ABC").Set DataTable("DT", dtGlobalSheet)
Statement 4- Browser("ABC").Page("").WebEdit("ABC").Set DataTable("DT", dtGlobalSheet)
Statement 5- Browser("ABC").Page("").WebEdit("ABC").Set DataTable("DT", dtGlobalSheet)

datatable.SetNextRow

Next

Excel sheet

Row 1 Row 2 Row 3

Farhana Naaz Ansari
  • 7,524
  • 26
  • 65
  • 105
  • Why not just check the value within the loop and if it's not set correctly just use an `ExitTestIteration` command, which will move onto the next iteration? Recovery scenarios etc seem to be overkill to me – Dave Apr 03 '18 at 14:55

3 Answers3

0

step1) create a new Action with Name "Action2" and put the code from inside for loop

step2) import data to Action2 local data table

step3) create a recovery scenario enable check on every line with recovery function as

     function RecoveryFunction()
         ExitActionIteration
     End function

step4) from Action1 call Action2 with allIterations

  • Hi Chintan,Thanks a lot for reply .I'm beginner in UFT and I'm not able to understand the Steps 3 which you mentioned above.Could you please tell me how I can create a recovery scenario enable check on every line – Devendra Dangi Apr 03 '18 at 10:55
  • goto file->settings then in test settings click on recovery and on recovery page there is a option "Activate recovery Scenario" with a dropdown with values "On Error","On every step" and "Never" , you can you "on error" also if you are not using "on error resume next" – Chintan Vaghasiya Apr 03 '18 at 11:05
  • What I need to choose in post recovery option to move control to next iteration : – Devendra Dangi Apr 03 '18 at 13:41
  • while creating recovery scenario, in post recovery operation select the option "function call" and then add the function that I have describe above. – Chintan Vaghasiya Apr 06 '18 at 03:58
0

Firstly, if your test is set to Run on all rows in File->Settings->Run then you do not require the loop you have in the code - UFT knows it needs to iterate for each row in your data table.

Secondly, all you need is the statement followed by a check on its success and any error handling. IN the event of the error, just exit the test iteration, and UFT will move onto the next one.

My reworked version of your code:

Browser("ABC").Page("ABC").WebEdit("ABC").Set "123" ' sets an initial value

Browser("ABC").Page("").WebEdit("ABC").Set DataTable("DT1", dtGlobalSheet)
If Browser("ABC").Page("").WebEdit("ABC").GetROProperty("value") <> DataTable("DT1", dtGlobalSheet) Then
    ' Handle error popup if it exists
    Browser("ABCError").Page("").WebButton("OK").Click
    ExitTestIteration
End If
Browser("ABC").Page("").WebEdit("CDE").Set DataTable("DT2", dtGlobalSheet)
If Browser("ABC").Page("").WebEdit("CDE").GetROProperty("value") <> DataTable("DT2", dtGlobalSheet) Then
    ' Handle error popup if it exists
    Browser("ABCError").Page("").WebButton("OK").Click
    ExitTestIteration
End If
Browser("ABC").Page("").WebEdit("FGH").Set DataTable("DT3", dtGlobalSheet)
If Browser("ABC").Page("").WebEdit("FGH").GetROProperty("value") <> DataTable("DT3", dtGlobalSheet) Then
    ' Handle error popup if it exists
    Browser("ABCError").Page("").WebButton("OK").Click
    ExitTestIteration
End If
Browser("ABC").Page("").WebEdit("JKL").Set DataTable("DT4", dtGlobalSheet)
If Browser("ABC").Page("").WebEdit("JKL").GetROProperty("value") <> DataTable("DT4", dtGlobalSheet) Then
    ' Handle error popup if it exists
    Browser("ABCError").Page("").WebButton("OK").Click
    ExitTestIteration
End If
Browser("ABC").Page("").WebEdit("MNO").Set DataTable("DT5", dtGlobalSheet)
If Browser("ABC").Page("").WebEdit("MNO").GetROProperty("value") <> DataTable("DT5", dtGlobalSheet) Then
    ' Handle error popup if it exists
    Browser("ABCError").Page("").WebButton("OK").Click
    ExitTestIteration
End If

I have assumed that your repeated setting of Statement 1 etc in the question is supposed to emulate setting a number of different WebEdit text boxes and coded 5 sets as an example. If, as the iteration progresses, any of the text boxes is not set to the specified data table column value (DT1 to DT5 in my example) then the If condition will be satisfied, causing the attempt to handle an error popup (you'd need to amend my guessed code to suit your requirements) followed by the exiting of the test iteration. Exiting the iteration will trigger a new one to be started, so just be sure you handle any error popup before you exit.

If all WebEdits are completed successfully, then UFT will just repeat for all iterations defined in your data table.

Dave
  • 4,328
  • 2
  • 24
  • 33
  • As per above code Supposed I got error for webedit JKL then iteration will be ended and start the new iteration from WebEdit("ABC") but I don't want to start from WebEdit("ABC") as that is login statement.After ended the iteration ,new iteration should start from WebEdit("CDE") .Please let me know how I can start from WebEdit("CDE") after closed the error pop up. – Devendra Dangi Apr 04 '18 at 07:51
  • Yes - that's how iterations work in UFT - you build a repeatable set of actions and call as required. In the above case, you could either add a check to see if the field exists before you try to set it - presumably your login edits won't be there if you're logged in. – Dave Apr 04 '18 at 10:18
0

You need to decide one thing: are you going to use the UFT way of Data-Driven testing or you would do the whole controlling yourself

Option 1 - Do the UFT Way

  1. Tell Uft to interpret the DataTable properly - meaning execute the Test Case as many times as many rows there are in the Global Sheet: File->Settings->Run-> Run on all rows should be checked
  2. Tell UFT that we are in a Datat-Driven mode. At the same page set the Setting; When error occurs during run session to proceed to Next Action Iteration - uft will start the whole thing with the beginning but next line
  3. Add the five statements in Action 1 (That's all, UFT Takes care of the rest)

Option 2 - Do it in your way

  1. Seems like you are already doing. You implement the Loop and iterate over all the lines of the Table
  2. Extract the 5 Statements into a function (and Function Library)
  3. Create a function that calls the previous one in a supervised manner (and Function Library)

PSEUDO-CODE

ACTION1

ForEach row In DataTable.GlobalSheet
    ExecuteStatementsSupervised row
Next


FUNCTION LIBRARY

Function ExecuteStatementsSupervised(row)
    On Error Resume Next
    ExecuteStatements row

    If Err.Number <> 0  Then
        Reporter.ReportEvent  micFail, "OOPS Failed"
    End If
    On Error GoTo 0
End Function


SubExecuteStatements(row)
    Statement1
    Statement2
    ....
    Statement5
End Sub

So in Action1 we iterate over the DataTable, in the Supervisor function we catch the error if anything happens and make sure that the iterations can go on. The real function per se, just executes the steps

Bela Tamas Jozsa
  • 714
  • 5
  • 10