|
| 1 | +import request from 'request' |
| 2 | +import { remote } from '../../../src' |
| 3 | + |
| 4 | +describe('isEqual test', () => { |
| 5 | + let browser |
| 6 | + let elem |
| 7 | + |
| 8 | + describe('web', () => { |
| 9 | + beforeAll(async () => { |
| 10 | + browser = await remote({ |
| 11 | + baseUrl: 'http://foobar.com', |
| 12 | + capabilities: { |
| 13 | + browserName: 'foobar' |
| 14 | + } |
| 15 | + }) |
| 16 | + elem = await browser.$('#foo') |
| 17 | + request.mockClear() |
| 18 | + }) |
| 19 | + |
| 20 | + it('should return true if elements are equal', async () => { |
| 21 | + expect(await elem.isEqual(elem)).toBe(true) |
| 22 | + }) |
| 23 | + |
| 24 | + it('should return false if elements are NOT equal', async () => { |
| 25 | + const elements = await browser.$$('#bar') |
| 26 | + expect(await elem.isEqual(elements[1])).toBe(false) |
| 27 | + }) |
| 28 | + |
| 29 | + it('should return false if execute command fails', async () => { |
| 30 | + const execute = browser.execute |
| 31 | + delete browser.execute |
| 32 | + expect(await elem.isEqual(elem)).toBe(false) |
| 33 | + browser.execute = execute |
| 34 | + }) |
| 35 | + }) |
| 36 | + |
| 37 | + describe('mobile', () => { |
| 38 | + beforeAll(async () => { |
| 39 | + browser = await remote({ |
| 40 | + baseUrl: 'http://foobar.com', |
| 41 | + capabilities: { |
| 42 | + mobileMode: true, |
| 43 | + browserName: 'foobar' |
| 44 | + } |
| 45 | + }) |
| 46 | + elem = await browser.$('#foo') |
| 47 | + request.mockClear() |
| 48 | + }) |
| 49 | + |
| 50 | + it('should return true if elements are equal', async () => { |
| 51 | + request.setMockResponse(['NATIVE_APP']) |
| 52 | + expect(await elem.isEqual(elem)).toBe(true) |
| 53 | + }) |
| 54 | + |
| 55 | + it('should return false if elements are NOT equal', async () => { |
| 56 | + const elements = await browser.$$('#bar') |
| 57 | + request.setMockResponse(['NATIVE_APP']) |
| 58 | + expect(await elem.isEqual(elements[1])).toBe(false) |
| 59 | + }) |
| 60 | + |
| 61 | + it('should call execute if in webview', async () => { |
| 62 | + request.setMockResponse(['WEBVIEW']) |
| 63 | + const execute = browser.execute |
| 64 | + delete browser.execute |
| 65 | + browser.execute = jest.fn().mockReturnValue(true) |
| 66 | + |
| 67 | + expect(await elem.isEqual(elem)).toBe(true) |
| 68 | + expect(browser.execute).toBeCalled() |
| 69 | + |
| 70 | + delete browser.execute |
| 71 | + browser.execute = execute |
| 72 | + }) |
| 73 | + }) |
| 74 | + |
| 75 | + afterEach(() => { |
| 76 | + request.mockClear() |
| 77 | + }) |
| 78 | +}) |
0 commit comments