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
spec
directory contains all the top-level test files. Each test file is named as*.spec.js
and contains the test for a particular user type. For example,blog-admin-tests
directory contains all the tests for theBlog Admin
user. -
The
puppeteer-testing-utilities
directory 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-utilities
directory holds the utility files for different user types. Each user utility class is build upon the basepuppeteerUtilities
class containing the original methods along with the ones related to that user type. For eg.e2eBlogPostAdmin
contains base functions as well as additional functions just related toBlog Admin
user. -
The
images
directory 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}}
For example, to run the check-blog-editor-unable-to-publish-duplicate-blog-post.spec.js
test, run the following command:
python -m scripts.run_acceptance_tests --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
spec
directory. For ex.Topic Manager
user 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.js
anddelete-topic.spec.js
forTopic Manager
user. 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-utilities
directory. For ex. the blog editor tests are written within thespec/blog-editor-tests
directory, and the functionality of the tests are defined in theuser-utilities/blog-post-editor-utils.js
file.
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
,deleteDraftBlogPostWithTitle
etc. 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.js
file, thecreateDraftBlogPostWithTitle
method is called to create a draft blog post with a given title. ThedeleteDraftBlogPostWithTitle
method is called to delete the draft blog post with the given title. -
For each test, the user is created using the
userFactory
class. For ex. in thecreate-draft-and-delete-draft-blog-post.spec.js
file, thecreateNewBlogPostEditor
method is called to create a new blog post editor user. ThecreateNewBlogPostEditor
method is defined in theuser-factory.js
file. ThecreateNewBlogPostEditor
method 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
showMessage
method is called to log the progress. For ex. in thecreate-draft-and-delete-draft-blog-post.spec.js
file, theshowMessage
method is called to log the progress after the draft blog post is created. TheshowMessage
method is defined in theshow-message-utils.js
file. -
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-utilities
directory 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