Overview
WooCommerce Steps adds step definitions to Webship-js 2.0.x for the markup the platform itself renders, regardless of theme or distribution, so scenarios read as plain sentences instead of CSS selectors. It is a plugin for Webship-js: it ships one file of step definitions you drop into an existing test project, and it composes with the built-in steps rather than duplicating them.
Install
npm install --save-dev @webship-js/woocommerce-steps
Then add its step file to cucumber.js beside the Webship-js steps:
require: [
'node_modules/webship-js/tests/step-definitions/**/*.js',
'node_modules/@webship-js/woocommerce-steps/tests/step-definitions/*.js',
'tests/step-definitions/**/*.js',
]
Test users
The steps that log in use accounts that already exist on the site, by the handle a feature names (Given I am a logged in user with the "admin" user). The site build creates them; a feature never creates or deletes an account. They are listed in cucumber.js under worldParameters. These are the test accounts of the pack's own test site: put the accounts of your site in your project, and keep real passwords in environment variables.
{
"worldParameters": {
"users": {
"admin": {
"username": "administrator",
"password": "dD.123123ddd",
"email": "administrator@example.com"
},
"shop_manager": {
"username": "shop_manager",
"password": "dD.123123ddd",
"email": "shop_manager@example.com"
},
"customer": {
"username": "customer",
"password": "dD.123123ddd",
"email": "customer@example.com"
}
}
}
}
Steps
This pack loads WordPress Steps itself, so every WordPress step is a step of a shop project too. They are listed here after the pack's own steps: one place to look for a tester or a developer working on a shop.
- When I log in to the store as "customer"
- Given I am a logged in user with the "admin" user
- When I log in as "admin" with password "secret"
- When I log in as the "admin" user with password "not-the-password"
- Given I am on the login page
- Then I should see the login form
- Then I should see a login error
- Then I should see a login message
- Given I am not logged in
- When I log out
- Then I should be logged in
- Then I should be on the login page
- Given I am on the shop
- Then the product list should have 16 products
- Then the result count should be "Showing 1–16 of 17 results"
- Then I should see the product "Beanie" in the product list
- When I open the product "Hoodie" from the product list
- When I sort the product list by "Sort by price: low to high"
- Then the product list should be ordered by price ascending
- When I go to the next page of the product list
- Then the product list should be on page 2
- When I add "Beanie" to the cart from the product list
- When I open the category "Hoodies"
- Then every product of the product list should be in the category "Hoodies"
- When I search the store for "hoodie"
- Then the breadcrumbs should be "Home / Shop"
- Then I should see the success message "“Hoodie” has been added to your cart."
- Then I should not see the coming soon page
- When I choose "Blue" for the product option "Color"
- Then the product option "Color" should be "Blue"
- When I set the product quantity to 2
- When I add the product to the cart
- Then adding the product to the cart should be refused with "Please select some product options"
- Then the product price should be "$45.00"
- Then the product should be on sale
- When I open the "Additional information" product tab
- Given my cart is empty
- Then the mini cart should show 1 item
- When I open the mini cart
- Then the mini cart should contain "Beanie"
- Then the cart should contain "Hoodie"
- When I change the cart quantity of "Beanie" to 2
- Then the cart quantity of "Beanie" should be 2
- When I remove "Beanie" from the cart
- Then the cart should be empty
- When I apply the coupon "suite10"
- Then the cart should have the coupon "suite10"
- When I remove the coupon "suite10"
- Then the cart subtotal should be "$45.00"
- When I fill in the checkout email with "guest@example.com"
- When I fill in the shipping address:
- When I choose the "Flat rate" shipping method
- When I choose the "Check payments" payment method
- When I place the order
- Then I should see the order confirmation
- Then the order total should be "$23.00"
- Then I should see the field error "Please enter a valid email address"
- Given I am on my "Orders" account page
- Then my order history should list the last placed order
- When I open the last placed order in my order history
- Then my billing address should contain "Los Angeles"
- When I change my billing address:
- When I open the last placed order in the admin
- Then the orders list should include the last placed order
- Then the order status should be "On hold"
- When I change the order status to "Completed"
- Then the order notes should include "Order status changed from On hold to Completed."
- When I add the order note "A note of the webship-js suite"
- Then the order should belong to a guest
- When I delete the last placed order
- Then the products list should include "Suite Mug"
- When I open the product "Suite Mug" in the admin
- When I move the product "Suite Mug" to the trash
- When I delete the product "Suite Mug" permanently
- Given there is no product "Suite Mug"
- When I delete the orders of "must-fail@example.com"
- Then an email with the subject "order has been received" should be sent to "guest@example.com"
- Then no email should be sent to "customer"
- Then the email with the subject "order has been received" to "guest@example.com" should contain "Beanie"
- Then the email with the subject "order has been received" to "guest@example.com" should be about the last placed order
- Then I should see the "At a Glance" dashboard widget
- Then the admin menu should list "Posts"
- Then the "Settings" admin submenu should list "Permalinks"
- When I click "Posts" in the admin menu
- When I click "Permalinks" under "Settings" in the admin menu
- Then the admin bar should list "Edit Post"
- When I click "Edit Post" in the admin bar
- Then I should see a success notice
- Then the "Hello Dolly" plugin should be installed
- When I activate the "Hello Dolly" plugin
- Then the "Twenty Twenty-Five" theme should be active
- Then the active theme should be a block theme
- When I save the settings
- Then the "Site Title" setting should be "My Site"
- When I change the "Site Title" setting to "My Site"
- When I restore the "Site Title" setting
- When I choose the "Post name" permalink structure
- When I restore the permalink structure
- Then the permalink structure should be "Post name"
- Then the site health test "Scheduled events are running" should pass
- Then the cron should respond
- Then the REST API should be available
- Then the REST route "/wp/v2/posts" should respond with status 200
- Then the REST route "/wp/v2/users/me" should require authentication
- Then the REST route "/wp/v2/posts?status=draft" should be refused
- Then the REST route "/wp/v2/posts" should list at least 1 item
- Then the REST route "/wp/v2/posts/1" should have "slug" equal to "hello-world"
- Then the site feed should be a valid RSS feed
- Then the site feed should list "Hello world!"
- Then the robots.txt file should be served
- Then robots.txt should disallow "/wp-admin/"
- Then robots.txt should list the sitemap
- Then the XML sitemap should be served
- When I submit the comment "Thank you for the article."
- Then I should see the comment "Thank you for the article."
- Then the comment "Thank you for the article." should be awaiting moderation
- When I approve the comment "Thank you for the article."
- Then the comment "Thank you for the article." should be pending
- Given I am on the new post screen
- When I open the post "Hello world!" in the editor
- When I set the post title to "A new post"
- When I write "Hello from the test." in the post content
- When I publish the post
- When I update the post
- When I save the post as a draft
- When I submit the post for review
- When I move the post to the trash
- Then the editor should offer "Publish"
- Then the post should be published in the editor
- Then I should see the editor notice "Post published."
- When I view the post
- Then the posts list should include "Hello world!"
- Then the post "Hello world!" should be published
- When I move the post "Review post" to the trash from the list
- When I restore the post "Review post" from the trash
- When I delete the post "Review post" permanently
- When I add the category "Reports"
- Then the category "Reports" should exist
- When I delete the category "Reports"
- When I file the post under the category "Reports"
- When I tag the post with "webship"
- Then the post should be in the category "Reports"
- When I upload the media file "webshipco.png"
- Then the media library should list "webshipco"
- When I delete the media file "webshipco" permanently
- Given I am on the lost password page
- When I request a password reset for the "subscriber" user
- Then my account should have the "editor" role
- Then the admin bar should show the account "webmaster"
- Given I am on the "Plugins" admin screen
- Then I should be on the "Dashboard" admin screen
- Then I should see the access denied screen
- Then the page should return HTTP status 200
- Then the navigation menu should list "Sample Page"
- When I open the navigation menu
- When I click "Sample Page" in the navigation menu
- Then I should see the "Search" block
- Then I should see the header template part
- Then the page should advertise the REST API
- Then the page should link to the site feed
- Then I should see the site title
- Then I should see the admin bar
- Then I should see the comment form
- Given I am on a page
- Given I am on a post
- Given I am on a category archive
- Then I should see the post title
- Then I should see post entries
- When I search the site for "hello world"
- When I search the site for existing content
- Then I should see the search form
- When I use the search form to search for "hello"
- Then I should see search results for "hello world"
- Then I should see no search results for "qzxjvwk"
- Then the search results should include "Hello world!"
Every assertion step reads both polarities from one definition: should see and should not see are the same step. Source and issues: github.com/webship/woocommerce-steps.