The Right Iterator for the Job?

Hello,

I’m finally moving out from under the repetitive scripts I accumulated from first learning Eggplant and have compressed a lot into iteration blocks like the one below. I trimmed this down for illustration purposes, and while I’ve been sitting with the SenseTalk manual more, I’m still a little unsure of proper choice of iterators based upon the type of testing; although I’ve used this for both application and web testing scenarios. Anyone work with iteration that might have a more advanced approach? Don’t get me wrong, it works great and in my larger script I have conditionals that do stuff based on which Link(x) is in play. But I still feel this is basic and could be better constructed.

Thanks!

The more advanced stuff really depends on the complex things you are wanting to do. But I can offer a few pointers right off the bat.

  1. I would put all of those links into a list and just repeat with each item Link of LinkList.
  2. Typing out a whole hyperlink is a bit painful (depending on the length). I’d set the remoteclipboard to “URL” typetext cotnrolkey, “v”, returnkey also controlkey, “l” is the hotkey for getting to the chrome address bar. I also recommend using typetext windowskey, “r” typetext BrowserVar&&URL_Var then you can launch chrome WITH a URL instead of typing it in. You can paste into the run window too of course.
  3. Learn to love repeatindex() or the repeatindex it is super-duper helpful for all kinds of stuff in repeats. You could use it to move your Link5 stuff into the repeat. I’d put a conditional statement in there, something like: if the repeatindex + 1 is “” else Click “newtabChrome” Or use not “”, whatever. Eggy is super speedy about processing conditional statements that aren’t looking for junk on the screen, so there is no reason to be concerned about the fact that it is processing a conditional statement EVERY time it repeats, it doesn’t care and the benefits of avoiding ‘special’ circumstance code like your Link5 stuff above is obvious.
  4. Once you start putting things in lists and processing them that way it won’t be long before you start wanting even more identifiers/controls/parameters/etc and the best way to do that is with Property Lists.

Here’s one I wrote yesterday
Repeat with each item Datum of the keys of DataList
Log “Looking for…”,“Header:”&& DataList.(NextDatum).FieldHeader,“Value:”&&DataList.(NextDatum).FieldValue
put (item (the repeatindex)+1 of the keys of DataList) into NextDatum
ScrollLeft DataList.(NextDatum).FieldHeader
assert that imagefound(text:DataList.(NextDatum).FieldValue, searchrectangle:[CheckForEndOfList (DataList, NextDatum),Row+15,left of imagerectangle(DataList.(Datum).FieldHeader),Row-15]) with error “Looking for FieldValue:”&&<<">>&DataList.(NextDatum).FieldValue&<<".>>&&“Under the Header:”&&<<">>&ParseFieldName (DataList, NextDatum)&<<".>>
add 1 to DatumCount
End Repeat

This was a modification of a repeat I call “The QA Engine”. With some modification it can scroll through any page and look for OCR text relative to any 1 or 2 images. It uses a fresh searchrectangle that is dynamically generated and indexes through a list to find the things you want. It nests functions and generic handlers into the assert to monitor the need to scroll and provides nice logging and throughout. I put it in a TestCase and then I can spit out all kinds of useful information when its done.

This particular one examines the page “backwards” (right to left in this example) which is especially weird, but that’s how the QA lead wanted it. It uses the relative position of the NEXT field to the current field to find stuff.

Nesting functions into searchrectangles is fun :crazy_face:.

Hope some of that helps.

1 Like

Logan,

Appreciate the reply! I’ll work on #1 and #2 today and see how they fit with my needs. I agree with #2 whole-heartedly! However, one reason I plugged the URLs into variables instead of right into the list was in case I needed to act on the variables later in the script. I’ll be honest, I haven’t had to as yet in my testing, but I wanted to have the option. I’m curious if there is any added benefit to variable assignment-> list versus list only?

Thanks for #3 and #4. I’ll sit with these tonight and play in my sandbox :slight_smile:

Thanks!

Glad I could help. The cool thing about the list is that you can always reference it later–so long as you know which item it is. Or you can reference it by its value. Or search for it in the list. Or, if you make it a property list and give the list items names you can reference them by names.
Some examples:
Log item 3 of LinkList
or
Log each item of LinkList which is “MyrURL”
or
Log each item of LinkList which contains “oglaf”
or
repeat with each item of LinkList
if it contains “sequentialart”
Log it
end repeat

Remember, the list is just a variable full of values. Or a variable full of Variables. Or a variable full of lists of variables if you like :slight_smile: .

This will become important when you start working with Functions if you’re not already, since you can only return one variable from a function.

1 Like

Thanks! I just finished a course on Python so programmatically this is all making sense. Functions in Eggplant are definitely the next hurdle. The more code I can squish into reusable objects the better!

Alright, I have some homework. Appreciate the help.

Cheers!

1 Like