无法访问量角测试中的输入字段



我是Angularjs/protractor的新手,并且难以在测试中访问输入标签。在浏览器中运行应用程序将输入字段设置为初始值。但是我似乎无法在测试中抓住它们或写入这些字段。量角器的输出结果是:

$protractor conf.js 
>[18:07:56] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
>[18:07:56] I/launcher - Running 1 instances of WebDriver
>Started 
>F
>Failures:
>1) When loading component loginComp the email/password get init values
>  Message:
>    Expected '' to be 'abc@example.com'.
>Stack:
>  Error: Failed expectation 
>   ....stack trace
>1 spec, 1 failure
>Finished in 1.101 seconds
>[18:07:58] I/launcher - 0 instance(s) of WebDriver still running
>[18:07:58] I/launcher - chrome #01 failed 1 test(s)
>[18:07:58] I/launcher - overall: 1 failed spec(s)
>[18:07:58] E/launcher - Process exited with error code 1

这是index.html:

index.html:
<!DOCTYPE html>
<html>
<head>
  <title>Test directives</title>
</head>
<body ng-app="docsapp">
  <div> Here is the test</div>
   <div>
    <login-comp></login-comp>
   </div>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.6/angular.js">  </script>
  <script src="app/app.module.js"></script>
  <script src="app/login-comp/login-comp.module.js"></script>
  <script src="app/login-comp/login-comp.component.js"></script>
 </body>
</html>

这是登录模块:

login-comp.module.js:
angular.module('loginComp', [])

这是登录Component Def:

function LoginCompController() {
  var vm = this;
  this.user = {
    email: "admin@example.com",
    password: "password" 
  }
}
angular.module('loginComp')
.component('loginComp', {
  templateUrl: './app/login-comp/login-comp.template.html',
  controller: LoginCompController,
  controllerAs: 'vm'
});

这是登录模板:

login-comp.template.html:
<input type="email" ng-model="vm.user.email"/>
<hr>
<input type="password" ng-model="vm.user.password"/>

这是测试文件:

login-comp.component.spec.js:
describe("When loading component loginComp", function() {
  beforeEach(function() {
    browser.get("http://127.0.0.1:8080/");
  });
  it("the email/password get init values", function() {
    var email = element(by.model("vm.user.email"));
    email.sendKeys("abc@example.com").then(function() {
      expect(email.getText()).toBe("abc@example.com");
    });
  });
});

我在测试中尝试了不同的变化:从电子邮件输入字段中读取,写信给它。我还尝试使用" user..email"或"电子邮件"访问输入字段,但这会产生错误(失败:使用定位器:by.model(" user.email")找到了错误。

如果有人在Stackoverflow上看到过此错误,请给我发送链接。我已经审查了许多与量角有关的问题,但不适用于我的案件。

非常感谢。

这是来自量量的常见问题:

getText从输入元素的结果始终为空

这是一个webdriver怪异。输入和textarea元素总是具有空的getText值。而是尝试:

element.getAttribute('value')

最新更新