-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwdio-pageobject.js
86 lines (80 loc) · 1.74 KB
/
wdio-pageobject.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
var desktop, mobile
function init (wdio) {
desktop = wdio.desktop
mobile = wdio.mobile
}
var convertMobile = function (targetWidth) {
// 1080px in mocks is 360px in CSS
return targetWidth / 3
}
function distance (posA, posB) {
return Promise.all([posA, posB]).then(function (values) {
return values[1] - values[0]
})
}
var PageElementDimensions = {
init (target, selector) {
this.target = target
this.selector = selector
},
get element () {
return this.target.element(this.selector)
},
get size () {
return this.element.getElementSize()
},
get width () {
return this.size.then(function (res) {
return res.width
})
},
get height () {
return this.size.then(function (res) {
return res.height
})
},
get location () {
return this.element.getLocation()
},
get posX () {
return this.location.then(function (res) {
return res.x
})
},
get left () {
return this.posX()
},
get posY () {
return this.location.then(function (res) {
return res.y
})
},
get top () {
return this.posY()
},
get right () {
return Promise.all([this.posX, this.width]).then(function (values) {
return values[0] + values[1]
})
},
get bottom () {
return Promise.all([this.posY, this.height]).then(function (values) {
return values[0] + values[1]
})
}
}
var PageElement = {
init (selector) {
this.selector = selector
this.desktop = Object.create(PageElementDimensions)
this.desktop.init(desktop, selector)
this.mobile = Object.create(PageElementDimensions)
this.mobile.init(mobile, selector)
}
}
module.exports = {
init: init,
PageElement: PageElement,
distance: distance,
convertMobile: convertMobile
}