-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
getSize.test.ts
64 lines (55 loc) · 1.97 KB
/
getSize.test.ts
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
// @ts-ignore mocked (original defined in webdriver package)
import gotMock from 'got'
import { remote } from '../../../src'
const got = gotMock as any as jest.Mock
jest.setTimeout(3000)
describe('getSize test', () => {
it('should allow to get the width and height of an element', async () => {
const browser = await remote({
baseUrl: 'http://foobar.com',
capabilities: {
browserName: 'foobar'
}
})
const elem = await browser.$('#foo')
const size = await elem.getSize()
expect(got.mock.calls[2][0].pathname)
.toBe('/session/foobar-123/element/some-elem-123/rect')
expect(size.width).toBe(50)
expect(size.height).toBe(30)
})
it('should allow to get the width and height of an element using jsonwp spec', async () => {
const browser = await remote({
baseUrl: 'http://foobar.com',
capabilities: {
// @ts-ignore mock feature
jsonwpMode: true,
browserName: 'foobar'
}
})
const elem = await browser.$('#foo')
const size = await elem.getSize()
expect(got.mock.calls[2][0].pathname)
.toBe('/session/foobar-123/element/some-elem-123/size')
expect(size.width).toBe(50)
expect(size.height).toBe(30)
})
it('should allow to get the width of an element', async () => {
const browser = await remote({
baseUrl: 'http://foobar.com',
capabilities: {
browserName: 'foobar'
}
})
const elem = await browser.$('#foo')
const width = await elem.getSize('width')
expect(width).toBe(50)
const height = await elem.getSize('height')
expect(height).toBe(30)
const invalid = await elem.getSize('foobar')
expect(invalid).toEqual({ width: 50, height: 30 })
})
afterEach(() => {
got.mockClear()
})
})