-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathwebdriver-sync.js
153 lines (128 loc) · 3.98 KB
/
webdriver-sync.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
'use strict';
describe('webdriver-sync', function(){
var assert;
var path;
var wd;
var driver;
var element;
var By;
var ChromeDriver;
var Cookie;
var ExpectedConditions;
var TimeUnit;
var options;
before(function(){
assert=require('assert');
path = require('path');
wd=require('../');
//wd.importTo(this);
By = wd.By;
ChromeDriver = wd.ChromeDriver;
Cookie = wd.Cookie;
ExpectedConditions = wd.ExpectedConditions;
TimeUnit = wd.TimeUnit;
driver = require('./lib/driver.js').driver;
options = driver.manage();
driver.get('http://www.google.com');
});
after(function(){
driver.quit();
});
describe('driver', function(){
beforeEach(function(){
options.deleteAllCookies();
});
it('should be able to show the google title', function(){
assert.equal(driver.getTitle(), 'Google');//prints 'Google'
});
it('should be able to type some keys and submit a form', function(){
element = driver.findElement(By.name('q'));
element.sendKeys('Cheese!');
element.submit();
element = driver.findElement(By.name('q'));
assert.equal(element.getAttribute('value'), 'Cheese!');
});
it('should be able to get a list of divs', function(){
var elements = driver.findElements(By.tagName('html'));
assert(elements.length > 0, 'There were no divs on the page.');
});
it('should be able to get the current url', function(){
assert(driver.getCurrentUrl(), 'the current url was empty.');
});
it('should be able to get the page source', function(){
driver.getPageSource();
});
xit('should be able to start HtmlUnit', function(){
var htmlDriver = new wd.HtmlUnitDriver();
htmlDriver.quit();
});
it('should be able to work with driver options', function(){
assert(driver.manage());
});
it('should be able to work with TimeUnit', function(){
assert(TimeUnit.DAYS, 'days');
assert(TimeUnit.HOURS, 'hours');
assert(TimeUnit.MICROSECONDS, 'microseconds');
assert(TimeUnit.MILLISECONDS, 'milliseconds');
assert(TimeUnit.MINUTES, 'minutes');
assert(TimeUnit.NANOSECONDS, 'nanoseconds');
assert(TimeUnit.SECONDS, 'seconds');
});
describe('#exportTo', function() {
it('should export all Constructors to target', function() {
var target = {};
wd.exportTo(target);
assert('ChromeDriver' in target, 'ChromeDriver');
assert('Keys' in target, 'Keys');
// assert('PhantomJSDriver' in target, 'PhantomJSDriver');
assert('SafariDriver' in target, 'SafariDriver');
assert(!('exportTo' in target), 'exportTo');
assert(!('sleep' in target), 'sleep');
});
});
it('should be albe to sleep', function(){
var start=Date.now();
var end;
var secondsToWait=2 * 1000;
wd.sleep(secondsToWait);
end=Date.now();
assert(end-start >= secondsToWait, 'sleep didn\'t work.');
});
});
describe('wait', function() {
var start;
beforeEach(function() {
start = Date.now();
});
it('should halt execution until the condition is satisfied', function() {
var count = 0;
wd.wait(function() {
return ++count === 2;
});
assert.equal(count, 2);
});
it('should throw an error after the provided timeout', function() {
var error;
try {
wd.wait(function() {
return false;
}, { timeout: 1000 });
} catch(err) {
error = err;
}
assert.ok(error);
assert(Date.now() - start >= 300);
});
it('should honor the specified polling period', function() {
var callTimes = [];
var perceivedPeriod;
wd.wait(function() {
callTimes.push(Date.now());
return callTimes.length === 2;
}, { timeout: 1000, period: 120 });
perceivedPeriod = callTimes[1] - callTimes[0];
assert(perceivedPeriod >= 120);
assert(perceivedPeriod < 200);
});
});
});