./psh.phar initShopware 6 gets initialized clean and without demo data. Installation of E2E dependencies can be accomplished separately by running
npm installin the E2E folder you're using, e.g. for Shopware Administration it's
run, this is done automatically.
Resources/app/<environment>/test/e2e, please run
npm init -yto generate a
package.jsonfile. It is very convenient to place a script inside the newly created
package.jsonto run the tests locally. Please add the following section to do so:
e2e/cypress/plugins/index.jswith the following content:
XQuartz > Preferences(
⌘ + ,) and enable
Allow connections from network clients:
$IPto xhost's ACL:
true. This way, Cypress will recognise your environment as local, without the use of docker. Afterwards, you are able to use the same
./psh.pharcommands as you would do using docker-based development environment.
Resources/app/<enviroment>/test/e2eand execute the following command:
<your-url>means the Storefront-URL of your Shopware environment.
e2e:init. However, if your shopware installation is already clean and prepared, you can skip the preparation of your shopware installation by using the following command inside your docker container:
Administrationas default app environment. If you want to use
Storefrontenvironment, add the following parameter:
src/Administration/Resources/app/administration/test/e2e. There you can find the following folder structure, depending on your environment being Administration or Storefront:
cypressfolder, all test related folders are located. Most things will take place in these four folders:
fixtures: Fixtures are used as external pieces of static data that can be used by your tests. You can use them
integration: By default, the test files are located here. A file with the suffix "*.spec.js" is a test file that
plugins: Contains extensions or plugins. By default, Cypress will automatically include the plugins file before
support: The support folder is a great place to put reusable behavior such as custom commands or global overrides in,
context()as its alias):
it()functions within the
describe()function are your actual tests. Similar to
it()is identical to
specify(). However, for writing Shopware tests we focus on
it()to keep it consistent.
afterhook (sometimes tests may fail), the safer way to cleanup your tests is the
beforeEachhook. On top of stability advantages, it's possible to stop the tests anytime without manual cleanup.
jsonfile in the folder
e2e/cypress/fixtures. You can use those files to provide fixed test data which can be used directly to create the desired entity without any further searching or processing. Fortunately, Cypress provides a way to handle those fixtures by default. The command
cy.fixture()loads this fixed set of data located in a json file.
e2e/cypress/support/service/api.service.js, ApiService is shared between all repositories and acts as a basis for all your next steps of creating fixtures. That implies that the axios implementation of all important api methods can be found there. This service acts as an interface: Next to the basic functions like get, post etc the request method is specified here as well as some Shopware-related methods which have to be available in all repositories.
cypress/support/commands/api-commands.jsfor general operation and
cypress/support/commands/fixture-commands.jsspecifically for fixture handling.
createDefaultFixture(endpoint, options = )command, as seen below:
jsonfile located in the
fixturesfolder. Let's look at the command in detail:
e2e/cypress/support/service. Some examples for these services are:
FixturesService, all methods of it can be used in all other services as well.
shipping.fixture.js. This service is a rather simple example - It depicts a service in need of some customization for creating a shipping method correctly. With that being said, let's start.
ShippingFixtureServicehas to extend the class
AdminFixtureService. Afterwards, you create a function called
setShippingFixture(userData)with the parameter
userDatafor the data you want to use to create your shipping method. This way, your class should look like this:
ShippingFixtureService, you need the ID of the rule you want to use for the availability, and the ID of the delivery time.
CustomerDefinitionin Shopware platform.