Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix",
"prepare": "npm run build",
"test": "mocha --exit --timeout 1m \"./test/unit/**/*-specs.js\"",
"e2e-test": "mocha --exit --timeout 10m \"./test/e2e/**/*-specs.js\""
"test": "mocha --exit --timeout 1m \"./test/unit/**/*-specs.ts\"",
"e2e-test": "mocha --exit --timeout 10m \"./test/e2e/**/*-specs.ts\""
},
"peerDependencies": {
"appium": "^3.0.0-rc.2"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { buildWdIoOptions } from '../helpers';
import { remote as wdio } from 'webdriverio';
import type { Browser } from 'webdriverio';
import { expect } from 'chai';
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';

chai.use(chaiAsPromised.default);

describe('context', function () {
let chai;
/** @type {import('webdriverio').Browser} */
let driver;
let driver: Browser | null = null;

before(async function () {
chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');

chai.should();
chai.use(chaiAsPromised.default);

driver = await wdio(buildWdIoOptions('Root'));
});

Expand All @@ -27,13 +25,13 @@ describe('context', function () {
});

it('should support context api', async function () {
(await driver.getAppiumContext()).should.equal('NATIVE_APP');
(await driver.getAppiumContexts()).should.eql(['NATIVE_APP']);
await driver.switchAppiumContext('NATIVE_APP');
expect(await driver!.getAppiumContext()).to.equal('NATIVE_APP');
expect(await driver!.getAppiumContexts()).to.eql(['NATIVE_APP']);
await driver!.switchAppiumContext('NATIVE_APP');
});

it('should throw an error if invalid context', async function () {
await driver.switchAppiumContext('INVALID_CONTEXT').should.rejected;
await expect(driver!.switchAppiumContext('INVALID_CONTEXT')).to.be.rejected;
});

});
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { remote as wdio } from 'webdriverio';
import type { Browser } from 'webdriverio';
import path from 'path';
import { tempDir, fs } from 'appium/support';
import { isAdmin } from '../../../lib/installer';
import { buildWdIoOptions } from '../helpers';
import { expect } from 'chai';
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';

describe('file movement', function () {
let driver;
let remotePath;
let chai;

before(async function () {
chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);

chai.should();
chai.use(chaiAsPromised.default);
});
describe('file movement', function () {
let driver: Browser | null = null;
let remotePath: string | null = null;

beforeEach(async function () {
if (process.env.CI || !await isAdmin()) {
Expand Down Expand Up @@ -46,27 +43,27 @@ describe('file movement', function () {
const base64Data = Buffer.from(stringData).toString('base64');
remotePath = await tempDir.path({ prefix: 'appium', suffix: '.tmp' });

await driver.pushFile(remotePath, base64Data);
await driver!.pushFile(remotePath, base64Data);

// get the file and its contents, to check
const remoteData64 = await driver.pullFile(remotePath);
const remoteData64 = await driver!.pullFile(remotePath);
const remoteData = Buffer.from(remoteData64, 'base64').toString();
remoteData.should.equal(stringData);
expect(remoteData).to.equal(stringData);
});

it('should be able to delete a file', async function () {
const stringData = `random string data ${Math.random()}`;
const base64Data = Buffer.from(stringData).toString('base64');
remotePath = await tempDir.path({ prefix: 'appium', suffix: '.tmp' });

await driver.pushFile(remotePath, base64Data);
await driver!.pushFile(remotePath, base64Data);

const remoteData64 = await driver.pullFile(remotePath);
const remoteData64 = await driver!.pullFile(remotePath);
const remoteData = Buffer.from(remoteData64, 'base64').toString();
remoteData.should.equal(stringData);
expect(remoteData).to.equal(stringData);

await driver.execute('windows: deleteFile', { remotePath });
await driver!.execute('windows: deleteFile', { remotePath });

await driver.pullFile(remotePath).should.eventually.be.rejectedWith(/does not exist/);
await expect(driver!.pullFile(remotePath)).to.eventually.be.rejectedWith(/does not exist/);
});
});
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { buildWdIoOptions } from '../helpers';
import { remote as wdio } from 'webdriverio';
import type { Browser } from 'webdriverio';
import { expect } from 'chai';
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';

chai.use(chaiAsPromised.default);

describe('log', function () {
let chai;
/** @type {import('webdriverio').Browser} */
let driver;
let driver: Browser | null = null;

before(async function () {
chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');

chai.should();
chai.use(chaiAsPromised.default);

driver = await wdio(buildWdIoOptions('Root'));
});

Expand All @@ -27,14 +25,14 @@ describe('log', function () {
});

it('should get the list of available logs', async function () {
(await driver.getLogTypes()).should.eql(['server']);
expect(await driver!.getLogTypes()).to.eql(['server']);
});

it('should throw an error when an invalid type is given', async function () {
await driver.getLogs('INVALID_LOG_TYPE').should.be.rejected;
await expect(driver!.getLogs('INVALID_LOG_TYPE')).to.be.rejected;
});

it('should get server logs', async function () {
(await driver.getLogs('server')).should.be.an('array');
expect(await driver!.getLogs('server')).to.be.an('array');
});
});
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { buildWdIoOptions } from '../helpers';
import { remote as wdio } from 'webdriverio';
import type { Browser } from 'webdriverio';
import { expect } from 'chai';
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';

chai.use(chaiAsPromised.default);

describe('winapi', function () {
let chai;
/** @type {import('webdriverio').Browser} */
let driver;
let driver: Browser | null = null;

before(async function () {
chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');

chai.should();
chai.use(chaiAsPromised.default);

driver = await wdio(buildWdIoOptions('Root'));
});

Expand All @@ -28,31 +26,31 @@ describe('winapi', function () {

describe('mouseClick', function () {
it('performs single click with Shift+Ctrl', async function () {
await driver.execute('windows: click', {
await driver!.execute('windows: click', {
x: 100,
y: 100,
modifierKeys: ['shift', 'ctrl'],
});
});

it('performs long click', async function () {
await driver.execute('windows: click', {
await driver!.execute('windows: click', {
x: 100,
y: 100,
durationMs: 500,
});
});

it('performs double click', async function () {
await driver.execute('windows: click', {
await driver!.execute('windows: click', {
x: 100,
y: 100,
times: 2,
});
});

it('performs context click', async function () {
await driver.execute('windows: click', {
await driver!.execute('windows: click', {
x: 100,
y: 100,
button: 'right',
Expand Down Expand Up @@ -92,14 +90,14 @@ describe('winapi', function () {
];

for (const errData of errDatas) {
await driver.execute('windows: click', errData).should.be.rejected;
await expect(driver!.execute('windows: click', errData)).to.be.rejected;
}
});
});

describe('mouseScroll', function () {
it('performs vertical scroll gesture with Ctrl+Alt depressed', async function () {
await driver.execute('windows: scroll', {
await driver!.execute('windows: scroll', {
x: 600,
y: 300,
deltaY: 200,
Expand All @@ -108,15 +106,15 @@ describe('winapi', function () {
});

it('performs horizontal scroll gesture', async function () {
await driver.execute('windows: scroll', {
await driver!.execute('windows: scroll', {
x: 600,
y: 300,
deltaX: -200,
});
});

it('does nothing if zero delta is provided', async function () {
await driver.execute('windows: scroll', {
await driver!.execute('windows: scroll', {
x: 100,
y: 100,
deltaY: 0,
Expand Down Expand Up @@ -144,14 +142,14 @@ describe('winapi', function () {
];

for (const errData of errDatas) {
await driver.execute('windows: scroll', errData).should.be.rejected;
await expect(driver!.execute('windows: scroll', errData)).to.be.rejected;
}
});
});

describe('mouseClickAndDrag', function () {
it('performs drag gesture with Ctrl+Shift depressed', async function () {
await driver.execute('windows: clickAndDrag', {
await driver!.execute('windows: clickAndDrag', {
startX: 600,
startY: 300,
endX: 500,
Expand All @@ -163,7 +161,7 @@ describe('winapi', function () {

describe('windowsHover', function () {
it('performs hover gesture with Ctrl+Shift depressed', async function () {
await driver.execute('windows: clickAndDrag', {
await driver!.execute('windows: clickAndDrag', {
startX: 600,
startY: 300,
endX: 500,
Expand All @@ -175,7 +173,7 @@ describe('winapi', function () {

describe('keys', function () {
it('performs complex key input', async function () {
await driver.execute('windows: keys', {
await driver!.execute('windows: keys', {
actions: [
{virtualKeyCode: 0x10, down: true},
{pause: 100},
Expand Down Expand Up @@ -207,7 +205,7 @@ describe('winapi', function () {
];

for (const errData of errDatas) {
await driver.execute('windows: keys', {actions: [errData]}).should.be.rejected;
await expect(driver!.execute('windows: keys', {actions: [errData]})).to.be.rejected;
}
});
});
Expand Down
19 changes: 8 additions & 11 deletions test/e2e/driver-e2e-specs.js → test/e2e/driver-e2e-specs.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { remote as wdio } from 'webdriverio';
import type { Browser } from 'webdriverio';
import { isAdmin } from '../../lib/installer';
import { buildWdIoOptions } from './helpers';
import { expect } from 'chai';
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';

describe('Driver', function () {
let driver;
let chai;

before(async function () {
chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);

chai.should();
chai.use(chaiAsPromised.default);
});
describe('Driver', function () {
let driver: Browser | null = null;

beforeEach(async function () {
if (process.env.CI || !await isAdmin()) {
Expand All @@ -33,6 +30,6 @@ describe('Driver', function () {
});

it('should run a basic session using a real client', async function () {
await driver.source().should.eventually.be.not.empty;
await expect((driver as any).source()).to.eventually.be.not.empty;
});
});
14 changes: 8 additions & 6 deletions test/e2e/helpers.js → test/e2e/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
export const TEST_PORT = parseInt(process.env.APPIUM_TEST_SERVER_PORT || 4788, 10);
export const TEST_HOST = process.env.APPIUM_TEST_SERVER_HOST || '127.0.0.1';
import type { remote } from 'webdriverio';

export const TEST_PORT = parseInt(process.env.APPIUM_TEST_SERVER_PORT || '4788', 10);
export const TEST_HOST = process.env.APPIUM_TEST_SERVER_HOST || '127.0.0.1';

/**
*
* @param {string} app
* @returns {Record<string, any>}
* Build WebdriverIO options for testing
* @param app - The app identifier
* @returns WebdriverIO options object
*/
export function buildWdIoOptions(app) {
export function buildWdIoOptions(app: string): Parameters<typeof remote>[0] {
return {
hostname: TEST_HOST,
port: TEST_PORT,
Expand All @@ -19,3 +20,4 @@ export function buildWdIoOptions(app) {
}
};
}

Loading