寫一個 Protractor 測試

開啟一個新的命令列或終端視窗,並建立一個乾淨的資料夾進行測試。

Protractor 需要執行兩個檔案,一個 spec 檔案和一個配置檔案。

讓我們從一個簡單的測試開始,該測試導航到 AngularJS 網站中的待辦事項列表示例,並在列表中新增一個新的待辦事項。

將以下內容複製到 spec.js

describe(‘angularjs homepage todo list’,function(){it(‘應新增 todo’,function(){browser.get(’ https://angularjs.org ‘);

element(by.model('todoList.todoText')).sendKeys('write first protractor test');
element(by.css('[value="add"]')).click();

var todoList = element.all(by.repeater('todo in todoList.todos'));
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual('write first protractor test');

// You wrote your first test, cross it off the list
todoList.get(2).element(by.css('input')).click();
var completedAmount = element.all(by.css('.done-true'));
expect(completedAmount.count()).toEqual(2);});});