Overview
OpenCart 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/opencart-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/opencart-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",
"name": "Administrator Test"
},
"editor": {
"username": "editor",
"password": "dD.123123ddd",
"email": "editor@example.com",
"name": "Editor Test"
},
"customer": {
"username": "customer@example.com",
"password": "dD.123123ddd",
"email": "customer@example.com",
"name": "Customer Test"
}
}
}
}
Steps
- Given I am logged in to the shop as "customer"
- Given I am logged in to the administration as "admin"
- When I log in to the administration with the username "administrator" and the password "wrong"
- Then the login should be refused with "No match for Username and/or Password."
- Then I should be logged in to the administration as "Administrator Test"
- When I go to the category "Desktops"
- When I search the shop for "Apple"
- Then the product list should show "Canon EOS 5D"
- Then the product list should show "iMac", "MacBook" in this order
- Then the product "MacBook" of the list should read "$602.00"
- When I go to the product "Canon EOS 5D"
- Then the product page should show "Brand" as "Apple"
- When I choose "Red" for the option "Select"
- When I add the product to the cart
- When I add "iPhone" to the cart from the list
- When I add the product to my wish list
- Then the shop should say "Success: You have added Canon EOS 5D to your shopping cart!"
- Then the option "Select" should say "Select required!"
- Then the cart button should read "1 item(s) - $122.00"
- When I go to the cart
- Then the cart should list "Canon EOS 5D"
- When I change the quantity of "Canon EOS 5D" in the cart to 2
- When I remove "Canon EOS 5D" from the cart
- Then the cart should show "Sub-Total" as "$100.00"
- When I apply the coupon "WEBSHIP10"
- Then the cart should be empty
- When I go to the checkout
- When I check out as a guest with:
- When I ship to my address "1 Webship Street"
- Then the checkout field "E-Mail" should say "E-Mail Address does not appear to be valid!"
- When I choose the shipping method "Flat Shipping Rate"
- When I choose the payment method "Cash On Delivery"
- Then the order summary should show "Total" as "$130.00"
- When I confirm the order
- Then the order should be placed
- When I open "Address Book" in my account
- Then my address book should list "1 Webship Street"
- When I add the address:
- When I delete the address "3 Webship Lane"
- Then my order history should list my order as "Pending"
- Then my wish list should list "iPhone"
- When I remove "iPhone" from my wish list
- When I go to "Products" in the administration
- Then the administration menu should offer "Products"
- Then the dashboard should show "Total Orders" as "0"
- Then the administration list should show "Canon EOS 5D"
- When I start a new product "Webship test product"
- When I set "Model" to "WT-1" in the "Data" tab
- When I save the form
- Then the field "Model" should say "Product Model must be greater than 1 and less than 64 characters!"
- When I delete the product "Webship test product" in the administration
- Given there is no product "Webship test product"
- When I open the order I placed in the administration
- Then the order status should be "Pending"
- When I change the order status to "Processing"
- Then the order history should list "Processing"
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/opencart-steps.