Puppetry
3.2.2
3.2.2
  • Welcome Puppetry
  • Getting Started
  • Project
  • Suite
  • Group
  • Target
    • Simple Target
    • iFrame Target
    • ShadowDOM Target
    • Chained Target
    • Shared Target
  • Test Case
  • Test Step / Action
    • Page Commands
    • Page Assertions
    • Target Commands
    • Target Assertions
  • Managing Records
  • Snippets
  • Running tests
    • Interactive Mode
    • Troubleshooting
  • Test Report
  • Export
    • Exporting as Jest Project (CI-friendly)
    • Exporting as Test Specification
  • Settings
  • Template Expressions
  • Testing Techniques
    • Testing Dynamic Content
    • Exhaustive Testing
    • Performance Testing
    • Visual Regression Testing
    • Testing Shadow DOM
    • Testing Google Analytics tracking code
    • Testing Chrome Extensions
    • Testing REST API
    • Mocking HTTP/S Requests
    • Testing Transactional Emails
      • Example with Restmail.net
      • Example with Mailinator
      • Example with IMAP bridge
      • Example with Google API
    • Testing Forms with Captcha
  • Version Control
  • Tips and Tricks
    • Embrace the Power of CSS
  • Command API
  • Test Application
Powered by GitBook
On this page
  • Using Snippets by Example
  • Creating Login Snippet
  • Running Snippets with Diverse Input

Was this helpful?

Snippets

PreviousManaging RecordsNextRunning tests

Last updated 5 years ago

Was this helpful?

Snippets are reusable test cases in scope of project. So you can create a snippet and refer to it in your test suites. For example, to login a user we need to perform multiple actions: visit login form, fill it out and submit. Instead of adding these test steps to every test case for logged in user we can simply create once a snippet and then refer to it from many test cases. Besides, to every reference we can assign a set of template variables that can be addressed in the body of the snippet. In other words, we can execute the same snippet, but giving it a different input every time.

Using Snippets by Example

In order to illustrate the concept we are going to create a simple test case for an . Let's say we have a test case "user registers and activates the account" where Puppetry visits forum register page, fills out the registration form and submits it. So we have a bran new user in the system and can login to run test flows for an authorized user. However to get the initial state in the beginning of every test group we need to repeat and repeat the login flow (visit login page, fill out the form, submit). Why not to make a snippet and reuse it?

Creating Login Snippet

Next we press Project / Snippets in the main menu

Snippets are quite similar to suites. They have local targets and test cases.

Now we just into Snippets tab and create the test case:

As we are done with the snippet we can navigate back to the suite:

We create an test case "user gets logged in" and click under it to the Add a reference button

In the following modal window we select our recently created snippet:

After extending the test case with other test steps it looks like that:

During the test run first all the test steps of the snippet are executed, so user gets logged in. We wait until the page is ready (login form doesn't contain .categories selector, but landing page does). Now we can assert that page header changed (has #user-header-name).

Running Snippets with Diverse Input

In the example above we used TEST_EMAIL template variable defined during registration flow. But imagine that we have a number of already registered accounts (let's say one is inactive, one is active, one is privileged) and we want sequencely log in with each one and assert that the application responds as intended. What we can do is reusing "user logs in" snippet, but with diverse emails. Click on the Edit action next to the reference test step:

You get a modal window that we know from the example below. Click to Local Template Variables to expand the template editing interface and add TEST_EMAIL variable:

Now you clone the reference and edit it again. Remove TEST_EMAIL and add it again with a new value. As you run the tests the references will execute the snippet with the values we assigned.

We start by defining targets for the

login form
imaginary ACME forum app
Snippets in the Project menu
Snippet's targets
Snippet's body
Adding a reference into test case body
Test case body after adding a reference
Providing reference with input data