3

私は2つのページを持つアプリを持っています...最初のページはログインボタンがあるランディングページです...ユーザーがこのログインボタンをクリックすると、login.htmlにリダイレクトされます....2つの入力があります。1 つはユーザー名用、もう 1 つはパスワード用です。

関連するコードは次のようになります。

index.html

<a ui-sref="login" class="fa fa-sign-in" href="/login">&nbsp;Login</a>

login.html

<input type="text" id="username" name="username" placeholder="Username" ng-model="user.username" required="" autocomplete="off" class="ng-pristine ng-invalid ng-invalid-required">

<input type="password" name="password" placeholder="Password" ng-model="user.password" required="" autocomplete="off" class="ng-pristine ng-invalid ng-invalid-required">

私のテストでは、最初にログイン ボタンをクリックし、新しいページに正しくリダイレ​​クトされていることを確認します。このテストはパスしますが、これらの入力ボックスに入力しようとすると、ボックスが存在しないかのようにエラーが発生します。ブラウザをスリープさせようとしましたが、それもうまくいきませんでした。

// in test/e2e/main.spec.js
describe('E2E: main page', function(){

'use strict';

var ptor;


// keep track of the protractor instance
beforeEach(function(){
    browser.get('http://127.0.0.1:9000/');
    ptor = protractor.getInstance();
});

it('it should load the login page once the login button is clicked', function(){

    var link = element(by.css('.fa.fa-sign-in'))

    link.click();


    browser.sleep(4000);

    expect(ptor.getCurrentUrl()).toMatch(/\/login/);

    element(by.input('user.username')).sendKeys('test');
    element(by.input('user.password')).sendKeys('test');

});


});

何かアドバイス?

アップデート:

by.input の代わりに by.model を使用すると動作しますが、私が読んでいた本には、最初のものも動作するはずだと書かれていました..奇妙です。

4

1 に答える 1

4

by.input()ロケーターは減価償却されているため、使用する必要by.model()がありますが、本当に必要な場合は、次のように独自に定義できます。

by.addLocator('input', function(model, opt_parentElement) {
  using = using || document;
  var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
  for (var p = 0; p < prefixes.length; ++p) {
      var selector = 'input[' + prefixes[p] + 'model="' + model + '"]';
      var inputs = using.querySelectorAll(selector);
      if (inputs.length) {
          return inputs;
      }
   }
});

// To use the locator
element(by.input('username')).sendKeys('test');
于 2014-07-02T22:34:21.690 に答える