Simulate Actions Using a Headless Browser

My code:

const Browser = require('zombie');
Browser.site = 'https://boilerplate-mochachai.luizfernandorg.repl.co';
const browser = new Browser();
suite('Functional Tests with Zombie.js', function() {
  this.timeout(5000);
  
  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) {
      assert.fail();

      done();
    });
    // #6
    test('Submit the surname "Vespucci" in the HTML form', function (done) {
      assert.fail();

      done();
    });
  });*/
});

All the tests that are not commented out pass, but the page does not open, the page opens at the beginning when the test is running, but at the end of the test the page crash, if you uncomment ‘Headless browser’, it gives an error 502. What turns the test at the exercise to fail because there is no page to test.

2 Likes

Not entirely sure what is going on, but it looks to be caused by the Functional Tests part.

You do have one of the done() calls in the wrong place but after fixing that I also have to comment out the this.timeout(5000); at the top of the Functional Tests function. Then the page stays up and passes the challenge I think you are on and is just failing the last two tests.

You replit

1 Like

Lasjorg thank you, it passes the test, but for some reason, the page still does not show.

2 Likes

hi @luizfernandorg “done” is a callback function just add to it a parenthesis
code :

const Browser = require('zombie');
Browser.site = 'https://boilerplate-mochachai.luizfernandorg.repl.co';
const browser = new Browser();
suite('Functional Tests with Zombie.js', function() {
  this.timeout(5000);
  
  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) {
      assert.fail();

      done();
    });
    // #6
    test('Submit the surname "Vespucci" in the HTML form', function (done) {
      assert.fail();

      done();
    });
  });*/
});
1 Like

502 errors also tend to come from the disconnection/miscommunication between repl and freecodecamp.

I am under the impression that whenever we press Run, repl will create a websocket/bridge asking for a connection to the Freecodecamp test page, where 502 means that connection is not available (or the two end points of both sides are “not lining up”).

My solution is to reload the freecodecamp ending, then stop and run the repl project again.