jeudi 27 août 2020

How to compare object values in a config to hrefs on a website

This is a follow-up to the question I previously posted here

In this question, I am trying to test the href values on the website to what is stored in the config file.

URL: https://wdwthemeparks.com

Config file (located at Resources/config.json)

{
    "url": "https://wdwthemeparks.com",
    "topMenuNav": {
        "All": "/all/",
        "News": "/news/",
        "Press Releases": "/press/",
        "Rumors": "/rumors/",
        "About": "/about/",
        "Contact": "/contact/",
        "Refurbishments": "/refurbishments/"
    }
}

Selectors located at Objects/header.js

import { Selector, t } from 'testcafe';

class Header {

    constructor() {
        this.topMenuNav = Selector('.top-header-menu')
        this.topMenuNavItem = Selector(this.topMenuNav).find('a');
    }
}

export default new Header();

Tests located at Tests/topMenu.js

import { Selector } from 'testcafe';
import Header from '../Objects/header';

const config = require('../Resources/config.json');

fixture `Check Top Menu`
    .page(config.url)
    .beforeEach( async t => {
        await t.maximizeWindow();
    });

test
    .meta({ desktop: 'true'})
    ('Check Top Menu Items', async t => {

        const topMenuNavKeys = Object.keys(config.topMenuNav);
        const topMenuNavValues = Object.values(config.topMenuNav);

        await t.expect(Header.topMenuNav.visible).ok('Top Menu Nav is NOT visible');
        
        for (const key of topMenuNavKeys) {
            await t.expect(Header.topMenuNavItem.withText(key).exists).ok(`"${key}" Top Menu Nav key does NOT match config`);
          }

// THE PROBLEM I AM HAVING IS HERE IN THIS PART OF THE CODE
          for (const value of topMenuNavValues) {
            await t.expect(Header.topMenuNavItem.getAttribute('href')).contains(value, `"${value}" Top Menu Nav value does NOT match config`);
          }
});

I get the following error message from TestCafe:

× Check Top Menu Items

   1) AssertionError: "/news/" Top Menu Nav value does NOT match config: expected 'https://wdwthemeparks.com/all/' to include '/news/'

      + expected - actual

      -'https://wdwthemeparks.com/all/'
      +undefined


      Browser: Chrome 85.0.4183.83 / Windows 10

         32 |                   await t.expect(Header.topMenuNavItem.withText(key).exists).ok(`"${key}" Top Menu Nav key does NOT match config`);
         33 |             }
         34 |
         35 |             for (const value of topMenuNavValues) {
         36 |                   console.log(Header.topMenuNavItem.getAttribute('href'));
       > 37 |                   await t.expect(await Header.topMenuNavItem.getAttribute('href')).contains(value, `"${value}" Top Menu Nav value does NOT match config`);
         38 |             }
         39 |});
         40 |

         at <anonymous> (C:\Users\J\Repos\wdwthemeparks-automation\Tests\topMenu.js:37:69)



 1/1 failed (7s)

I'm not sure what I'm doing wrong.

Aucun commentaire:

Enregistrer un commentaire