Torc
Torc

Reputation: 1322

Webdriver.io Comparator Operator

I am trying to ensure that the number of elements that are appearing on a webpage is greater than zero. I am unaware of a way to assert that the elements I need are correctly populating. Below is what I have so far, but it is erring on the last line (i.e. assert.equal(fieldsButtonList, "less than zero");

const assert = require("assert");
import header from "../pages/header.page";

describe("View Report", () => {
  it("Only data fields that were selected, will display in the result’s column", () => {
    browser.url(""); // Navigate to the FDA app
    browser.maximizeWindow(); // ensure that the window is maximized so that everything can be viewed
    header.searchAndVisualizeHeader.click(); // Select the "Search & Visualize" tab
    const searchTitle = $("h1").getText();
    assert(searchTitle, "Show");
  });

  it("There should be buttons", () => {
    assert.equal(browser.$$(".data-source").length, 4);
    const ndcButton = $(
      '//*[@id="data-sidebar-item-0"]/div/div/div/div[2]/button'
    );
    ndcButton.click();
  });

  it("There should be fields", () => {
    const fieldsButton = browser.$('//*[@id="data-sidebar-item-1-heading"]');
    fieldsButton.click();
    const fieldsButtonList = () => {
      if (browser.$$(".data-field").length > 0) {
        return "greater than zero";
      } else {
        return "less than zero";
      }
    };
    //assert.equal(fieldsButtonList, "less than zero");
  });
});

The error that I am getting is as follows (running in latest Chrome Version 77.0.3865.120 (Official Build) (64-bit)):

[0-0] 2019-10-18T13:15:58.821Z INFO webdriver: COMMAND findElement("xpath", "//*[@id="data-sidebar-item-1-heading"]")
[0-0] 2019-10-18T13:15:58.821Z INFO webdriver: [POST] http://127.0.0.1:4444/session/d3813ab85ffd49ae3f3ba4c4b2df033f/element
[0-0] 2019-10-18T13:15:58.821Z INFO webdriver: DATA { using: 'xpath',
  value: '//*[@id="data-sidebar-item-1-heading"]' }
[0-0] 2019-10-18T13:15:58.842Z INFO webdriver: RESULT { 'element-6066-11e4-a52e-4f735466cecf': '885111a2-8a1e-47df-ba60-ce764f56e58e' }
[0-0] 2019-10-18T13:15:58.846Z INFO webdriver: COMMAND elementClick("885111a2-8a1e-47df-ba60-ce764f56e58e")
[0-0] 2019-10-18T13:15:58.846Z INFO webdriver: [POST] http://127.0.0.1:4444/session/d3813ab85ffd49ae3f3ba4c4b2df033f/element/885111a2-8a1e-47df-ba60-ce764f56e58e/click
[0-0] AssertionError [ERR_ASSERTION] in "View Report Fields should appear"
[Function: fieldsButtonList] == 'less than zero'

Upvotes: 0

Views: 74

Answers (1)

Naveen Thiyagarajan
Naveen Thiyagarajan

Reputation: 588

See the error: [Function: fieldsButtonList] == 'less than zero' that is because the function reference is tried to compare against the value less than zero.

Issue is you are not calling the function at the line assert.equal(fieldsButtonList, "less than zero");.

You are still creating a reference to it.

Please replace the line of code as: assert.equal(fieldsButtonList(), "less than zero");

Let us know this works.

Thanks, Naveen

Upvotes: 2

Related Questions