Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Quality Assurance Intermediate Selenium WebDriver Use Selenium with Testing Frameworks Moving Page Code to a Page Object

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Confused: Mocha Tests aren't passing

What can I do to ensure my tests are passing? Having followed the video and updated the page_objects directory of the project files follow along my tests are not playing ball.

Do I need to update mocha or run the tests from a different directory?

rsvp.js
const {Browser, By, Key, until} = require("selenium-webdriver");

const url = "https://treehouse-projects.github.io/selenium-webdriver-intermediate/waits/app/index.html";

class RsvpPage {
    constructor(driver) {
        this.driver = driver;
        this.locators = {
            invitedList: By.id('invitedList'),
            registrationForm:  By.id('registrar'),
        }
    }

    open() {
        this.driver.get(url);
    }
}

module.exports = RsvpPage;
invitees.js
onst {Browser, By, Key, until} = require("selenium-webdriver");
const {suite} = require("selenium-webdriver/testing");
const assert = require('assert');
const RsvpPage = require('../pages/rsvp.js');

suite(function(env) {
    describe('RSVP site', function() {
        let driver;
        let page;

        before(async function() {
            driver = await env.builder().build();
            page = new RsvpPage(driver);
            await page.open();
        });

        it('has invitee list', async function() {
            let elements = await driver.findElements(page.locators.invitedList);
            assert(elements.length > 0);
        });

        it('has registration form', async function() {
            let elements = await driver.findElements(page.locators.registrationForm);
            assert(elements.length > 0);
        });

        after(async function() {
            driver.quit();
        });
    });
});
[INFO] Searching for WebDriver executables installed on the current system...
[INFO] ... located chrome
[INFO] Running tests against [chrome]


  [chrome]
    RSVP site
      1) "before all" hook
      2) "after all" hook


  0 passing (2s)
  2 failing

  1) [chrome]
       RSVP site
         "before all" hook:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\xamp\htdocs\intermediate-selenium\page_objects\test\invitees.js)


  2) [chrome]
       RSVP site
         "after all" hook:
     TypeError: Cannot read property 'quit' of undefined
      at Context.<anonymous> (test\invitees.js:28:20)




DevTools listening on ws://127.0.0.1:12722/devtools/browser/1c3fb564-b0bd-477d-85b9-c893efe7b29f

1 Answer

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,735 Points

It's just taking too long. This is the key part of the error message: "Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves."

The simplest way to deal with this is to add a flag to mocha when you run the command in the terminal to extend it's timeout:

mocha --timeout 15000