使用Protractor访问JS范围元素/变量 [英] Accessing JS scope elements/variables with Protractor

查看:69
本文介绍了使用Protractor访问JS范围元素/变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Protractor测试,输入登录数据并单击登录按钮,我希望检查Angular变量的值。

I have a Protractor test that enters login data and clicks the login button and I wish to check the value of an Angular variable.

ng-click for the ng clicked元素是doLogin(),它在控制器文件中定义为:

The ng-click for the clicked element is doLogin() which is defined in the controller file as:

$scope.doLogin  = function(){
        console.log('login -- todo');
        // remember email used
        localStorageService.add('lastKeyEmail', $scope.data.login.key.email);
        // todo - make dynamic
        $scope.authentication.user = true;
        // set email of logged in user
        // todo: would need to be done in user service (set user details received from server)
        Authentication.setEmail($scope.data.login.key.email);
        // overwrite password in memory
        $scope.data.login.password = "thispasswordisdeletedsoyoucantreadit";
    };

如何在$ scope.authentication.user的值上使用Protractor的expect()?

How do I use Protractor's expect() on the value of $scope.authentication.user?

推荐答案

有一个名为 evaluate 的函数可以让你评估角度表达式给定一个元素。

There is a function called evaluate that allows you to evaluate an angular expressions given an element.

选择要检查范围的DOM元素,然后调用evaluate。文档中有一个例子:

Select a DOM element for which you want to examine the scope, then call evaluate. There is an example in the documentation:

http://angular.github.io/protractor/#/api?view=ElementArrayFinder.prototype.evaluate

这篇关于使用Protractor访问JS范围元素/变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆