Acceptance tests are end-to-end tests that test the complete functionality of the application, and this will help users to catch bugs and regressions before they are released ensuring that the code does what it is supposed to do.
This guide will help you to get started on how to write e2e acceptance test for a particular user-type.
oppia/core/tests/
└── puppeteer-acceptance-tests
├── spec
│ ├── blog-admin-tests (give user type name)
│ │ ├── assign-role-to-users-and-change-tag-properties.spec.js
│ ├── blog-editor-tests
│ │ ├── create-draft-and-delete-draft-blog-post.spec.js
│ │ └── publish-blog-post-and-delete-published-blog-post.spec.js
| | └── check-blog-editor-unable-to-publish-duplicate-blog-post.spec.js
├── images
│ └── blog-post-thumbnail.svg
├── puppeteer-testing-utilities
│ ├── puppeteer-utils.js
│ ├── show-message-utils.js
│ ├── test-constants.js
│ └── user-factory.js
└── user-utilities
└── blog-post-admin-utils.js
└── super-admin-utils.js
The directory structure is as follows:
-
The
specdirectory contains all the top-level test files. Each test file is named as*.spec.jsand contains the test for a particular user type. For example,blog-admin-testsdirectory contains all the tests for theBlog Adminuser. -
The
puppeteer-testing-utilitiesdirectory contains all the utility files and helper functions, which you would require to write new acceptance tests. This directory can also be used to append more utility functions as when required or needed by the user. Files included inside this directory are :
puppeteer-utils.js-> This file contains the base puppeteerUtilities class which provides the most common and useful methods such as openBrowser, goto etc. This class also serves the purpose of providing a base for defining other user oriented subclasses for eg. e2eBlogPostAdmin class of blog-post-admin-utils.js .user-factory.js-> This file contains methods for creating a certain user. The file has different methods for creating different types of user.test-constants.js-> This file contains defined constants such as _*URLs, classname, id etc. which are used in the tests.show-message-utils.js-> This file contains method for logging the progress and errors during a test.
-
The
user-utilitiesdirectory holds the utility files for different user types. Each user utility class is build upon the basepuppeteerUtilitiesclass containing the original methods along with the ones related to that user type. For eg.e2eBlogPostAdmincontains base functions as well as additional functions just related toBlog Adminuser. -
The
imagesdirectory contains all the images used in the tests.
From the root directory of oppia, run the following command:
python -m scripts.run_acceptance_tests --suite={{suiteName}}
Docker:
make run_tests.acceptance suite=SUITE_NAME
For example, to run the check-blog-editor-unable-to-publish-duplicate-blog-post.spec.js test, run the following command:
Python:
python -m scripts.run_acceptance_tests --suite="blog-editor-tests/check-blog-editor-unable-to-publish-duplicate-blog-post.spec.js"
Docker:
make run_tests.acceptance suite="blog-editor-tests/check-blog-editor-unable-to-publish-duplicate-blog-post.spec.js"
- Create a new directory for the specific user if it doesn't already exists inside the
specdirectory. For ex.Topic Manageruser can have directory named astopic-manager-tests, and within the user directory, each test file is named as*.spec.js.
Note: Naming convention for directories / files is kebab case, where each word is separated by a (-)
-
Within the user directory, create a new file for each test. For ex.
create-new-topic.spec.jsanddelete-topic.spec.jsforTopic Manageruser. And these top-level test contains single user stories checking their test steps and expectations mentioned in the testing spreadsheet. -
The functionality of the top-level tests for each user-type is defined in the
user-utilitiesdirectory. For ex. the blog editor tests are written within thespec/blog-editor-testsdirectory, and the functionality of the tests are defined in theuser-utilities/blog-post-editor-utils.jsfile.
Note: A utility file is maintained for each user type. The purpose of maintaining this file is to add methods specific to that user on top of the already provided basic methods. This file maintains a user class which is extended from the base class of puppeteer-utils.js . For ex. blog-post-admin-utils.js have a class e2eBlogPostAdmin which have methods like
createDraftBlogPostWithTitle,deleteDraftBlogPostWithTitleetc. specific to Blog Admin only.
-
The utility files are imported in the top-level test files and the methods are called to perform the required actions. For ex. in the
create-draft-and-delete-draft-blog-post.spec.jsfile, thecreateDraftBlogPostWithTitlemethod is called to create a draft blog post with a given title. ThedeleteDraftBlogPostWithTitlemethod is called to delete the draft blog post with the given title. -
For each test, the user is created using the
userFactoryclass. For ex. in thecreate-draft-and-delete-draft-blog-post.spec.jsfile, thecreateNewBlogPostEditormethod is called to create a new blog post editor user. ThecreateNewBlogPostEditormethod is defined in theuser-factory.jsfile. ThecreateNewBlogPostEditormethod creates a new user with the given username and returns the user object. The user object is used to perform the required actions (that are defined in theuser-utilities/*-utils.js). -
After successful completition of any test step or any expectation, the
showMessagemethod is called to log the progress. For ex. in thecreate-draft-and-delete-draft-blog-post.spec.jsfile, theshowMessagemethod is called to log the progress after the draft blog post is created. TheshowMessagemethod is defined in theshow-message-utils.jsfile. -
If there is any error during the test, then we throw errors in the expectation step or there would be timeout error if some component does not behave as intended.
-
The
puppeteer-testing-utilitiesdirectory contains all the utility files and helper functions, which you would require to write new acceptance tests. This directory can also be used to append more utility functions as when required or needed by the user. -
The test must be thoroughly tested before submitting a PR. The test can be run locally by running the following command as mentioned above or you can run the test on the CI server by pushing your code to the remote branch in your fork. The CI server will run the test and will show the result.
Blog Admin and Blog Editor Tests - Blog Admin top-level tests Blog Editor top-level tests user utility files puppeteer utility files - base class puppeteer utility files - user factory