The important thing to keep in mind when creating an Eggplant script is to ask yourself “How would a person do this?”. Usually this will be the same approach that your script should take.
In your example, the script will select a document to be previewed in the same way that a person would (such as by clicking the name of the document in a list and then clicking a “Preview” button, or whatever the steps are in your application).
To verify that the document displayed is the correct one, a person would “look at” the document displayed in the preview area. The usual way to tell Eggplant to do this is by inserting a WaitFor command in your script. This command will repeatedly scan the screen looking for a particular image to appear. So your command might look like this:
Here, “MyDocumentPage1” would be a captured image of the first page of the document, and 8 is the maximum time (in seconds) that you think it should take for the application to display the page. In general, you want to capture an image that is just enough to uniquely identify an object. In this case, though, you may want to capture an image of the entire page to validate that it all looks exactly like it should.
I like to think of the process of creating an Eggplant script as being one of showing Eggplant what you want it to do. You walk Eggplant through the steps you want to automate, pointing out what you want it to do along the way: “Click this button, type some text here, press return, wait until you see something that looks like this, then close the window…”.
When you’re done showing Eggplant all of the steps to take, then it can repeat them again. Of course, scripts get more complicated than that, but starting with the idea of walking Eggplant carefully through all of the steps is usually a good way to start, then go back and refine the script as needed.
In your case, after the document has been selected, you want to verify each of the pages. So after the WaitFor command that waits for the first page to be displayed, your script would click the button to flip to the next page, then wait for that page to appear, and so forth. For a three page document, it might look like this:
Again, you will capture an image of each page to validate if you need to verify the appearance of the entire page. Or you could simply capture images of the page numbers if it’s only important to verify that the correct number of pages appears.
As your scripting skills increase (and your test requirements become more complex) you may want to refine this code using a data driven approach. The portion of the script shown above might end up looking something like this:
repeat with pageNum = 1 to the number of items in pageList
WaitFor 8, item pageNum of pageList
Here, it is assumed that the names of all of your page (or page number) images are in a list called pageList. I hope this explanation is enough to help you get started.