Search code examples
javascripttestingautomated-testsmocha.jszombie.js

check multiple classes with zombie.js


Using zombie and mocha to test the frontend of the website. Zombie documentation says:

assert.className(selection, className, message): Asserts that selected element(s) has that and only that class name. May also be space-separated list of class names.

Testing the following code gives a failre:

it('Check if section class item company_bnr ', function(done){
    browser.visit(url+'/aboutus', function () {
    browser.assert.className('section','company_bnr item');
        done();
    });
});

as follows:

About Us Page
1) Check if section class item company_bnr 




0 passing (2s)
  1 failing

  1) About Us Page Check if section class item company_bnr :
  Uncaught AssertionError: Expected element "section" to have class "company_bnr item", found "item"
  + expected - actual

  -item
  +company_bnr item

If I make the test code as:

it('Check if section class item company_bnr ', function(done){
    browser.visit(url+'/aboutus', function () {
    browser.assert.className('section','item');
        done();
    });
});

I get the following output:

About Us Page
1) Check if section class item company_bnr 




 0 passing (2s)
  1 failing

  1) About Us Page Check if section class item company_bnr :
  Uncaught AssertionError: Expected element "section" to have class "item", found "company_bnr item"
  + expected - actual

  -company_bnr item
  +item

Solution

  • the issue Appears that Zombie assert iterates for all tags and stops when gets an mismatch and reports it. Give absolute path of tag like:

    browser.assert.attribute('div section header div div span a','href','https://www.website.com');