Skip to content

Commit e6e977a

Browse files
test: Migrate e2e tests to typescript (#973)
1 parent 04c16e3 commit e6e977a

38 files changed

Lines changed: 739 additions & 777 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"e2e-test:commands:find": "mocha --exit --timeout 10m \"./test/functional/commands/find\"",
4040
"e2e-test:commands:general": "mocha --exit --timeout 10m \"./test/functional/commands/general\"",
4141
"e2e-test:commands:keyboard": "mocha --exit --timeout 10m \"./test/functional/commands/keyboard\"",
42-
"e2e-test:driver": "mocha --exit --timeout 10m \"./test/functional/driver-e2e-specs.js\"",
42+
"e2e-test:driver": "mocha --exit --timeout 10m \"./test/functional/driver-e2e-specs.ts\"",
4343
"lint": "eslint .",
4444
"lint:commit": "commitlint",
4545
"lint:fix": "npm run lint -- --fix",

scripts/run-functional-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ checkTestPrerequisites
2525

2626
RESULTS_XML=test-results.xml
2727
echo "{\"reporterEnabled\": \"spec, xunit\", \"xunitReporterOptions\": {\"output\": \"$RESULTS_XML\"}}" > reporter_config.json
28-
ARGS=(./test/functional/driver-e2e-specs.js \
28+
ARGS=(./test/functional/driver-e2e-specs.ts \
2929
./test/functional/commands \
3030
./test/functional/commands/find \
3131
./test/functional/commands/general \
Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,59 @@
1-
import _ from 'lodash';
1+
import type {Browser} from 'webdriverio';
22
import B from 'bluebird';
3-
import stream from 'stream';
3+
import stream from 'node:stream';
44
import unzipper from 'unzipper';
5-
import { APIDEMOS_CAPS } from '../desired';
6-
import { initSession, deleteSession } from '../helpers/session';
5+
import {APIDEMOS_CAPS} from '../desired';
6+
import {initSession, deleteSession} from '../helpers/session';
7+
import chai, {expect} from 'chai';
8+
import chaiAsPromised from 'chai-as-promised';
79

10+
chai.use(chaiAsPromised);
811

912
describe('file movement', function () {
10-
let driver;
11-
let chai;
13+
let driver: Browser;
1214

1315
before(async function () {
14-
chai = await import('chai');
15-
const chaiAsPromised = await import('chai-as-promised');
16-
17-
chai.should();
18-
chai.use(chaiAsPromised.default);
19-
2016
driver = await initSession(APIDEMOS_CAPS);
2117
});
2218
after(async function () {
2319
await deleteSession();
2420
});
2521

26-
function getRandomDir () {
22+
function getRandomDir(): string {
2723
return `/data/local/tmp/test${Math.random()}`;
2824
}
2925

3026
it('should push and pull a file', async function () {
31-
let stringData = `random string data ${Math.random()}`;
32-
let base64Data = Buffer.from(stringData).toString('base64');
33-
let remotePath = `${getRandomDir()}/remote.txt`;
27+
const stringData = `random string data ${Math.random()}`;
28+
const base64Data = Buffer.from(stringData).toString('base64');
29+
const remotePath = `${getRandomDir()}/remote.txt`;
3430

3531
await driver.pushFile(remotePath, base64Data);
3632

3733
// get the file and its contents, to check
38-
let remoteData64 = await driver.pullFile(remotePath);
39-
let remoteData = Buffer.from(remoteData64, 'base64').toString();
40-
remoteData.should.equal(stringData);
34+
const remoteData64 = await driver.pullFile(remotePath);
35+
const remoteData = Buffer.from(remoteData64, 'base64').toString();
36+
expect(remoteData).to.equal(stringData);
4137
});
4238

4339
it('should pull a folder', async function () {
44-
let stringData = `random string data ${Math.random()}`;
45-
let base64Data = Buffer.from(stringData).toString('base64');
40+
const stringData = `random string data ${Math.random()}`;
41+
const base64Data = Buffer.from(stringData).toString('base64');
4642

4743
// send the files, then pull the whole folder
48-
let remoteDir = getRandomDir();
44+
const remoteDir = getRandomDir();
4945
await driver.pushFile(`${remoteDir}/remote0.txt`, base64Data);
5046
await driver.pushFile(`${remoteDir}/remote1.txt`, base64Data);
5147

5248
// TODO: 'pullFolder' is returning 404 error
53-
let data = await driver.pullFolder(remoteDir);
49+
const data = await driver.pullFolder(remoteDir);
5450

5551
// go through the folder we pulled and make sure the
5652
// two files we pushed are in it
57-
let zipPromise = new B((resolve) => {
53+
const zipPromise = new B<number>((resolve) => {
5854
let entryCount = 0;
59-
let zipStream = new stream.Readable();
60-
zipStream._read = _.noop;
55+
const zipStream = new stream.Readable();
56+
zipStream._read = () => {};
6157
zipStream
6258
.pipe(unzipper.Parse())
6359
.on('entry', function (entry) {
@@ -73,6 +69,7 @@ describe('file movement', function () {
7369
zipStream.push(null);
7470
});
7571

76-
(await zipPromise).should.equal(2);
72+
expect(await zipPromise).to.equal(2);
7773
});
7874
});
75+

test/functional/commands/find/by-accessibility-id-e2e-specs.js

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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';
6+
7+
chai.use(chaiAsPromised);
8+
9+
describe('Find - accessibility ID', function () {
10+
let driver: Browser;
11+
12+
before(async function () {
13+
driver = await initSession(APIDEMOS_CAPS);
14+
});
15+
after(async function () {
16+
await deleteSession();
17+
});
18+
it('should find an element by name', async function () {
19+
await expect(driver.$('~Animation').elementId).to.eventually.exist;
20+
});
21+
it('should return an array of one element with findElements', async function () {
22+
const els = await driver.$$('~Animation');
23+
expect(els).to.be.an.instanceof(Array);
24+
expect(els).to.have.length(1);
25+
});
26+
it('should find an element with a content-desc property containing an apostrophe', async function () {
27+
await expect(driver.$("~Access'ibility").elementId).to.eventually.exist;
28+
});
29+
});
30+
Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,72 @@
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';
36

7+
chai.use(chaiAsPromised);
48

59
describe('Find - CSS', function () {
6-
let driver;
7-
let chai;
10+
let driver: Browser;
811
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-
1512
driver = await initSession(APIDEMOS_CAPS);
1613
});
1714
after(async function () {
1815
await deleteSession();
1916
});
2017
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;
2421
});
2522
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;
2724
});
2825
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);
3229
});
3330
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;
3532
});
3633
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');
3835
const text = await el.getText();
39-
text.toLowerCase().should.equal('api demos');
36+
expect(text.toLowerCase()).to.equal('api demos');
4037
});
4138
it('should find an element with a chain of attributes and pseudo-classes', async function () {
4239
// TODO: webdriver selects 'class name' strategy.
4340
// ref. https://github.com/webdriverio/webdriverio/blob/eba541a77dbc42173717e1c106a7c4d3ccb198f5/packages/webdriverio/src/utils/findStrategy.ts#L91-L96
4441
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');
4744
});
4845
it('should find an element with recursive UiSelectors', async function () {
4946
const els = await driver.$$('*[focused=true] *[clickable=true]');
50-
els.should.have.length(1);
47+
expect(els).to.have.length(1);
5148
});
5249
it('should find an element by a non-fully qualified class name using CSS tag name', async function () {
5350
const els = await driver.$$('android.widget.TextView');
54-
els.length.should.be.above(0);
51+
expect(els.length).to.be.above(0);
5552
});
5653
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;
5855
});
5956
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;
6158
});
6259
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;
6461
});
6562
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;
6764
});
6865
it('should allow UiScrollable with unicode string', async function () {
6966
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('عربي');
7370
});
7471
});
72+

test/functional/commands/find/by-id-e2e-specs.js

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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';
6+
7+
chai.use(chaiAsPromised);
8+
9+
describe('Find - ID', function () {
10+
let driver: Browser;
11+
12+
before(async function () {
13+
driver = await initSession(APIDEMOS_CAPS);
14+
});
15+
after(async function () {
16+
await deleteSession();
17+
});
18+
it('should find an element by id', async function () {
19+
await expect(driver.$('id=android:id/text1').elementId).to.eventually.exist;
20+
});
21+
it('should return an array of one element with findElements', async function () {
22+
const els = await driver.$$('id=android:id/text1');
23+
expect(els).to.be.an.instanceof(Array);
24+
expect(els).to.have.length.above(1);
25+
});
26+
});
27+

0 commit comments

Comments
 (0)