用量角器获取伪元素的值

时间:2013-11-11 21:51:26

标签: javascript angularjs protractor e2e-testing angularjs-e2e

我想验证伪元素的文本内容。使用ptor.executeScript("window.getComputedStyle(jQuery('.my-class')[0], ':after').content").then(function(data){ console.log(arguments) // {'0':null} });

返回的承诺

我也试过按预期放弃,但我猜这是因为同样的原因。

由于CSS声明指向了元素的一个属性,我应该尝试读取该属性吗?

2 个答案:

答案 0 :(得分:9)

executeScript会等待您返回一个值 - 所以您需要这样做:

ptor.executeScript("return window.getComputedStyle(jQuery('.my-class')[0], ':after').content")
    .then(function(data){ console.log(arguments)});

答案 1 :(得分:1)

作为一个更新的答案基于我们的好朋友Julie又名"量角器向导。"

我没有jQuery可用来获取我的pseduo元素所以我这样做了......

describe('#swPopover Component', () => {
    it('should show the popover message when hovered', () => {
      browser.actions().mouseMove(objectsPage.popover).perform();
      browser.executeScript('return window.getComputedStyle(document.querySelector(".sw-popover"), ":after").content')
        .then(data => expect(data).toBe('"I am the popover text"'));
    });
  });
相关问题