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.

[Quality Assurance and Testing with Chai] Example functional test failing

See original GitHub issue

Describe your problem and - if possible - how to reproduce it

When submitting my solution for Run Functional Tests using a Headless Browser all tests are passing except the first one - All tests should pass After inspecting the glitch logs I found out that the example test is also failing:

 1) Functional Tests

       e2e Testing with Zombie.js

         "Famous Italian Explorers" form

           #example - submit the input "surname" : "Polo":

     TypeError: browser.fill(...).pressButton is not a function

      at Context.<anonymous> (tests/2_functional-tests.js:217:12)

This is the test function from the example:

test('#example - submit the input "surname" : "Polo"', function(done) {
        
        browser
          .fill('surname', 'Polo')
          .pressButton('submit', function(){
            // pressButton is ## Async ##.  
            // It waits for the ajax call to complete...

            // assert that status is OK 200
            browser.assert.success();
            // assert that the text inside the element 'span#name' is 'Marco'
            browser.assert.text('span#name', 'Marco');
            // assert that the text inside the element 'span#surname' is 'Polo'
            browser.assert.text('span#surname', 'Polo');
            // assert that the element(s) 'span#dates' exist and their count is 1
            browser.assert.element('span#dates', 1);

            done();   // It's an async test, so we have to call 'done()''
          });
      });

And this is my solution:

test('submit "surname" : "Colombo" - write your e2e test...', function(done) {

        // fill the form...
        // then submit it pressing 'submit' button.
        //
        // in the 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
        browser
          .fill('surname', 'Colombo')
          .pressButton('submit', function(){
            
            /** YOUR TESTS HERE, Don't forget to remove assert.fail() **/
            
            // assert that status is OK 200
            browser.assert.success();
            // assert that the text inside the element 'span#name' is 'Cristoforo'
            browser.assert.text('span#name', 'Cristoforo');
            // assert that the text inside the element 'span#surname' is 'Colombo'
            browser.assert.text('span#surname', 'Colombo');
            // assert that the element(s) 'span#dates' exist and their count is 1
            browser.assert.element('span#dates', 1);
                        
            done();   // It's an async test, so we have to call 'done()''
          });
      });

Add a Link to the page with the problem

Quality Assurance and Testing with Chai - Run Functional Tests using a Headless Browser

Tell us about your browser and operating system

  • Browser Name: Chrome
  • Browser Version: 67.0.3396.99 (Official Build) (64-bit)
  • Operating System: Windows 10

If possible, add a screenshot here

image

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
lucasarvelocommented, Nov 21, 2019

Ok, I found the problem. The test in the challenge is testing for a single quotation.

- text: You should assert that the text inside the element 'span#name' is 'Cristoforo'.
    testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=4')
      .then(data => { 
        assert.equal(data.assertions[1].method, 'browser.text'); 
        assert.equal(data.assertions[1].args[0], '\'span#name\''); 
        assert.equal(data.assertions[1].args[1], '\'Cristoforo\'');
      }, 
    xhr => { throw new Error(xhr.responseText); })

Here '\'span#name\''and here '\'Cristoforo\''

I just replace the double quotations for single quotations and the local and challenge tests pass.

Should be use assert.match() instead of assert.equal() in the challenge test? Maybe replace double quotation for a single in assertion-analyser.js??

2reactions
moigithubcommented, Jul 28, 2018

on version 6.2.1 .fill method doesnt return the Browser object anymore soo its not possible to do method chain

and .element method only check if the element exist to check for “count” element, there are another method named elements (plural) which accept a count parameter

Read more comments on GitHub >

github_iconTop Results From Across the Web

Quality Assurance and Testing with Chai | FreeCodeCamp
I go through the quality assurance and testing with Chai portion of FreeCodeCamp. The beginning tests were super easy, but the last four ......
Read more >
Run Functional Tests Using a Headless Browser I &II -- One ...
Quality Assurance and Testing with Chai - Run Functional Tests Using a Headless Browser I &II -- One of the tests keeps failing....
Read more >
Testing with Mocha and Chai
Let's learn about unit testing our code using Mocha, which is a light-weight Node.js test framework, and Chai, which is a TDD assertion ......
Read more >
Testing Node.js Code with Mocha and Chai
In this guide - learn the basics of testing in JavaScript with Mocha and Chai - focusing on Unit Testing and creating test...
Read more >
How to Write Simple Unit Tests in JavaScript with Mocha ...
Unit testing is the most foundational level of software testing. In this level of testing, individual functionality, modules, procedures or even ...
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