qtphp-uft

Cannot find the "agentName" object's parent "Micro Focus MyFlight Sample" when iterating over datatable


So im new UFT and i was trying to record an application which is the Micro Focus MyFlight Sample Application and run a test , well at the start everything worked fine with simple Values. Now i wanted to run test on multiple values using datatable and it passes the Test Iteration: Row 1 but crashs in Test Iteration: Row 2 and return an error. here is my code

WpfWindow("Micro Focus MyFlight Sample").WpfEdit("agentName").Set "john"
WpfWindow("Micro Focus MyFlight Sample").WpfEdit("password").SetSecure "63a57b9fda739663f7d7"
WpfWindow("Micro Focus MyFlight Sample").WpfButton("OK").Click
WpfWindow("Micro Focus MyFlight Sample").WpfComboBox("fromCity").Select "Paris"
WpfWindow("Micro Focus MyFlight Sample").WpfComboBox("toCity").Select "Zurich"
WpfWindow("Micro Focus MyFlight Sample").WpfButton("FIND FLIGHTS").Click
WpfWindow("Micro Focus MyFlight Sample").WpfTable("flightsDataGrid").SelectCell 0,3
WpfWindow("Micro Focus MyFlight Sample").WpfButton("SELECT FLIGHT").Click
WpfWindow("Micro Focus MyFlight Sample").WpfEdit("passengerName").Set DataTable("Passenger", dtGlobalSheet)
WpfWindow("Micro Focus MyFlight Sample").Close

after the first iteration it crashs in the 2nd iteration returning this error

Cannot find the "agentName" object's parent "Micro Focus MyFlight Sample" (class WpfWindow).
Verify that parent properties match an object currently displayed in your application.
Line (3): "WpfWindow("Micro Focus MyFlight Sample").WpfEdit("agentName").Set "john"". 

i tried removing

WpfWindow("Micro Focus MyFlight Sample").Close

i also tried adding this at the first line of the script

WpfWindow("Micro Focus MyFlight Sample").Activate

but nothing seems to work , how can i fix this


Solution

  • Is that all your code or is there any more to share?

    Your first line, with agentName

    WpfWindow("Micro Focus MyFlight Sample").WpfEdit("agentName").Set  "john"
    

    Is the username field on the login prompt. It's attempting to enter "john" in the agent name field.

    Your error tells you: Cannot find the ".." object's parent "..." - the object's parent is missing. i.e. the window object. You are right, it can't find the window because you're closing it.

    The easiest solution to achieve what you're trying to do is to tell UFT to open the application at the start of the test iteration.

    1. IF you've set the record and run settings to open the application when pressing run, please remove this. Do not use the run from menu options as it hides what your code is doing and (like this issue) stops you seeing what's really happening.
    2. Instead, sdd this line to the start of your script:
    systemUtil.run "c:\path\to\flight.exe" '(obviously update the path)