【问题标题】:In protractor cucumber, getAttribute(Value) is returning Object (browser_, then, ...) instead of returning data在量角器黄瓜中,getAttribute(Value) 返回 Object (browser_, then, ...) 而不是返回数据
【发布时间】:2019-01-18 23:20:39
【问题描述】:

在尝试断言在以下网页中输入的日期时 getAttribute('value') 返回 "Object (browser_, then, ...)" 而不是 value 。 https://material.angular.io/components/datepicker/examples

以下是错误代码的sn-p

expect(element(by.xpath('//input[@id="mat-input-2"]')).getAttribute('value')).to.eventually.equal(element(by.xpath('//input[@id="mat-input-2"]')).getAttribute('value')).and.notify(callback);

为此,我收到以下错误 AssertionError: 预期 '1/6/2019' 等于 { Object (browser_, then, ...) }

     var date=element(by.xpath('//input[@id="mat-input-2"]')).getAttribute('value').getText();
  console.log(date);

上面代码的 console.log 正在返回类似这样的内容。

ElementFinder {
browser_:
  ProtractorBrowser {
 controlFlow: [Function],
 schedule: [Function],
 setFileDetector: [Function],
 getExecutor: [Function],
 getSession: [Function],
 getCapabilities: [Function],
 quit: [Function],
 actions: [Function],
 touchActions: [Function],
 executeScript: [Function],
 executeAsyncScript: [Function],
 call: [Function],
 wait: [Function],
 sleep: [Function],
 getWindowHandle: [Function],
 getAllWindowHandles: [Function],
 getPageSource: [Function],
 close: [Function],
 getCurrentUrl: [Function],
 getTitle: [Function],
 findElementInternal_: [Function],
 findElementsInternal_: [Function],
 takeScreenshot: [Function],
 manage: [Function],
 switchTo: [Function],
 driver:
  Driver {
    flow_: [ControlFlow],
    session_: [ManagedPromise],
    executor_: [Executor],
    fileDetector_: null,
    onQuit_: undefined,
    getNetworkConnection: [Function],
    setNetworkConnection: [Function],
    toggleAirplaneMode: [Function],
    toggleWiFi: [Function],

请为此提供一些解决方案

【问题讨论】:

  • 对于断言API:expect(actual_value).to.xxx(expect_value),它不支持actual_valueexpect_value都是promise。记不太清了,好像只允许actual_value 作为promise。

标签: protractor cucumberjs


【解决方案1】:

试试看:

const elementOne = element(by.xpath('//input[@id="mat-input-2"]');
const elementTwo = element(by.xpath('//input[@id="mat-input-2"]');

return elementOne.getAttribute('value').then((elementOneValue) => {
    return expect(elementTwo.getAttribute('value')).to.eventually.equal(elementOneValue).and.notify(callback);
});

顺便说一句。两个元素都有相同的选择器——它们必须相等。

【讨论】:

  • 我又面临一个问题。 xpath 的日期如下。 //table[@class="mat-calendar-table"]/tbody/tr/td[@aria-label="2019 年 1 月 1 日"]。我想从 feture 文件中传递日期,如下所示“当输入日期“2019 年 1 月 6 日”时,我无法动态更新 xpath
  • @sowjanya 只是说清楚......这里没有测试任何东西。它们是相同的元素,所以它们总是相等的。
猜你喜欢
  • 2015-03-23
  • 2019-10-18
  • 2020-06-25
  • 2021-03-17
  • 1970-01-01
  • 2021-10-17
  • 2021-03-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多