什么时候比较计数和元素值不起作用?

时间:2019-04-09 09:05:47

标签: protractor

这是我的代码:

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);
});

我跑步时遇到失败: 登录页面应检查“待处理休假”的计数   讯息:

  

[31m预期'37'为37. [0m堆栈:       错误:预期失败           在E:\ Selenium \ Users \ Rafeeq \ Proc_wfm \ spec.js:119:108           在ManagedPromise.invokeCallback_(E:\ Selenium \ Users \ Rafeeq \ Proc_wfm \ node_modules \ selenium-webdriver \ lib \ promise.js:1376:14)           在TaskQueue.execute_(E:\ Selenium \ Users \ Rafeeq \ Proc_wfm \ node_modules \ selenium-webdriver \ lib \ promise.js:3084:14)           在TaskQueue.executeNext_(E:\ Selenium \ Users \ Rafeeq \ Proc_wfm \ node_modules \ selenium-webdriver \ lib \ promise.js:3067:27)           在asyncRun(E:\ Selenium \ Users \ Rafeeq \ Proc_wfm \ node_modules \ selenium-webdriver \ lib \ promise.js:2927:27)           在E:\ Selenium \ Users \ Rafeeq \ Proc_wfm \ node_modules \ selenium-webdriver \ lib \ promise.js:668:7           在process._tickCallback(internal / process / next_tick.js:68:7)

1 个答案:

答案 0 :(得分:0)

element.all().count()返回一个Number,但是getText()返回一个String

expect().toBe()将比较数据的类型和值,等同于===

您需要将数字转换为字符串。

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