2017-02-02 4 views
1

テストワゴンに飛び乗ってウェブサイトのE2Eテストを実装しましたが、面倒な小さな問題に遭遇しました。分度器、失敗:不明なエラー:カスタム入力フィールドに要素をフォーカスできません

フィールドを選択してその入力フィールドにキーを送信して値を変更しようとしていますが、唯一の問題は「失敗:不明なエラー:要素をフォーカスできません」というエラーです。私は他のフィールドで作業していますが、この設定のものではありません。

pageObjectファイル。

var profilePage = function() { 

this.firstName = element(by.id('firstname')); 
this.lastName = element(by.id('lastname')); 
this.saveBtn = element(by.css('ng-click="saveLocalAccount()"')); 
this.cancelBtn = element(by.css('ng-click="cancelChanges()"')); 

this.changeName = function(firstname, lastname) { 

    this.firstName.click(); 

    var input = firstName.element(by.css('input')); 
    input.click(); 
    this.input.sendKeys(firstname); 

    this.lastName.click(); 
    this.lastName.sendKeys(lastname); 
    browser.waitForAngular(); 
} 
}; 

module.exports = new profilePage(); 

仕様です。

var profilePage = require('TestProtractor/E2E/PageObjects/profile.pageObject.js'); 

describe('Testing the profile page functionality', function() { 

var firstNameTest = "firstTest"; 
var lastNameTest = "lastTest"; 

it('Navigate to profile page.' ,function() { 
    browser.get('xxx'); 

    expect(browser.getCurrentUrl()) 
     .toContain('xxx'); 
}); 

it('Should change the firstname and lastname successfully', function() { 
    profilePage.changeName(firstNameTest, lastNameTest); 
    expect(element(by.id('firstname')).getText()).toContain(firstNameTest);  
    expect(element(by.id('lastname')).getText()).toContain(firstNameTest); 
}); 

});

HTML

enter image description here

答えて

2

あなたがlastName = element(by.id('lastname'))sendKeys()しようとしているchangeName()あなたの再利用可能な方法でinput

ない要素にsendKeys()しようとしているときは、Failed: unknown error: cannot focus element errorが表示されますこれはinput要素ではありません。あなたが最初の名前のためにテキストを入力し、とあなたは同じように、それにアプローチする必要が

彼らはinput

this.changeName = function(firstname, lastname) { 

    this.firstName.click(); 

    var input = firstName.element(by.css('input')); 
    input.click(); 
    this.input.sendKeys(firstname); 

    this.lastName.click(); 
    var input2 = lastName.element(by.css('input')); 
    input2.click(); 
    this.input2.sendKeys(lastName); 
} 
}; 

すぎ姓の内部であると仮定すると、
関連する問題