0
我是Angularjs /量角器的新手,無法在我的測試中訪問輸入標籤。在瀏覽器中運行應用程序會將輸入字段設置爲初始值。但我似乎無法抓住他們或在我的測試中寫入這些字段。量角器的輸出結果是:無法訪問量角器測試中的輸入字段
$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 '[email protected]'.
>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>
這裏是loginComp模塊:
login-comp.module.js:
angular.module('loginComp', [])
這裏是loginComp部件DEF:
function LoginCompController() {
var vm = this;
this.user = {
email: "[email protected]",
password: "password"
}
}
angular.module('loginComp')
.component('loginComp', {
templateUrl: './app/login-comp/login-comp.template.html',
controller: LoginCompController,
controllerAs: 'vm'
});
這是loginComp模板:
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("[email protected]").then(function() {
expect(email.getText()).toBe("[email protected]");
});
});
});
我曾嘗試不同的變化的測試:從電子郵件輸入字段讀,寫它。我也嘗試使用「user.email」或「email」來訪問輸入字段,但這會給出錯誤(失敗:找不到使用locator的元素:by.model(「user.email」))。
如果有人在Stackoverflow上看到過此錯誤,請將鏈接發送給我。我已經回顧了很多量角器相關的問題,但沒有一個適用於我的案例。
非常感謝。
謝謝!這工作。在Protractor的PluralSight網站上有一個使用getText的教程。它在教程中起作用,所以我認爲還有其他錯誤。 – user2137480