question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fixing End-to-End Tests with action.js and waitFor.js

See original GitHub issue

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, use action.click() from action.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 because action.click includes waitFor statements.
  • Instead of calling .getText() on an element, use action.getText() from action.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 because action.getText includes waitFor statements.
  • Instead of calling .clear() on an element, use action.clear() from action.js
    • Here’s an example (link):
      - await stateNameInput.clear();
      + await action.clear('State Name input', stateNameInput);
      
      Note that the diff above is simplified from the linked PR for clarity.
    • 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 because action.clear includes waitFor statements.
  • Instead of calling .sendKeys() on an element, use action.sendKeys() from action.js
    • Here’s an example (link):
      - await stateNameInput.sendKeys(name);
      + await action.sendKeys('State Name input', stateNameInput, name);
      
      Note that the diff above is simplified from the linked PR for clarity.
    • 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 because action.sendKeys includes waitFor statements.
  • 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 add waitFor 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 unnecessary waitFor statements if you’re unsure.

For more guidance, see our wiki page

Tests to Fix

Finished Files

Note: For a guide on how to access Oppia’s webpages, see this.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:285 (225 by maintainers)

github_iconTop GitHub Comments

1reaction
U8NWXDcommented, Sep 8, 2021
1reaction
U8NWXDcommented, Sep 7, 2021

@tiptondt1998 @mahendra1290 I’ve assigned you

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Write End-to-End Tests in Node.js Using Puppeteer ...
First, create a few folders to give structure to your testing application: mkdir actions; mkdir logs; mkdir specs; mkdir utils.
Read more >
Async waits in React Testing Library - Reflect.run
This tells the JS runtime to wait for the Promise to be resolved before proceeding, and allows async code to be read top-down...
Read more >
How to Fix Flaky Tests - Semaphore CI
Randomly failing tests are the hardest to debug. Here's a framework you can use to fix them and keep your test suite healthy....
Read more >
React testing library how to use waitFor - Stack Overflow
The terminal says waitForElement has been deprecated and to use waitFor instead. How can I use waitFor in this test file? javascript ·...
Read more >
Frontend testing standards and style guidelines - GitLab Docs
We use Jest for JavaScript unit and integration testing, and RSpec feature tests with Capybara for e2e (end-to-end) integration testing.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found