Help with Quality Assurance with Chai Run Functional Tests Using a Headless Browser challenge

Hi,

I am doing the Quality Assurance and Testing with Chai course, and I am stuck on the second last and last challenges where I need to use Zombie.js to code functional tests in the browser.

Here are the instructions that FCC provides to complete the challenge :

test('Submit the surname "Polo" in the HTML form', function (done) {
  browser.fill('surname', 'Polo').then(() => {
    browser.pressButton('submit', () => {
      browser.assert.success();
      browser.assert.text('span#name', 'Marco');
      browser.assert.text('span#surname', 'Polo');
      browser.assert.elements('span#dates', 1);
      done();
    });
  });
});

My package.json

{
  "name": "automated-testing-app",
  "version": "0.0.1",
  "description": "Boilerplate for the Quality Assurance and Testing with Chai challenges",
  "main": "server.js",
  "scripts": {
    "start": "node --watch server.js"
  },
  "dependencies": {
    "body-parser": "1.19.0",
    "chai": "4.3.4",
    "chai-http": "4.3.0",
    "cors": "2.8.5",
    "express": "4.17.1",
    "mocha": "9.0.3",
    "zombie": "6.1.4"
  },
  "license": "MIT",
  "directories": {
    "test": "tests"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/freeCodeCamp/boilerplate-mochachai.git"
  },
  "keywords": [],
  "author": "",
  "type": "commonjs",
  "bugs": {
    "url": "https://github.com/freeCodeCamp/boilerplate-mochachai/issues"
  },
  "homepage": "https://github.com/freeCodeCamp/boilerplate-mochachai#readme"
}

And this is my Zombie.js and Chai setup

const Browser = require('zombie');

suite('Functional Tests with Zombie.js', function () {
  this.timeout(5000);

  Browser.site = 'http://127.0.0.1:3000/';
  const browser = new Browser();

  suiteSetup(function(done) {
    return browser.visit('/', done);
  });

  suite('Headless browser', function () {
    test('should have a working "site" property', function() {
      assert.isNotNull(browser.site);
    });
  });

  suite('"Famous Italian Explorers" form', function () {
    // #5
    test('Submit the surname "Colombo" in the HTML form', function (done) {
      browser.fill('surname', 'Colombo').then(() => {
        browser.pressButton('submit', () => {
          browser.assert.success();
          browser.assert.text('span#name', 'Cristoforo');
          browser.assert.text('span#surname', 'Colombo');
          browser.assert.elements('span#dates', 1);
          done();
        });
      });
    });
    // #6
    test('Submit the surname "Vespucci" in the HTML form', function (done) {
      browser.fill('surname', 'Vespucci').then(() => {
        browser.pressButton('submit', () => {
          browser.assert.success();
          browser.assert.text('span#name', 'Armegio');
          browser.assert.text('span#surname', 'Vespucci');
          browser.assert.elements('span#dates', 1);
          done();
        });
      });
    });


  });
});

The terminal gives out these error messages

Restarting 'server.js'
Listening on port 3000
Running Tests...
(node:99889) [DEP0176] DeprecationWarning: fs.F_OK is deprecated, use fs.constants.F_OK instead
(Use `node --trace-deprecation ...` to show where the warning was created)


  Unit Tests
    Basic Assertions
      ✔ #isNull, #isNotNull
      ✔ #isDefined, #isUndefined
      ✔ #isOk, #isNotOk
      ✔ #isTrue, #isNotTrue
    Equality
      ✔ #equal, #notEqual
      ✔ #strictEqual, #notStrictEqual
      ✔ #deepEqual, #notDeepEqual
    Comparisons
      ✔ #isAbove, #isAtMost
      ✔ #isBelow, #isAtLeast
      ✔ #approximately
    Arrays
      ✔ #isArray, #isNotArray
      ✔ Array #include, #notInclude
    Strings
      ✔ #isString, #isNotString
      ✔ String #include, #notInclude
      ✔ #match, #notMatch
    Objects
      ✔ #property, #notProperty
      ✔ #typeOf, #notTypeOf
      ✔ #instanceOf, #notInstanceOf

  Functional Tests
    Integration tests with chai-http
      ✔ Test GET /hello with no name
      ✔ Test GET /hello with your name
      ✔ Send {surname: "Colombo"}
      ✔ Send {surname: "da Verrazzano"}

  Functional Tests with Zombie.js
(node:99889) [DEP0044] DeprecationWarning: The `util.isArray` API is deprecated. Please use `Array.isArray()` instead.
    Headless browser
      ✔ should have a working "site" property
    "Famous Italian Explorers" form
      1) Submit the surname "Colombo" in the HTML form
      2) Submit the surname "Vespucci" in the HTML form


  23 passing (64ms)
  2 failing

  1) Functional Tests with Zombie.js
       "Famous Italian Explorers" form
         Submit the surname "Colombo" in the HTML form:
     Uncaught TypeError: isRegExp is not a function
      at assertMatch (node_modules/zombie/lib/assert.js:22:7)
      at Assert.text (node_modules/zombie/lib/assert.js:184:5)
      at /Users/qingyan/Desktop/Computing Self Study/FCC Quality Assurance/Learn Quality Assurance with Chai/boilerplate-mochachai/tests/2_functional-tests.js:94:26
      at EventLoop.done (node_modules/zombie/lib/eventloop.js:424:9)
      at Object.onceWrapper (node:events:622:28)
      at EventLoop.emit (node:events:520:35)
      at Immediate.<anonymous> (node_modules/zombie/lib/eventloop.js:515:65)
      at process.processImmediate (node:internal/timers:505:21)

  2) Functional Tests with Zombie.js
       "Famous Italian Explorers" form
         Submit the surname "Vespucci" in the HTML form:
     Uncaught TypeError: isRegExp is not a function
      at assertMatch (node_modules/zombie/lib/assert.js:22:7)
      at Assert.text (node_modules/zombie/lib/assert.js:184:5)
      at /Users/qingyan/Desktop/Computing Self Study/FCC Quality Assurance/Learn Quality Assurance with Chai/boilerplate-mochachai/tests/2_functional-tests.js:106:26
      at EventLoop.done (node_modules/zombie/lib/eventloop.js:424:9)
      at Object.onceWrapper (node:events:622:28)
      at EventLoop.emit (node:events:520:35)
      at Immediate.<anonymous> (node_modules/zombie/lib/eventloop.js:515:65)
      at process.processImmediate (node:internal/timers:505:21)

All the tests except the first one is failing, which I think is caused by perhaps some old version of Zombie.js being used in the challenge. Any help on how to solve this problem would be appreciated, thanks!

Hi @chuqingyan123

Check for typos in the name.

Happy coding

Hi, I saw that there was a typo in the name of Amerigo Vespucci, and I have fixed it, but that isnt the challenge step I am at right now. I am at

Challenge Link

this step of the course, which is checking for Cristoforo Colombo and how to assert whether the HTML form submission works through Zombie.js.

Within tests/2_functional-tests.js, in the 'Submit the surname "Colombo" in the HTML form' test (// #5), automate the following:

Fill in the form with the surname Colombo

Press the submit button

And within the pressButton callback:

Assert that status is OK 200

Assert that the text inside the element span#name is 'Cristoforo'

Assert that the text inside the element span#surname is 'Colombo'

Assert that the element(s) span#dates exist and their count is 1

Do not forget to remove the assert.fail() call.

This was the instructions given, and right now my code portion looks like this:

suite('"Famous Italian Explorers" form', function () {
    // #5
    test('Submit the surname "Colombo" in the HTML form', function (done) {
      browser.fill('surname', 'Colombo').then(() => {
        browser.pressButton('submit', () => {
          browser.assert.success();
          browser.assert.text('span#name', 'Cristoforo');
          browser.assert.text('span#surname', 'Colombo');
          browser.assert.elements('span#dates', 1);
          done();
        });
      });
    });
    // #6
    test('Submit the surname "Vespucci" in the HTML form', function (done) {
      assert.fail();
    });


  });
});

I have removed the parts that I had done for the next step just in case it was affecting the tests for my current step.

I have filled in the code for Cristoforo Colombo, and I am managing to pass FCC’s tests for the Chai assertions about the content itself, but I am just failing the first test case due to an error that seems out of my control.

Functional Tests with Zombie.js
(node:19676) [DEP0044] DeprecationWarning: The `util.isArray` API is deprecated. Please use `Array.isArray()` instead.
    Headless browser
      ✔ should have a working "site" property
    "Famous Italian Explorers" form
      1) Submit the surname "Colombo" in the HTML form
      2) Submit the surname "Vespucci" in the HTML form


  23 passing (66ms)
  2 failing

  1) Functional Tests with Zombie.js
       "Famous Italian Explorers" form
         Submit the surname "Colombo" in the HTML form:
     Uncaught TypeError: isRegExp is not a function
      at assertMatch (node_modules/zombie/lib/assert.js:22:7)
      at Assert.text (node_modules/zombie/lib/assert.js:184:5)
      at /Users/qingyan/Desktop/Computing Self Study/FCC Quality Assurance/Learn Quality Assurance with Chai/boilerplate-mochachai/tests/2_functional-tests.js:94:26
      at EventLoop.done (node_modules/zombie/lib/eventloop.js:424:9)
      at Object.onceWrapper (node:events:622:28)
      at EventLoop.emit (node:events:520:35)
      at Immediate.<anonymous> (node_modules/zombie/lib/eventloop.js:515:65)
      at process.processImmediate (node:internal/timers:505:21)

  2) Functional Tests with Zombie.js
       "Famous Italian Explorers" form
         Submit the surname "Vespucci" in the HTML form:
     AssertionError: assert.fail()
      at Context.<anonymous> (tests/2_functional-tests.js:103:14)
      at process.processImmediate (node:internal/timers:505:21)

As you can see inside the terminal, it is showing that I am failing the test suite due to

Uncaught TypeError: isRegExp is not a function
      at assertMatch (node_modules/zombie/lib/assert.js:22:7)
      at Assert.text (node_modules/zombie/lib/assert.js:184:5)
      at /Users/qingyan/Desktop/Computing Self Study/FCC Quality Assurance/Learn Quality Assurance with Chai/boilerplate-mochachai/tests/2_functional-tests.js:94:26
      at EventLoop.done (node_modules/zombie/lib/eventloop.js:424:9)
      at Object.onceWrapper (node:events:622:28)
      at EventLoop.emit (node:events:520:35)
      at Immediate.<anonymous> (node_modules/zombie/lib/eventloop.js:515:65)
      at process.processImmediate (node:internal/timers:505:21)

this error, which seems to be because Zombie.js is already deprecated, according to their official site.

Upon reading another post on the forum, it seems that the issue is due to the deprecation of Zombie.js. I found a workaround that is to downgrade the version of node being used in the project. The steps are:

In terminal, enter

nvm --version

If you see a version number beyond node 16, continue to do the next steps:

nvm install 16

then once done,

nvm use 16

Now Zombie.js should work properly and no more errors should show up.