0

I wrote following condition in Protractor test:

expect(dialog.getAttribute('style')).toContain('display: none');

That raises an error:

Expected [ 'display: none; width: 400px;' ] to contain 'display: none'.

So, I've tried to add a call to .toString() method after getAttribute, but it returns `[object Object]'. The error is as follows:

Expected '[object Object]' to contain 'display: none'.

I've tried answers posted here: Converting an object to a string but they seems to not work but they're also not working.

How should I amend my code, so that test will pass?

matandked
  • 1,527
  • 4
  • 26
  • 51
  • Show the definition of variable `dialog` – yong May 29 '18 at 15:48
  • `const dialog = element(by.css('p-dialog[header="Deleting"]'));` Since te suggested solution for this issue was to use `element` instead of `all`, I wonder if I should delete this question. – matandked Jun 04 '18 at 11:54

1 Answers1

0

Because you declare the variable dialog as an element list, like element.all(), so getAttribute() will return a list.

Please clarify you hope dialog be a single element or an element list.

yong
  • 13,357
  • 1
  • 16
  • 27
  • In my case, I provide such locator, that only one element should be returned. I've tried to add a call to get method (`.get(0)`), but it returned me an error. Should I use `first` or `last` instead to obtain one element only? – matandked May 29 '18 at 19:01
  • pleas show the code how you declare/init the variable `dialog`. – yong May 29 '18 at 23:18