-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
92 lines (69 loc) · 2.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* Copyright (C) 2014 yanni4night.com
* index.js
*
* changelog
* 2015-10-28[23:25:33]:revised
*
* @author [email protected]
* @version 0.1.0
* @since 0.1.0
*/
var Nightmare = require('nightmare');
var vo = require('vo');
function* test() {
var i = 0;
var nightmare = Nightmare({
width: 2560,
height: 1600,
show: true
});
var ready = false;
yield nightmare.on('dom-ready', function () {
ready = true;
}).goto('https://passport.baidu.com/v2/?login');
while (!ready) {
yield nightmare.wait(1e3);
}
yield nightmare.type('input[name="userName"]', '平台化测试').type('input[name="password"]', 'pingtaihua123').click(
'input[type="submit"]');
yield nightmare.wait(2e3);
ready = false;
yield nightmare.goto('http://tieba.baidu.com/f?ie=utf-8&kw=%E8%B4%B4%E5%90%A7%E5%9C%B0%E5%8C%BAtest');
while (!ready) {
yield nightmare.wait(1e3);
}
yield nightmare.evaluate(function () {
var $ = window.$;
$(document).scrollTop($('#rforum_mod').offset().top);
return $('.j-local-category .j-cate-item').length;
});
yield nightmare.click('#forumEditBtn').click(1e3).wait(3e3);
yield nightmare.type('#addForumArea', 'test').wait(1e3).click('#dialogJbody input[type="button"]').wait(3e3);
var succeed = yield nightmare.evaluate(function () {
var $ = window.$;
var exist = Array.prototype.some.call($('#dialogJbody .forumGroup .item a'), function (a) {
return $(a).text().trim() === 'test';
});
return exist;
});
yield nightmare.evaluate(function () {
var $ = window.$;
var exist = Array.prototype.forEach.call($('#dialogJbody .forumGroup .item'), function (item) {
var $item = $(item);
if ('test' === $item.find('a').text().trim()) {
$item.find('button').click();
}
});
});
yield nightmare.wait(2e3);
yield nightmare.evaluate(function (succeed) {
document.write('<center><font size=+5 color=red>Test Result:' + succeed + '</font></center>');
}, succeed);
yield nightmare.wait(3e3);
yield nightmare.end();
return succeed;
}
vo(test)(function (err, result) {
console.log(result);
});