0
votes

This is my code:

element.all(by.repeater("el in leaveApproved | orderBy:'Applied_Date' track by $index"))
  .count()
  .then(function(str){
     element(by.linkText('Dashboard')).click();
     browser.sleep(500);
     expect(element(by.xpath(
            "//*[@id='divDashboardAppCtl']/div[2]/div[2]/div[1]/div/div[2]/h1"))
       .getText()).toBe(str);
});

When I run, I got Failures: login page Should check the count for Request Pending leave Message:

[31m Expected '37' to be 37.[0m Stack: Error: Failed expectation at E:\Selenium\Users\Rafeeq\Proc_wfm\spec.js:119:108 at ManagedPromise.invokeCallback_ (E:\Selenium\Users\Rafeeq\Proc_wfm\node_modules\selenium-webdriver\lib\promise.js:1376:14) at TaskQueue.execute_ (E:\Selenium\Users\Rafeeq\Proc_wfm\node_modules\selenium-webdriver\lib\promise.js:3084:14) at TaskQueue.executeNext_ (E:\Selenium\Users\Rafeeq\Proc_wfm\node_modules\selenium-webdriver\lib\promise.js:3067:27) at asyncRun (E:\Selenium\Users\Rafeeq\Proc_wfm\node_modules\selenium-webdriver\lib\promise.js:2927:27) at E:\Selenium\Users\Rafeeq\Proc_wfm\node_modules\selenium-webdriver\lib\promise.js:668:7 at process._tickCallback (internal/process/next_tick.js:68:7)

1
make .toBe('37'); you are getting the value with ' surrounded. - Madhan

1 Answers

0
votes

element.all().count() return a Number, but getText() return a String.

expect().toBe() will compare both the Type and Value of the data, equivalent to ===

You need to convert the number to string.

expect(element(by.xpath(
            "//*[@id='divDashboardAppCtl']/div[2]/div[2]/div[1]/div/div[2]/h1"))
       .getText()).toBe(str+'');