Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access $scope object with protractor

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');
like image 466
Mimetix Avatar asked Jul 01 '15 07:07

Mimetix


1 Answers

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

like image 124
Delian Mitankin Avatar answered Oct 02 '22 12:10

Delian Mitankin