I got an object like:
$scope.project = {name: 'whatever', description: 'blabla', another: 'another'};
To debug this, i enter in repl mode and try to see what "project" has. When i define project variable as below, and call it, it returns my object, but when i try to access its keys (project.name), i get undefined. If i do Object.keys(project) i am getting the page object methods like click, getAttribute, etc.
Any ideas on how can i have access to the original object keys?
View side:
<h1 id="foo">{{project.name}}</h1>
Test side:
var project = element(by.id('foo')).evaluate('project');
evaluate
uses executeScript
behind the scenes. It returns an ElementFinder
which resolves to the object you are looking for:
var project;
element(by.id('foo')).evaluate('project').then(function(value) {
project = value;
});
The documentation says:
which resolves to the evaluated expression for each underlying element. The result will be resolved as in webdriver.WebDriver.executeScript. In summary - primitives will be resolved as is, functions will be converted to string, and elements will be returned as a WebElement.
Also, check out Accessing Angular inside Protractor Test
Edit: syntax error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With