cancel
Showing results for 
Search instead for 
Did you mean: 

lazy loading - objects not yet in memory

SOLVED
Highlighted
Contributor

lazy loading - objects not yet in memory

I am working with an application that uses lazy loading. In one of my tests, I am accessing a row that is visible on a normal monitor. Today I am working on my small laptop and the row is not only not visible, it is not even in memory because the app uses lazy loading to create the objects as they are needed. I can't find a way to scroll before finding the needed row (when I use several of the scroll methods for javascript I get a 'member not found' error. I can't define the row number and then scrollIntoViewIfNeeded because the row doesn't exist to find in the first place so it errors on that (panel(x) could not be found). Suggestions?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

FindChild by itself still won't overcome the lazy-load... that's why my PseudoCode had the PageDown call in a while loop.  I'd re-write your code as follows.

 

function findRow()
{
var Row = 8;
var List = Aliases.pageDispatch.ListDispatchJobs;
var child = List.FindChild("Name", "Panel(" + (Row -1) + ")", 1, true);
while (!child.Exists) {
    List.Keys("[PageDown]");
    child = List.FindChild("Name", "Panel(" + (Row -1) + ")", 1, true);
}
Log.Message(child.contentText);
}

This will check to see if the child exists.  If not, it sends a page down keystroke to scroll the list and then checks again.  When it does exist, it exits the while loop and the child object is now the desired object.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

9 REPLIES 9
Highlighted
Community Hero

I'm assuming "Page Down" as a keystroke will work to navigate downward through the table, correct?  

 

If so, here's what I would do (pseudocode)

 

rowNotFound = true

while (rowNotFound) {

    If (rowTextExistsOnScreen) {

       rowNotFound = false

    }

    else {

        tableObject.Keys('[Page Down]')

    }

 

}


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Highlighted

@tristaanogre :

 

Thanks for the reply. Here is what I was trying before:

 

function GridCellCheckboxClick(List, Row, Column)
{
   var Row = List.Panel(Row - 1).Panel(0);
   if (! (Row.Exists = true))

       {

           Row.scrollIntoViewIfNeeded();

        }
}

 

Unnecessary parts of the function were removed. I knew I would need to clean up my if statement but because the row was not even in memory yet it was failing on the declaration of the variable, which is where I think your suggestion might also fail.

Highlighted

My code was pseudcode, by no means fully fleshed out or tested. It was intended to present concept.

 

So, basically, replace you "ScrollIntoView" with sending a PageDown keystroke to the table that needs to scroll.  Then write some code to check to see if the desired row is on screen.  FindChild works well for this.  It will return a stub object with Exists = false if not found or it will return an actual object which you can then return as the result of the function if so desired.  


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Highlighted

Just as a note, your test for "Row Exists" will fail immediately because if the object does not exist, how can you test the value of the property of the non-existing object?  ALWAYS, when testing for "existence", you should use a method that will return some object with the Exists property.  FindChild, FindChildren, WaitChild, WaitAliasChild, etc., will all return a "stub" with the Exists property as false.  Your code COULD work if you replace that logic and replace the ScrollIntoView with a PageDown.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Highlighted

@tristaanogre 

I have been experimenting with the find child (which i have used successfully in other places) and it will not return a stub object. Maybe I am using it incorrectly. Here is my code:

 

function findRow()
{
var Row = 8;
var List = Aliases.pageDispatch.ListDispatchJobs;
var child = List.FindChild("Name", "Panel(" + (Row -1) + ")", 1, true);
Log.Message(child.contentText);
}

 

Row 7 does not exist yet as I haven't scrolled that far. If I run it without the Log.Message line, it passes with no details at all. With the Log.Message, I get this message: "The object does not exist. See details..." and the details say "You are trying to call the "contentText' method or property of an object that does not exist." It does not give me a stub object. I also tried entering a row number that does exist and it returned the correct content text.

Highlighted

Hi,

 

It does not give me a stub object.

It does.

Exactly as Robert has said (and as stated in the test log) : the sought for object does not exist (stub with the only .Exists property is returned) and thus you cannot use any method/property except the .Exists one.

Correct code will be:

var child = List.FindChild("Name", "Panel(" + (Row -1) + ")", 1, true);

if (child.Exists)
  Log.Message(child.contentText);

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted

FindChild by itself still won't overcome the lazy-load... that's why my PseudoCode had the PageDown call in a while loop.  I'd re-write your code as follows.

 

function findRow()
{
var Row = 8;
var List = Aliases.pageDispatch.ListDispatchJobs;
var child = List.FindChild("Name", "Panel(" + (Row -1) + ")", 1, true);
while (!child.Exists) {
    List.Keys("[PageDown]");
    child = List.FindChild("Name", "Panel(" + (Row -1) + ")", 1, true);
}
Log.Message(child.contentText);
}

This will check to see if the child exists.  If not, it sends a page down keystroke to scroll the list and then checks again.  When it does exist, it exits the while loop and the child object is now the desired object.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

Highlighted

I am going to accept the above as the solution because it would have gotten me there if the app was built the way I had assumed. However, I am going to have to re-think how I want to identify the child because it seems to not only be lazy loading but when it generates the content, it seems like it is adding some items to memory and removing others and dynamically generating parts of the identifiers I had planned to use. However, this solution gets me much further down the road. Thank you!!!

Highlighted

You can still adapt that solution.  But rather than picking a static row number, I'm assuming there's a specific text you're looking for.  If that's the case, you can do something like this.

function findRow()
{
var List = Aliases.pageDispatch.ListDispatchJobs;
var child = List.FindChild("contentText", "*the text you're looking for*", 1, true);
while (!child.Exists) {
    List.Keys("[PageDown]");
    child = List.FindChild("contentText", "*the text you're looking for*", 1, true)
}
Log.Message(child.contentText);
}

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors