Quality Assurance and Testing

I don’t know why my code for these final two tests aren’t passing:

type or paste code const chai = require("chai");
const assert = chai.assert;

const server = require("../server");

const chaiHttp = require("chai-http");
chai.use(chaiHttp);

suite("Functional Tests", function() {
  suite("Integration tests with chai-http", function() {
    // #1
    test("Test GET /hello with no name", function(done) {
      chai
        .request(server)
        .get("/hello")
        .end(function(err, res) {
          assert.equal(res.status, 200);
          assert.equal(res.text, "hello Guest");
          done();
        });
    });
    // #2
    test("Test GET /hello with your name", function(done) {
      chai
        .request(server)
        .get("/hello?name=se23")
        .end(function(err, res) {
          assert.equal(res.status, 200);
          assert.equal(res.text, "hello se23");
          done();
        });
    });
    // #3
    test('send {surname: "Colombo"}', function(done) {
      chai
        .request(server)
        .put("/travellers")

        .end(function(err, res) {
          assert.equal(res.status, 200);
          assert.equal(res.type, "application/json");
          assert.equal(res.body.name, "Cristoforo");
          assert.equal(res.body.surname, "Colombo");

          done();
        });
    });
    // #4
    test('send {surname: "da Verrazzano"}', function(done) {
      chai
        .request(server)
        .put("/travellers")
        .send({ surname: "da Verrazzano" })
        .end((error, res) => {
          assert.equal(res.status, 200);
          assert.equal(res.type, "application/json");
          assert.equal(res.body.name, "Giovanni");
          assert.equal(res.body.surname, "da Verrazzano");
          done();
        });
    });
  });
});

const Browser = require("zombie");
Browser.site = "https://fcc-qa-s23.glitch.me/";

suite("Functional Tests with Zombie.js", function() {
  const browser = new Browser();

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

  suite('"Famous Italian Explorers" form', function() {
    // #5
    test('submit "surname" : "Colombo" - write your e2e test...', function(done) {
      browser.fill("surname", "Colombo").pressButton("submit", function() {
        browser.assert.success();
        browser.assert.text("span#name", "Cristoforo");
        browser.assert.text("span#surname", "Colombo");
        browser.assert.element("span#dates", 1);
        done();
      });
    });
    // #6
    test('submit "surname" : "Vespucci" - write your e2e test...', function(done) {
      browser.fill("surname", "Vespucci").pressButton("submit", function() {
        browser.assert.success();
        browser.assert.text("span#name", "Amerigo");
        browser.assert.text("span#surname", "Vespucci");
        browser.assert.element("span#dates", 1);
        done();
      });
    });
  });
});


https://boilerplate-mochachai.joshhayles1.repl.co


**Your browser information:**

User Agent is: <code>Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36</code>

**Challenge:**  Simulate Actions Using a Headless Browser

**Link to the challenge:**
https://www.freecodecamp.org/learn/quality-assurance/quality-assurance-and-testing-with-chai/simulate-actions-using-a-headless-browser

Can’t say I’ll be able to help with this, but I’m sure someone can. However it might be difficult for them without a little more information.

Could you post a link to the lesson? What errors are you getting? What have you tried? Do you have an idea about were the issue is?

I posted the link in another post. I’ve tried everything, and as a last resort when I knew the code was correct, I copied the solution and pasted it in. It’s still not working. That’s why I’m wondering if it’s a bug somewhere else.

1 Like

The Zombie.js tests are unreliable on Replit. Usually, they will pass at some point if you try enough times.

I’d suggest just doing them locally instead.

Or you can try on Glitch.

Thank you. I’m trying to do it locally. It does look like my code isn’t working. Can you help me spot how to fix these three errors?

Can you post your Replit? Oh I see you have it on Glitch

Edit: I’m confused you have this

Browser.site = "https://fcc-qa-s23.glitch.me/";

But then you also have a link to Replit

https://boilerplate-mochachai.joshhayles1.repl.co


Are you sure you set the Browser.site correctly?

Sorry … I’m using the local site now: http://localhost:3000/

But I’m still getting the same three errors

It looks like you are missing the .then

Here is the example code. See how the browser.pressButton is inside the .then

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();
    });
  });
});

You are also missing .send({ surname: 'Colombo' }) where the empty line is

test('send {surname: "Colombo"}', function(done) {
  chai
    .request(server)
    .put("/travellers")

    .end(function(err, res) {
      assert.equal(res.status, 200);
      assert.equal(res.type, "application/json");
      assert.equal(res.body.name, "Cristoforo");
      assert.equal(res.body.surname, "Colombo");

      done();
    });
});

Actually, it’s still not passing me on the FreeCodeCamp test, but my local tests are passing …


Uploading: Screen Shot 2022-05-23 at 5.15.15 PM.png…

Post your new code, please.

const chai = require("chai");
const assert = chai.assert;

const server = require("../server");

const chaiHttp = require("chai-http");
chai.use(chaiHttp);

suite("Functional Tests", function() {
  suite("Integration tests with chai-http", function() {
    // #1
    test("Test GET /hello with no name", function(done) {
      chai
        .request(server)
        .get("/hello")
        .end(function(err, res) {
          assert.equal(res.status, 200);
          assert.equal(res.text, "hello Guest");
          done();
        });
    });
    // #2
    test("Test GET /hello with your name", function(done) {
      chai
        .request(server)
        .get("/hello?name=se23")
        .end(function(err, res) {
          assert.equal(res.status, 200);
          assert.equal(res.text, "hello se23");
          done();
        });
    });
    // #3
    test('send {surname: "Colombo"}', function(done) {
      chai
        .request(server)
        .put("/travellers")
        .send({ surname: "Colombo" })
        .end(function(err, res) {
          assert.equal(res.status, 200);
          assert.equal(res.type, "application/json");
          assert.equal(res.body.name, "Cristoforo");
          assert.equal(res.body.surname, "Colombo");

          done();
        });
    });
    // #4
    test('send {surname: "da Verrazzano"}', function(done) {
      chai
        .request(server)
        .put("/travellers")
        .send({ surname: "da Verrazzano" })
        .end((error, res) => {
          assert.equal(res.status, 200);
          assert.equal(res.type, "application/json");
          assert.equal(res.body.name, "Giovanni");
          assert.equal(res.body.surname, "da Verrazzano");
          done();
        });
    });
  });
});

const Browser = require("zombie");
Browser.site = "http://localhost:3000/";

suite("Functional Tests with Zombie.js", function() {
  const browser = new Browser();

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

  suite('"Famous Italian Explorers" form', function() {
    // #5
    test('submit "surname" : "Colombo" - write your e2e test...', 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 "surname" : "Vespucci" - write your e2e test...', function(done) {
      browser.fill('surname', 'Vespucci').then(() => {
        browser.pressButton('submit', () => {
        browser.assert.success();
        browser.assert.text('span#name', 'Amerigo');
        browser.assert.text('span#surname', 'Vespucci');
        browser.assert.elements('span#dates', 1);
        done();
        });
      });
    });
  });
});   

You removed some code.

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

That should be between the suiteSetup code and the first suite('"Famous Italian Explorers" form'...

Edit: It should go on line: 74 in your code if that helps.

Nevermind, it worked! I had to npm start again. Thank you so much for your help! Do you mind me asking if you have a QA Background?

1 Like

Not at all.

I have completed the challenges so I can do a code diff (visually and using a tool) to look for errors or differences in the code.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.