|
1 | | -import { APIDEMOS_CAPS } from '../../desired'; |
2 | | -import { initSession, deleteSession } from '../../helpers/session'; |
| 1 | +import type {Browser} from 'webdriverio'; |
| 2 | +import {APIDEMOS_CAPS} from '../../desired'; |
| 3 | +import {initSession, deleteSession} from '../../helpers/session'; |
| 4 | +import chai, {expect} from 'chai'; |
| 5 | +import chaiAsPromised from 'chai-as-promised'; |
3 | 6 |
|
| 7 | +chai.use(chaiAsPromised); |
4 | 8 |
|
5 | 9 | describe('Find - CSS', function () { |
6 | | - let driver; |
7 | | - let chai; |
| 10 | + let driver: Browser; |
8 | 11 | before(async function () { |
9 | | - chai = await import('chai'); |
10 | | - const chaiAsPromised = await import('chai-as-promised'); |
11 | | - |
12 | | - chai.should(); |
13 | | - chai.use(chaiAsPromised.default); |
14 | | - |
15 | 12 | driver = await initSession(APIDEMOS_CAPS); |
16 | 13 | }); |
17 | 14 | after(async function () { |
18 | 15 | await deleteSession(); |
19 | 16 | }); |
20 | 17 | it('should find an element by id (android resource-id)', async function () { |
21 | | - await driver.$('#android\\:id\\/text1').elementId.should.eventually.exist; |
22 | | - await driver.$('*[id="android:id/text1"]').elementId.should.eventually.exist; |
23 | | - await driver.$('*[resource-id="android:id/text1"]').elementId.should.eventually.exist; |
| 18 | + await expect(driver.$('#android\\:id\\/text1').elementId).to.eventually.exist; |
| 19 | + await expect(driver.$('*[id="android:id/text1"]').elementId).to.eventually.exist; |
| 20 | + await expect(driver.$('*[resource-id="android:id/text1"]').elementId).to.eventually.exist; |
24 | 21 | }); |
25 | 22 | it('should find an element by content description', async function () { |
26 | | - await driver.$('*[description="Animation"]').elementId.should.eventually.exist; |
| 23 | + await expect(driver.$('*[description="Animation"]').elementId).to.eventually.exist; |
27 | 24 | }); |
28 | 25 | it('should return an array with findElements', async function () { |
29 | | - let els = await driver.$$('*[content-desc="Animation"]'); |
30 | | - els.should.be.an.instanceof(Array); |
31 | | - els.should.have.length(1); |
| 26 | + const els = await driver.$$('*[content-desc="Animation"]'); |
| 27 | + expect(els).to.be.an.instanceof(Array); |
| 28 | + expect(els).to.have.length(1); |
32 | 29 | }); |
33 | 30 | it('should find an element with a content-desc property containing an apostrophe', async function () { |
34 | | - await driver.$('*[content-description="Access\'ibility"]').elementId.should.eventually.exist; |
| 31 | + await expect(driver.$('*[content-description="Access\'ibility"]').elementId).to.eventually.exist; |
35 | 32 | }); |
36 | 33 | it('should find an element by class name', async function () { |
37 | | - let el = await driver.$('android.widget.TextView'); |
| 34 | + const el = await driver.$('android.widget.TextView'); |
38 | 35 | const text = await el.getText(); |
39 | | - text.toLowerCase().should.equal('api demos'); |
| 36 | + expect(text.toLowerCase()).to.equal('api demos'); |
40 | 37 | }); |
41 | 38 | it('should find an element with a chain of attributes and pseudo-classes', async function () { |
42 | 39 | // TODO: webdriver selects 'class name' strategy. |
43 | 40 | // ref. https://github.com/webdriverio/webdriverio/blob/eba541a77dbc42173717e1c106a7c4d3ccb198f5/packages/webdriverio/src/utils/findStrategy.ts#L91-L96 |
44 | 41 | this.skip(); |
45 | | - let el = await driver.$('android.widget.TextView[clickable=true]:nth-child(1)'); |
46 | | - await el.getText().should.eventually.equal('Accessibility'); |
| 42 | + const el = await driver.$('android.widget.TextView[clickable=true]:nth-child(1)'); |
| 43 | + await expect(el.getText()).to.eventually.equal('Accessibility'); |
47 | 44 | }); |
48 | 45 | it('should find an element with recursive UiSelectors', async function () { |
49 | 46 | const els = await driver.$$('*[focused=true] *[clickable=true]'); |
50 | | - els.should.have.length(1); |
| 47 | + expect(els).to.have.length(1); |
51 | 48 | }); |
52 | 49 | it('should find an element by a non-fully qualified class name using CSS tag name', async function () { |
53 | 50 | const els = await driver.$$('android.widget.TextView'); |
54 | | - els.length.should.be.above(0); |
| 51 | + expect(els.length).to.be.above(0); |
55 | 52 | }); |
56 | 53 | it('should find elements using starts with attribute', async function () { |
57 | | - await driver.$('*[description^="Animation"]').elementId.should.eventually.exist; |
| 54 | + await expect(driver.$('*[description^="Animation"]').elementId).to.eventually.exist; |
58 | 55 | }); |
59 | 56 | it('should find elements using ends with attribute', async function () { |
60 | | - await driver.$('*[description$="Animation"]').elementId.should.eventually.exist; |
| 57 | + await expect(driver.$('*[description$="Animation"]').elementId).to.eventually.exist; |
61 | 58 | }); |
62 | 59 | it('should find elements using word match attribute', async function () { |
63 | | - await driver.$('*[description~="Animation"]').elementId.should.eventually.exist; |
| 60 | + await expect(driver.$('*[description~="Animation"]').elementId).to.eventually.exist; |
64 | 61 | }); |
65 | 62 | it('should find elements using wildcard attribute', async function () { |
66 | | - await driver.$('*[description*="Animation"]').elementId.should.eventually.exist; |
| 63 | + await expect(driver.$('*[description*="Animation"]').elementId).to.eventually.exist; |
67 | 64 | }); |
68 | 65 | it('should allow UiScrollable with unicode string', async function () { |
69 | 66 | await driver.startActivity('io.appium.android.apis', '.text.Unicode'); |
70 | | - let selector = '*[text="عربي"]:instance(0)'; |
71 | | - let el = await driver.$(selector); |
72 | | - await el.getText().should.eventually.equal('عربي'); |
| 67 | + const selector = '*[text="عربي"]:instance(0)'; |
| 68 | + const el = await driver.$(selector); |
| 69 | + await expect(el.getText()).to.eventually.equal('عربي'); |
73 | 70 | }); |
74 | 71 | }); |
| 72 | + |
0 commit comments