Fixing End-to-End Tests with action.js and waitFor.js #10798
Description
Introduction
Background
To ensure Oppia remains available and high-quality for our students, we run end-to-end tests on all PRs to check that the site's functionality hasn't been broken. Recently, these tests have begun failing non-deterministically. This frustrates developers and slows their work by incorrectly indicating that developers’ changes are faulty. The goal of this issue is to help resolve these failures, also known as "flakes," by fixing common bad patterns in the current tests.
Getting Started
Review the instructions below on how to fix the tests. Then message on the issue thread asking to be assigned to one of the unclaimed files. We will assign you to the file by adding your username next to the file listing. If you have any questions, message on the issue thread, and we'll help you out!
How to Fix Tests
For this task, we would like you to pick one of the files listed below and make the following fixes wherever applicable:
- Instead of calling
.click()
on an element, useaction.click()
fromaction.js
- Here's an example (link):
- await element(by.css('.protractor-test-interaction')).click(); + var testInteractionButton = element(by.css('.protractor-test-interaction')); + await action.click('Test Interaction Button', testInteractionButton);
- Sometimes there might be a
waitFor
statement before the.click()
call to make sure the element has loaded before we click it. These can be removed becauseaction.click
includeswaitFor
statements.
- Here's an example (link):
- Instead of calling
.getText()
on an element, useaction.getText()
fromaction.js
- Here's an example:
- var text = await element(by.css('.protractor-test-interaction-name')).getText(); + var interactionNameElement = element(by.css('.protractor-test-interaction-name')); + var text = await action.getText('Interaction name element', interactionNameElement);
- Sometimes there might be a
waitFor
statement before the.getText()
call to make sure the element has loaded before we get its text. These can be removed becauseaction.getText
includeswaitFor
statements.
- Here's an example:
- Instead of calling
.clear()
on an element, useaction.clear()
fromaction.js
- Here's an example (link):
Note that the diff above is simplified from the linked PR for clarity.
- await stateNameInput.clear(); + await action.clear('State Name input', stateNameInput);
- Sometimes there might be a
waitFor
statement before the.clear()
call to make sure the element has loaded before we click it. These can be removed becauseaction.clear
includeswaitFor
statements.
- Here's an example (link):
- Instead of calling
.sendKeys()
on an element, useaction.sendKeys()
fromaction.js
- Here's an example (link):
Note that the diff above is simplified from the linked PR for clarity.
- await stateNameInput.sendKeys(name); + await action.sendKeys('State Name input', stateNameInput, name);
- Sometimes there might be a
waitFor
statement before the.sendKeys()
call to make sure the element has loaded before we click it. These can be removed becauseaction.sendKeys
includeswaitFor
statements.
- Here's an example (link):
- Use functions from
waitFor.js
to verify that elements have loaded before interacting with them:- Here's an example(link):
+ await waitFor.visibilityOf(languageSelectorLabelElement, + 'Language selector label element taking too long to appear'); expect(await languageSelectorLabelElement.getText()).toBe( 'Translations for language:');
- Guidelines on finding out which elements need
waitFor.js
function calls: Please addwaitFor
statements before any code that requires an element to be present. For example, we need to wait for the element to be present before getting an element's text. In some cases you might not be able to just wait for the element to appear because the test is checking whether that element is present. In these cases, you can wait instead for another element that loads at the same time. Err on the side of adding unnecessarywaitFor
statements if you're unsure.
- Here's an example(link):
For more guidance, see our wiki page
Tests to Fix
Finished Files
- core/tests/protractor/learnerFlow.js @AdityaDubey0
- core/tests/protractor_utils/AdminPage.js @mridul-netizen Fix part of #10798:Fixing End-to-End Tests with action.js and waitFor.js #10954 Fix part of #10831 #10831
- core/tests/protractor_utils/ContributorDashboardPage.js @HarshKhilawala fix end to end tests for ContributorDashboard Page.js with action.js and waitFor.js #10928 fix ContributorDashboardPage.js #10872
- core/tests/protractor_utils/CollectionEditorPage.js @mridul-netizen Fixes part of #10798:Fixing End-to-End Tests for CollectionEditor.js #11126
- core/tests/protractor_utils/ContributorDashboardTranslateTextTab.js @jnthn-sltn bug 10798 u:jnthn-sltn assignment complete #11062 Fix part of #10798 #11064
- core/tests/protractor_utils/ExplorationEditorFeedbackTab.js @suryasiriki4 Fix issue #10798 : Fixed End-to-End Tests with action.js and waitFor.js in ExplorationEditorFeedbackTab.js #11166
- core/tests/protractor_utils/ExplorationPlayerPage.js @jimbyo Fix to #10798 Refactor ExplorationPlayerPage.js #11301
- core/tests/protractor_utils/CreatorDashboardPage.js @xarcode Fixed End-to-End tests for CreatorDashboardPage.js #11145
- core/tests/protractor_utils/ExplorationEditorImprovementsTab.js @prayutsu Fix part of #10798: Fix end to end tests for ExplorationEditorImprovementsTab.js #11619
- core/tests/protractor_utils/PreferencesPage.js @HarshKhilawala fix preferencePages as part of #10798 #11669
- core/tests/protractor_utils/GetStartedPage.js @prayutsu
- core/tests/protractor_utils/SubscriptionDashboardPage.js @archi15
- core/tests/protractor_utils/ProtractorConstants.js
- core/tests/protractor_utils/ThanksPage.js @Garvnanwani
- core/tests/protractor/profileMenuFlow.js @kishanhitk
- core/tests/protractor_utils/LearnerDashboardPage.js @SAEb-ai
- core/tests/protractor_utils/users.js @ashutoshc8101
- core/tests/protractor_utils/general.js @shubhamkorde
- core/tests/protractor/accessibility.js @FareesHussain
- core/tests/protractor/libraryFlow.js @kishanhitk
- core/tests/protractor_utils/ExplorationEditorHistoryTab.js @BxBxB
- core/tests/protractor_utils/LibraryPage.js @taiwo2
- core/tests/protractor_utils/ProfilePage.js @sajenjeshan1222 Update ProfilePage.js #12593
- core/tests/protractor_utils/ExplorationEditorMainTab.js @EeshaArif Fix part of #10798: Fix explorationEditorMainTab with action.js and waitfor.js #12700
- core/tests/protractor_utils/ExplorationEditorSettingsTab.js @halsheik Fix Part of #10798: Fixed e2e test file to resolve non-deterministic behavior #12614
- core/tests/protractor_utils/ExplorationEditorTranslationTab.js @mahendra1290 Fix part of #10798: Fix end-to-end tests for ExplorationEditorTranslationTab.js #13856
- core/tests/protractor_utils/ClassroomPage.js @pankajdahiyapd Fix part of #10798: Fix end to end tests for ClassroomPage.js #12670
- core/tests/protractor_utils/ExplorationEditorPage.js @mohithk100 Fix #10798: Fixing e2e tests for ExplorationEditorPage.js #13937
- core/tests/protractor_utils/forms.js @sahiljoster32 Fix part of #10798: Fixing End-to-End Tests with action.js and waitFor.js for forms.js #13924
- core/tests/protractor_utils/TopicEditorPage.js @soumyo123-prog Fix part of #10798: Use action.js and waitFor.js in TopicEditor.js #13887
- core/tests/protractor_utils/TopicsAndSkillsDashboardPage.js @ashish-patwal Fixing #10798 End-to-End Tests with action.js and waitFor.js in TopicsAndSkillsDashboardPage.js #14077
- core/tests/protractor_utils/StoryEditorPage.js @ShivamJhaa Fix #10798: Fixes End-to-End Tests for core/tests/protractor_utils/StoryEditorPage.js #13931
- core/tests/protractor_utils/workflow.js @KarishmaVanwari Fix part of #10798: Fixed end-to-end tests for workflow.js #14124
- core/tests/protractor_utils/SkillEditorPage.js @mahendra1290 Fix part of #10798: Fix end to end tests for SkillEditorPage.js #14114
Note: For a guide on how to access Oppia's webpages, see this.