Skip to content

Commit e6a4b14

Browse files
committed
refactor(test): implement app-page object
encapsulating information about the elements on your application page
1 parent 0ff6693 commit e6a4b14

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed

test/app-e2e-test.js

+25-24
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,56 @@ var injectBrowser = require('testium/mocha');
44
var assert = require("power-assert");
55
var AppPage = require("./page-objects/app-page");
66
var browser;
7-
function addTodo(text) {
8-
browser.setValue('.todoText', text);
9-
browser.click('.todoBtn');
10-
}
117
describe("app-test", function () {
12-
var text = 'todo text';
8+
var inputText = 'todo text';
9+
var page;
1310
before(injectBrowser());
1411
beforeEach(function () {
1512
browser = this.browser;
16-
this.browser.navigateTo("/");
13+
page = new AppPage(this.browser);
1714
});
1815
context("when テキストボックスに文字を入れて送信した時", function () {
1916
beforeEach(function () {
20-
addTodo(text)
17+
page.addTodo(inputText)
2118
});
2219
it("should li要素が作成されている", function () {
23-
var list = browser.getElements('.todoList li');
24-
assert(list.length > 0);
20+
var list = page.getTodoItems();
21+
assert(list.length === 1);
2522
});
2623

2724
it("should リストアイテムのテキストは送信したものと一致している", function () {
28-
browser.assert.elementHasText('.todoList li', text)
25+
var todo = page.getTodoItems()[0];
26+
var text = todo.get("text");
27+
assert.equal(text, inputText);
2928
});
3029
});
31-
describe("todoについて", function () {
30+
describe("todo", function () {
3231
beforeEach(function () {
33-
addTodo(text);
32+
page.addTodo(inputText);
3433
});
35-
context("checkboxをクリックしたら", function () {
36-
it("should `is-complete`が追加される", function () {
37-
browser.click('.todoList li input[type="checkbox"]');
34+
context("when click the checkbox", function () {
35+
it("should added `is-complete`", function () {
36+
var todo = page.getTodoItems()[0];
37+
page.toggleTodo(todo);
3838
browser.assert.elementExists(".is-complete");
3939
});
4040
});
41-
context("removeBtnをクリックして、confirmでキャンセルしても", function () {
42-
it("li要素は消えない", function () {
41+
context("when click removeBtn, then cancel confirm", function () {
42+
it("should have todo item", function () {
43+
var todo = page.getTodoItems()[0];
4344
// confirmがfalseを返すようにする = キャンセル
4445
browser.evaluate("return window.confirm = function() { return " + false + "; };");
45-
46-
browser.click('.todoList li .removeBtn');
47-
browser.assert.elementExists(".todoList li");
46+
page.removeTodo(todo);
47+
assert(page.getTodoItems().length > 0);
4848
});
4949
});
50-
context("removeBtnをクリックしてconfirmでOKしたら", function () {
51-
it("li要素が消える", function () {
50+
context("when click removeBtn, then ok to confirm", function () {
51+
it("should have nottodo item", function () {
52+
var todo = page.getTodoItems()[0];
5253
// confirmがtrueを返すようにする = OK
5354
browser.evaluate("return window.confirm = function() { return " + true + "; };");
54-
browser.click('.todoList li .removeBtn');
55-
browser.assert.elementDoesntExist(".todoList li");
55+
page.removeTodo(todo);
56+
assert(page.getTodoItems().length === 0);
5657
});
5758
});
5859
});

test/page-objects/app-page.js

+21
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,26 @@
22
"use strict";
33
function AppPage(browser) {
44
this.browser = browser;
5+
this.browser.navigateTo("/");
56
}
7+
AppPage.prototype.addTodo = function addTodo(text) {
8+
this.browser.setValue('.todoText', text);
9+
this.browser.click('.todoBtn');
10+
};
11+
AppPage.prototype.getTodoItems = function () {
12+
return this.browser.getElements('.todoList li');
13+
};
14+
/**
15+
* @param todo the todo Element
16+
*/
17+
AppPage.prototype.toggleTodo = function (todo) {
18+
// @todo https://github.com/groupon-testium/webdriver-http-sync doesn't implemented Element#getElement.
19+
var input = todo.getElement('input[type="checkbox"]');
20+
input.click();
21+
};
22+
AppPage.prototype.removeTodo = function (todo) {
23+
// @todo https://github.com/groupon-testium/webdriver-http-sync doesn't implemented Element#getElement.
24+
var input = todo.getElement('.removeBtn');
25+
input.click();
26+
};
627
module.exports = AppPage;

0 commit comments

Comments
 (0)