Getting Started
When you launch Puppetry the very first time you are expected to see the welcome page:
At this stage we cannot do much - only to open an existing project or create one:
Let's create our first project intended to test responsive design on the landing page or our imaginary ACME forum application.
So we enter project name, browse for location and provide a name for the first suite. After pressing submit we end up on the suite page:
Let's add a few targets:
Here we identify main menu container, which is visible on desktop, but behind the burger menu on mobile. We define teaser target (the first matching the selector), which also visible only on desktop. Eventually we specify mobile menu container that on the contrary shows up on mobile, but hidden on desktop.
Now we switch to the Test Cases tab:
Let's add the first group "Landing page":
Now we have to expand the newly added group, so we click expand button:
Under the group record we get a new form to enter test case name:
As a new test case record appears we again click expand button next to it:
Let's add our first command into the test case. So we click on Add a command/assertion button:
That brings us to Edit Command/Assertion modal window:
Our goal is to ensure desktop-like screen size. So we select page target and setViewport method. We set screen width 1440 and height 900:
Many of test steps have additional options collapsed under Advanced Options link. E.g:
Here we don't need to change them. We click on Save button and get back to test case editing, where we click on Add a command/assertion button again to set navigation URL:
Now we have to assert that desktop menu and teasers are visible in this test case, but mobile menu not. So we click Add a command/assertion button and select a target identifier corresponding to mobile menu container:
Next we need assertVisible
method, so we focus on method input and start typing "assert":
The list of options adjust according to search keyword, so we can easily find the required method.
We tick off value checkbox and click Save button. Similarly we create assertions for desktop menu and teaser, but set value to on. Finally we add command page.screenshot
and our first test case is ready:
I would suggest now to run the tests and check if everything is ok. So we press F6 and get the following modal window:
Here we just click on Run button. Yet the available options are:
On/Off switch makes Puppetry to run the test either in headless mode or in default browser (additional options will open as son as you set it On)
select a target environment
select which suites we include in the run
As we run it Puppetry opens panel Test report with test results:
It says everything is fine. If we click on Open directory with generated screenshots link we can see generated folder named after the test case where we can find the screenshot:
Now we create a new test case named on iPhone 8 mobile menu displayed. First we add a command to emulate iPhone 8 device:
Next we need a command to visit the landing page and assertions from the previous case. Let's just copy/paste them. So we focus on page.goto
command of the first test case and right-click on it:
Now we focus the destination - page.emulate
command of the second test case and right-click again:
We need to repeat it for the assertions and page.screenshot
command. Then we edit assertions for opposite values and give a new title for page.screenshot
. After that our first suite is complete.
But what if any of assertion was wrong? Let's deliberately change assertion value for mobile menu container in the second case. So now it's expected to be not visible. We run tests (F6) and observer the failed test step reported:
If we switch to suite tab (rwd.json) we see that failed assertion record is highlighted:
When working with test cases (especially debugging) sometimes you will want to temporarily disable some test steps and run only the ones you currently focused on. That can be done from the context menu (right-click). The disabled test steps will be also highlighted:
Last updated